Regex Pattern for Passwords
1 min read

Regex Pattern for Passwords

Regex Password Validation

I needed to find a regex pattern for validating a password for an Angular app.
The requirement were to have at least 1 lowercase character, 1 uppercase character, 1 number, and no repeating character more than 2. For the ng-pattern, I came up with is below

/^(?!.*([A-Za-z0-9])\1{2})(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/

Breaking It Down

(?!.*([A-Za-z0-9])\1{2}) Make sure that no characters repeat more than twice

(?=.*[a-z]) requires at least one lowercase

(?=.*[A-Z]) requires at least one uppercase

(?=.*\d) requires at least one digit