Skip to content

Instantly share code, notes, and snippets.

@leandromoh
Created December 26, 2016 15:48
Show Gist options
  • Save leandromoh/470b0b54208f02a9ba223cdbdd1534bd to your computer and use it in GitHub Desktop.
Save leandromoh/470b0b54208f02a9ba223cdbdd1534bd to your computer and use it in GitHub Desktop.
Regex to validate password strength
^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$
Explanation:
^ Start anchor
(?=.*[A-Z].*[A-Z]) Ensure string has two uppercase letters.
(?=.*[!@#$&*]) Ensure string has one special case letter.
(?=.*[0-9].*[0-9]) Ensure string has two digits.
(?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
.{8} Ensure string is of length 8.
$ End anchor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment