Last active
November 14, 2018 04:58
-
-
Save btburton42/69ad028e8ebdd19cb266 to your computer and use it in GitHub Desktop.
ParselyJS Custom Validator for Passwords
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
window.ParsleyValidator.addValidator 'password', (value, requirements) -> | |
requirements = requirements.split ',' | |
regexPatterns = | |
upperCase: '[A-Z]' | |
lowerCase: '[a-z]' | |
number: '[0-9]' | |
symbol: '[@#$%^&!*()_+<>]' | |
isValid = true | |
for key in requirements | |
if isValid && regexPatterns[key]? | |
isValid = false unless value.search(regexPatterns[key]) >= 0 | |
return isValid | |
.addMessage 'en', 'password', 'This password does not meet the requirements.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to your forms constructor and pass in a comma-delimited set of strings like