Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi All,

I need a password validation regex.

At least 8 characters.
Special character - @ only
Alphanumeric
Uppercase - at least one
Lowercase - at least one



Here is my current regex:

^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!*@#$%^&+=]).*$

but it accept different kinds of special character. Please help.
Thank you!
Posted

Try this

(?=^.{8,}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s)[0-9a-zA-Z@\-]*$

Look RegExLib[^] for other examples
 
Share this answer
 
v2
This should work, I think.

^(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9@]{8,}$


This is a good page for getting info about regular expressions.
http://www.regular-expressions.info/[^]

This a good tool for testing regular expressions in an editor.
Regextest[^]
 
Share this answer
 

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