Skip to content

Instantly share code, notes, and snippets.

@btburton42
Last active November 14, 2018 04:58
Show Gist options
  • Save btburton42/69ad028e8ebdd19cb266 to your computer and use it in GitHub Desktop.
Save btburton42/69ad028e8ebdd19cb266 to your computer and use it in GitHub Desktop.
ParselyJS Custom Validator for Passwords
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.'
@btburton42
Copy link
Author

Add this to your forms constructor and pass in a comma-delimited set of strings like

<input data-parsley-password="upperCase,number,symbol"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment