I have the following criteria for creating a regular expression for a password that conforms to the following rules:
- The password must be 8 characters long (this I can do :-)).
The password must then contain characters from at least 3 of the following 4 rules:
- Upper case
- Lower case
- Numbers
- Non-alpha numeric
I can make the expression match ALL of those rules with the following expression:
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.[\W]).{8,}$/
But I am struggling with how to do this in such a way that it only needs to solve any 3 of the 4 rules.
Can anyone help me out with this?
Don’t use one regex to check it then.
If you must use a single regex:
This regex is not optimized for efficiency. It is constructed by
A·B·C + A·B·D + A·C·D + B·C·Dwith some factorization. Breakdown: