Validate an field with a maximum number of characters : Validation : Form Control JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Form Control » Validation »

 

Validate an field with a maximum number of characters




<html>

<head>
<script type="text/javascript">
function validate(){
    x=document.myForm
    input=x.myInput.value
    if (input.length>5){
        alert("The field cannot contain more than 5 characters!")
        return false
    }else {
        return true
    }
}
</script>
</head>

<body>
<form name="myForm" action="http://www.navioo.com" onsubmit="return validate()">
Enter some text (less than characters):
<input type="text" name="myInput" size="20">
<input type="submit" value="Submit">
</form>
</body>

</html>




           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Form Control
» Validation