<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Validate Field With Only Digits Allowed</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005, 2006 Roderick Divilbiss">
<script type="text/javascript">
<!--
function checkDigitsOnly(fld) {
var phone = fld.value;
var RegExPattern = /^[0-9]+$/;
if ((phone.match(RegExPattern)) && (phone!='')) {
return true;
} else {
alert("Phone number contains invalid characters!\n Only Numbers are allowed.\n\t 5555555555"); //if any invalid chars
fld.focus();
return false;
}
}
//-->
</script>
</head>
<body>
<input type="text" name="intPhone" onblur="checkDigitsOnly(this);" size="25" />
</body>
</html>
© Coyright 2000-2008, Roderick (Rod) W. Divilbiss. Some rights reserved.
Except where otherwise noted, this site, all content, and all source code and markup is licensed under a Creative Commons License
Creative Commons License.
No part of this web site including all application code and examples may be used for commercial purposes without prior written permission from the author,
Roderick W. Divilbiss of Overland Park, Kansas, United States of America.