Last active
December 28, 2015 09:39
-
-
Save dkesberg/7480990 to your computer and use it in GitHub Desktop.
jQuery Validator method for passwords regex from http://forums.phpfreaks.com/topic/273119-yet-another-password-regex/?p=1405494
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 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