Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Comments
Prateek Dalbehera 31-May-16 2:47am    
you are doing password validation in client side or server side. please post the complte code how you are vaLIDATING... May be some encoding issues will be there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900