Forked from pmarreck/complex_password_validation.rb
Created
November 8, 2018 09:34
-
-
Save vigosan/71133bc77554c6c66b3396ce88aee958 to your computer and use it in GitHub Desktop.
Example of using regex to check a complex password validation requirement ("use at least 1 character from 3 sets of characters out of a total of 4 sets of characters")
This file contains hidden or 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
PASSWORD_VALIDATOR = /( # Start of group | |
(?: # Start of nonmatching group, 4 possible solutions | |
(?=.*[a-z]) # Must contain one lowercase character | |
(?=.*[A-Z]) # Must contain one uppercase character | |
(?=.*\W) # Must contain one non-word character or symbol | |
| # or... | |
(?=.*\d) # Must contain one digit from 0-9 | |
(?=.*[A-Z]) # Must contain one uppercase character | |
(?=.*\W) # Must contain one non-word character or symbol | |
| # or... | |
(?=.*\d) # Must contain one digit from 0-9 | |
(?=.*[a-z]) # Must contain one lowercase character | |
(?=.*\W) # Must contain one non-word character or symbol | |
| # or... | |
(?=.*\d) # Must contain one digit from 0-9 | |
(?=.*[a-z]) # Must contain one lowercase character | |
(?=.*[A-Z]) # Must contain one uppercase character | |
) # End of nonmatching group with possible solutions | |
.* # Match anything with previous condition checking | |
)/x # End of group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment