Created
December 13, 2016 11:53
-
-
Save anonymous/544379003f421bcdc791b040b7eeadb4 to your computer and use it in GitHub Desktop.
password validation example JS
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
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