View Full Version : Validation Script & Error Message Help

Jus S
07-29-2008, 02:50 PM
The inputs to the form below is supposed to be validated using the script below. If the user does not use all numbers, a message is supposed to appear next to the "validate" button saying "The input is not numeric." Can someone help me on this?

<form id="form1" name="form1" action="#">
<table align='center'>
<td><input name="numeric" id="numeric" validation="required" /><input type="submit" value=" Validate " onclick="IsNumeric();" /></td>

<script type="text/javascript">
function IsNumeric(sText) {
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i=0;i<sText.length && IsNumber == true; i++) {
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
return IsNumber;

07-29-2008, 03:27 PM
Use Regular Expressions instead:

Jus S
07-29-2008, 04:34 PM
I just solved my own problem. Thanks to all for looking at this.