/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke
ISBN: 067231763X
Publisher Sams CopyRight 2000
*/
<html>
<head>
<title>Integer Validation</title>
<script language="JavaScript">
<!--begin script
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;
}
// end script-->
</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>
|