I’m again struggling with some regex syntax for a password validation.
The rules for a password are:
- must contain at least number
- must contain at least one special character of the set
. : , ; - $ % _ = ! ? - must NOT contain other special characters than the set above in rule 2
- may contain one or more regular word characters lowercase or uppercase
I’ve come so far:
var regex = /.*(?=.*[\.:,;\-\$%=\!\?])(?=.*\d).*/;
But this does only meet the rules 1 and 2 and allows any other special characters.
Can anyone help?
Putting it all together
And if you want to enforce a minimal length you can use
{6,}or something similar,