My password strength criteria is as below :
- 8 characters length
- 2 letters in Upper Case
- 1 Special Character
(!@#$&*)
- 2 numerals
(0-9)
- 3 letters in Lower Case
Can somebody please give me regex for same. All conditions must be met by password .
My password strength criteria is as below :
(!@#$&*)
(0-9)
Can somebody please give me regex for same. All conditions must be met by password .
Another solution:
I would suggest adding
You can use zero-length positive look-aheads to specify each of your constraints separately:
If your regex engine doesn't support the
\p
notation and pure ASCII is enough, then you can replace\p{Lu}
with[A-Z]
and\p{Ll}
with[a-z]
.You can do these checks using positive look ahead assertions:
Rubular link
Explanation:
Password must meet at least 3 out of the following 4 complexity rules,
[at least 1 uppercase character (A-Z) at least 1 lowercase character (a-z) at least 1 digit (0-9) at least 1 special character — do not forget to treat space as special characters too]
at least 10 characters
at most 128 characters
not more than 2 identical characters in a row (e.g., 111 not allowed)
'^(?!.(.)\1{2}) ((?=.[a-z])(?=.[A-Z])(?=.[0-9])|(?=.[a-z])(?=.[A-Z])(?=.[^a-zA-Z0-9])|(?=.[A-Z])(?=.[0-9])(?=.[^a-zA-Z0-9])|(?=.[a-z])(?=.[0-9])(?=.*[^a-zA-Z0-9])).{10,127}$'
(?!.*(.)\1{2})
(?=.[a-z])(?=.[A-Z])(?=.*[0-9])
(?=.[a-z])(?=.[A-Z])(?=.*[^a-zA-Z0-9])
(?=.[A-Z])(?=.[0-9])(?=.*[^a-zA-Z0-9])
(?=.[a-z])(?=.[0-9])(?=.*[^a-zA-Z0-9])
.{10.127}