RegEx For Strong Password

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

I’m not entirely sure what you mean by “special character” so I am interpreting this to mean W, but you can change this if you want:

^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*W)S{6,15}$

Method 3

Regexlib.com has tons of examples for you and a searchable database of reg ex’s.

Method 4

1 => /^.{6,15}$/
2 => /[a-z]/
3 => /[A-Z]/
4 => /d/
5 => /[#{special_chars_for_regex}]/
6 => /^S*$/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x