Reputation: 259
I am writing a regular expression for a stronger password which needs atleast one small case letter, upper case letter, one number, one special character and has length=8 or above.
I have the below one regular expression.
/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{8,}/
The problem with this one is it is not considering underscore('_') character as a special character. How can I include this in the list of special characters?
Thanks in advance.
Upvotes: 2
Views: 66
Reputation: 8332
_
is a word-character and thus not included in the \W
(not word) class. Put the \W
inside []
and add the _
like
/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_]).{8,}/
That should do it
Regards
Upvotes: 2