Hello!
I am writing a password screen, and the requirements for the password security are somewhere between 8 and 20 characters in length, must contain AT LEAST one Alpha character and AT LEAST one numeric character and AT LEAST one special character of [!@#$%^&*].
I have cobbled together this regular expression, which appeared to work in C#, but when I started rewriting the code for a javascript validation, the regular expression is flagging what I thought were valid passwords as invalid.
Here is the regular expression as I assign it to RegExp:
var regExPatt = new RegExp('^(?=(?:.*[a-zA-Z]){1})(?=(?:.*\d){1})(?=(?:.*[!@@#$%^&*]){1})(?!.*\s).{8,20}$');
*NOTE BENE: The double @@ symbol is there to get the @ symbol into the RegExp, otherwise it tries to treat partial strings like Razor variables and things go sideways fast.
Where did I go wrong with this regular expression? I know it is fairly complicated.
Passwords that work: freddy1234%, freddy123$5, freddy12#45, freddy1@345, freddy!2345
passwords that do not work: test1234%, wilma1234%
Any ideas?
Thanks in advance,
Andrew Giles