Mega Code Archive

 
Categories / JavaScript DHTML / Form Control
 

Creating Reusable Validation Code

<html> <head> <title>Integer Validation</title> <script language="JavaScript"> <!-- function isInt(textObj) {    var newValue = textObj.value;    var newLength = newValue.length;    for(var i = 0; i != newLength; i++) {       aChar = newValue.substring(i,i+1);       if(aChar < "0" || aChar > "9") {          return false;       }    }    return true; } // --> </script> </head>     <body> <h1>Integer Validation</h1> <form name="form1"> <input type="text" size=16 maxlength=16 name="data"> <input type="button" name="CheckButton" value="Validate" onClick="document.form1.result.value = '' + isInt(document.form1.data)"> <br> Result <input type="text" size=16 maxlength=16 name="result"> </form> </body> </html>