Click here to Skip to main content
15,746,813 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want the Regular Expression for Password Complexity

The password must then contain characters of the following rules:

1- At least one Upper case letter
2- At least Lower case
3- At least one Numbers
4- Disallow the consecutive digits like 1234, 4567, etc.
5- Disallow the consecutive alphabets like abcd, ijkl, etc.

What I have tried:

Updated 30-Jun-22 1:59am

1 solution

Don't. It's a mess at best, and when the rules change - as they always do - the changes are a total PITA as the Regex is massively complex already - if you could implement each of your rules, which I don't think you can - "consecutive numbers" aren't something regular expressions have any concept of.

Remember that Regexes are text matching engines: they don't have any processing power to speak of. Instead, use multiple Regexes to count how many of each type is found, and use those numbers to decide if it's valid or not. That way, when the rules change or a problem is found in your checking, it's simple to implement or fix.

And read this: The Myth of Complex Passwords - Nisos[^]
Share this answer
Maciej Los 2-Jul-22 15:29pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900