JavaScript Password Validation
Here we see that how to validate any password field. Like password field can be blank and length of password is minimum 8 characters.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<!DOCTYPE html> <html> <head> <script> functionpass_validation() { var password=document.myform.password.value; if (password==null || password=="") { alert("password can't be blank"); return false; } else if(password.length<8) { alert("Password must be at least 8 characters long."); return false; } } </script> </head> <body> <form name="myform" method="post" action="register.php" onsubmit="return pass_validation()" > Password: <input type="password" name="password"> <input type="submit" value="submit"> </form> </body> </html> |