I need help in javascript password validation? -
i working on password validation script.
the following code working fine numbers, upper- , lower-case letters.
the problem in .press spacebar key, length more 8, display return true.
not allowed special characters.
$("#password").keyup(function () { var validated = true; if (this.value.length < 8) validated = false; if (!/\d/.test(this.value)) validated = false; if (!/[a-z]/.test(this.value)) validated = false; if (!/[a-z]/.test(this.value)) validated = false; if (!/[@#$%\&^\-\+=!*.?~]/.test(this.value)) validated = false; if (/[^0-9a-za-z@#$%^&+=!*,.?~]/.test(this.value)) validated = false; $('#password_strength').text(validated ? "good" : "too weak");
when checking symbols in password using regex, you'll want escape them they're taken literal character, not regex meaning of character. more information, recommend checking out:
http://www.javascriptkit.com/javatutors/redev2.shtml
https://developer.mozilla.org/en-us/docs/javascript/guide/regular_expressions
Comments
Post a Comment