»
EnglishFrenchVietnamese

Print - Validation (password) - JavaScriptBank.com

Full version: jsB@nk » Form » Validation » Validation (password)
URL: https://www.javascriptbank.com/validation-password.html

Validation (password) © JavaScriptBank.comThis JavaScript works like our Password Verifier, however, it also checks for a minimum length and invalid characters.

Full version: jsB@nk » Form » Validation » Validation (password)
URL: https://www.javascriptbank.com/validation-password.html



JavaScript
<SCRIPT LANGUAGE="JavaScript">// Russ Swift (rswift220@yahoo.com)<!-- Beginfunction validatePwd() {var invalid = " "; // Invalid character is a spacevar minLength = 6; // Minimum lengthvar pw1 = document.myForm.password.value;var pw2 = document.myForm.password2.value;// check for a value in both fields.if (pw1 == '' || pw2 == '') {alert('Please enter your password twice.');return false;}// check for minimum lengthif (document.myForm.password.value.length < minLength) {alert('Your password must be at least ' + minLength + ' characters long. Try again.');return false;}// check for spacesif (document.myForm.password.value.indexOf(invalid) > -1) {alert("Sorry, spaces are not allowed.");return false;}else {if (pw1 != pw2) {alert ("You did not enter the same new password twice. Please re-enter your password.");return false;}else {alert('Nice job.');return true;      }   }}//  End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name=myForm onSubmit="return validatePwd()">Enter your password twice.<br>(At least 6 characters, 12 characters max, and spaces are not allowed.)<p>Password: <input type=password name=password maxlength=12><br>Verify password: <input type=password name=password2 maxlength=12><p><input type=submit value="Submit"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->