...

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>
</table>
</form>

<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;
}
</script>

Kor
07-29-2008, 03:27 PM
Use Regular Expressions instead:
http://lawrence.ecorp.net/inet/samples/regexp-intro.php
http://lawrence.ecorp.net/inet/samples/regexp-validate2.php

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum