Last active
August 29, 2015 13:58
-
-
Save kalinchernev/10388366 to your computer and use it in GitHub Desktop.
JavaScript password validator
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
/** | |
* Validates if the input for password field matches requirements for password strength | |
* @returns {void} | |
*/ | |
function validatePassword() { | |
var inputValue; | |
var requirement = new RegExp("(^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[@#$%*]).{8,}$)"); | |
// clear previous | |
jQuery(".reg-validate-message").remove(); | |
inputValue = jQuery(this).val(); | |
if (requirement.test(inputValue)) { | |
jQuery(this).after("<span class='reg-validate-message alert alert-success'>Password is good!<i class='icon-fix icon-ok'></i></span>"); | |
} else { | |
jQuery(this).after("<span class='reg-validate-message alert alert-error'>Password is not good enough!<i class='icon-fix icon-exclamation-sign'></i></span>"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment