Skip to content

Instantly share code, notes, and snippets.

@TaylorAckley
Forked from jbutko/script.js
Created October 16, 2016 22:01
Show Gist options
  • Save TaylorAckley/87d519a2ef8055da21f8eef28d8666f6 to your computer and use it in GitHub Desktop.
Save TaylorAckley/87d519a2ef8055da21f8eef28d8666f6 to your computer and use it in GitHub Desktop.
#JS, #RegExp: How To Validate Password With Regular Expression
// 1. approach:
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})
/*
( # Start of group
(?=.*\d) # must contains one digit from 0-9
(?=.*[a-z]) # must contains one lowercase characters
(?=.*[A-Z]) # must contains one uppercase characters
(?=.*[@#$%]) # must contains one special symbols in the list "@#$%"
. # match anything with previous condition checking
{6,20} # length at least 6 characters and maximum of 20
)
*/
// via From http://www.mkyong.com/regular-expressions/how-to-validate-password-with-regular-expression/
// 2. approach:
^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$
/*
^ 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.
*/
// via http://stackoverflow.com/questions/5142103/regex-for-password-strength
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment