Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
Last active August 29, 2015 13:58
Show Gist options
  • Save kalinchernev/10388366 to your computer and use it in GitHub Desktop.
Save kalinchernev/10388366 to your computer and use it in GitHub Desktop.
JavaScript password validator
/**
* 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