Minimum Character Validation

In JavaScript we can check the numbers of characters entered in Text Box and validate minimum or maximum numbers of characters in textbox.
example:

<html>
<script>
function validate() {
var password = document.myForm.txtPassword.value;
if(password.length<8) { alert("Password should be minimum 8 character long"); password.focus(); return false; } else { return true; } } </script> <body> <form onSubmit="return validate()" name="myForm"> Password : <input type="password" id="txtPassword"/> <br/> <input type="submit" id="submit" value="Submit"/> </form> </body> </html>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.