Skip to content

Instantly share code, notes, and snippets.

@dkesberg
Last active December 28, 2015 09:39
Show Gist options
  • Save dkesberg/7480990 to your computer and use it in GitHub Desktop.
Save dkesberg/7480990 to your computer and use it in GitHub Desktop.
/**
* Password regex
* ^ # Bind the RegExp to the beginning of the string.
* (?=.{8,}) # Followed by 8 or more characters (min length)
* (?=.*\d) # At least one digit.
* (?=.*[a-z]) # At least one lower-case character.
* (?=.*[A-Z]) # At least one upper-case character.
* .*\z # Followed by any number of characters, before the end of the string.
*/
jQuery.validator.addMethod("password", function(value, element) {
return this.optional(element) || /^(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/.test(value);
}, "Invalid password format. You must use at least 8 characters. Your password must contain uppercase and lowercase letters and digits.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment