I have a requirement where we need to add find out regex pattern where user can enter below combinations only.
we have used below regex pattern..
/^(?=.*?[a-zA-Z0-9.-_])+$/
Can someone please help on this?
A - has different meanings in a character class depending on its position
At the end or at the start it's a literal: [._-] contains the three literals ., _ and -
Somewhere else, it's a range: [.-_] is a range from . to _.
You can use 4 regexes to check the strings
function check(str) {
return /^[a-zA-Z0-9._-]+$/.test(str) && /[a-zA-Z]/.test(str) && /[0-9]/.test(str) && /[._-]/.test(str);
}
const str1 = 'aA5.-_';
console.log(check(str1));
const str2 = 'aA5';
console.log(check(str2));
const str3 = 'aA5.-_+';
console.log(check(str3));