Link to home
Start Free TrialLog in
Avatar of Elliott Ward
Elliott Ward

asked on

I need help with a .NET Regex password expression

The requirements for the expression are:
- No more than two characters can repeat
- Minimum size of 8 characters
- Must contain a least one upper case character
- Must contain a least one special character
- Must contain at least one numeric digit

I have already tried Reglib but am not familiar enough with them to create this expression. Any suggestions?

Thank you for your help
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

By "No more than two characters can repeat" I interpret this as allowing:
abababab1&
but not
aaababa1&

Try this (I'm just about to test it now though!):
^(?=.*[-`~!@#$%\^&*()_+=\[\]{}\\|;':",./<>?])(?=.*\d)(?=.*[A-Z])(?!.*?(.)\1\1)).{8,}
After testing, I needed to make a minor change. This appears to work:
^(?=.*[-`~!@\#$%\^&*()_+=\[\]{}\\|;':",./<>?])(?=.*\d)(?=.*[A-Z])(?:(?!(.)\1\1).){8,}$
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Elliott Ward
Elliott Ward

ASKER

Thank you both for your assistance. This is exactly what I needed.