var nameMinMax = [2,30]; var patternName = new RegExp("^([a-zA-Zа-яёА-ЯЁ0-9_. -]{" + nameMinMax + "})$"); console.log(patternName)