-1

I have used regular expression validator in aspx form.I have used this express ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{6,15}),working fine.

I am trying to use same expression in javascript,but that fail why so ?

In javascript

var regularExpression  = ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{6,15})


if (regularExpression.test(newPassword)) {
    alert("Password must be at least 6 characters, not more than 15 characters, and must include at least one upper case letter, one lower case letter, one special character and one numeric digit.");
    return false;
} 
pinku
  • 1
  • 2
  • `var regularExpression = ((?` is invalid syntax, you need delimiters. – CertainPerformance Dec 07 '18 at 07:17
  • Can u pls correct it out? – pinku Dec 07 '18 at 07:17
  • Possible duplicate of [Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters](https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a) – Jose Noriega Dec 07 '18 at 08:06

1 Answers1

1

you should use / instead of ( for RegExp

var regularExpression  = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{6,15}/;

if (regularExpression.test(newPassword)) {
    alert("Password must be at least 6 characters, not more than 15 characters, and must include at least one upper case letter, one lower case letter, one special character and one numeric digit.");
    return false;
} 
Artyom Amiryan
  • 2,846
  • 1
  • 10
  • 22