Last active
October 16, 2016 22:01
-
-
Save jbutko/696fc165c44983a26cce to your computer and use it in GitHub Desktop.
#JS, #RegExp: How To Validate Password With Regular Expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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