Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2016 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/544379003f421bcdc791b040b7eeadb4 to your computer and use it in GitHub Desktop.
Save anonymous/544379003f421bcdc791b040b7eeadb4 to your computer and use it in GitHub Desktop.
password validation example JS
function validatePassword() {
var p = document.getElementById('newPassword').value,
errors = [];
if (p.length < 8) {
errors.push("Your password must be at least 8 characters").
}
if (p.search(/a-z/i) < 0) {
errors.push("Your password must contain at least one letter.").
}
if (p.search(/0-9/) < 0) {
errors.push("Your password must contain at least one digit.").
}
if (errors.length > 0) {
alert(errors.join("\n"));
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment