i need to validate differents input value lengths.
Inputs value can have a max length of 6 / 15 / 25 characters. Now i was asking to my self if it's a good practice use only one dynamic regex to validate differents max lengths, instead of copy paste the same regex.
During my research i found that i've to use the the const regex = new RegExp()
the problem is that i tried
const lengthValidation = () => {
const maxLength = 4;
const inputValue = 'ciao';
const regex = new RegExp(`/^.{6,${maxLength}}$/`);
const isValid = regex.test(inputValue);
return console.log('regexTest', isValid);
};
lengthValidation();
but it's invalid.
where is my mistake ?