Skip to content

Instantly share code, notes, and snippets.

@ebta
Last active August 30, 2022 09:34
Show Gist options
  • Save ebta/01cd04c41036c38be417e8e345d32e76 to your computer and use it in GitHub Desktop.
Save ebta/01cd04c41036c38be417e8e345d32e76 to your computer and use it in GitHub Desktop.
Regexp Password Validation

Minimum eight characters, at least one letter and one number:

^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$

Minimum eight characters, at least one letter, one number and one special character:

^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$

Minimum eight characters, at least one uppercase letter, one lowercase letter and one number:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$

Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

Minimum eight and maximum 10 characters, at least one uppercase letter, one lowercase letter, one number and one special character:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,10}$

With Description

You may use this regex with multiple lookahead assertions (conditions):

^(?=.*?[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)

Ref: https://stackoverflow.com/a/21456918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment