Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx For Strong Password

Tags:

regex

asp.net

I have the following password requirements:

1) Should be 6-15 characters in length
2) Should have atleast one lowercase character
3) Should have atleast one uppercase character
4) Should have atleast one number
5) Should have atleast one special character
6) Should not have spaces

Can anyone suggest me a RegEx for this requirement?

like image 317
Kumar Avatar asked Mar 06 '10 21:03

Kumar


People also ask

How do you denote special characters in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).


1 Answers

Not sure I would use a Regex for that : regex are not always the right tool for any possible kind of job...

Here, you specified a list of 6 requirements ; so, why not just use 6 different tests, one per requirement ?
Those 6 different tests, should I add, would be really simple -- while a Regex would be much harder to write (you asked for help -- you would probably not have for the 6 tests).

This would make your code a lot more easier to understand, I'd bet ;-)
And also : easier to maintain ; and easier to add/remove/change one of the condition corresponding to one of the requirements.

like image 86
Pascal MARTIN Avatar answered Sep 20 '22 14:09

Pascal MARTIN