Reputation: 17128
I tried this expression -
^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$
This regex will enforce these rules:
At least one upper case English letter, (?=.*?[A-Z])
At least one lower case English letter, (?=.*?[a-z])
At least one digit, (?=.*?[0-9])
At least one special character, (?=.*?[#?!@$%^&*-])
Minimum eight in length .{8,}
(with the anchors)
How will be the regular expression for below requirement.
Upvotes: 0
Views: 1021
Reputation: 31508
While a single regex may not be the most readable / sane way to do this, it's actually rather straightforward:
^(?=.*?[a-z])(.{13,}|(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,12})$
I've simply added an alteration on the length so that 13+ chars merely requires [a-z]
while 8-12 chars (one could omit the upper bound due to ordering) requires the full monty.
Upvotes: 0