I'm writing a regular expression for validating a password.
I wanted to know the easiest way to make a regular expression accept at least two of these conditions:
At this point, I have the following regular expression:
"(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{4,20}";
where:
(?=.*\d)
: Accept at least one number.
(?=.*[a-z])
: Accept at least one lowercase letter.
(?=.*[A-Z])
: Accept at least one uppercase letter. (?=.*[@#$%])
: Accept at least one symbol. < {4,20}
: Password between 4 and 20 characters.
The problem is that, in order for the password to pass in this validation process, the password must have mandatory one of these symbols. That is, a password must have a number, a lowercase letter, a capital letter and a symbol.
What I want is for the password to respect two or more conditions .
Example :
- A password with a lowercase letter and a symbol is accepted (from encounter with both conditions).
- A password with a lowercase letter, a capital letter, and a symbol is also accepted.
- A lowercase password is not accepted.