I need a regex pattern that validates a password format.
The rules are:
- Minimum 8 chars in total
- at least two letters
- at least two digits or symbols
I came up with the following:
/((?=.*[0-9\@\&#\$\?\%!\|(){}[]])(?=.*[a-zA-Z]).{8,})/
It will look if both occure once, but I need it toch validate if they occur at least twice.
If I add the {2,} like this:
/((?=.*[0-9\@\&#\$\?\%!\|(){}[]]{2,})(?=.*[a-zA-Z]{2,}).{8,})/
Then the following doesnt work for example: a1a1a1a1a1
Can anybody help me?
This is how you do it, using positive lookaheads: http://regex101.com/r/uW0yI4
/^(?=.*[a-z].*[a-z])(?=.*[!"#...\d].*[!"#...\d]).{8,}$/gmiJust replace
!"#...with all the symbols you want to match.Note: the multiline flag might be unnecessary for your applications.