homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Javascript Error
Numeric Validation Fails

 8:55 pm on Mar 5, 2003 (gmt 0)

The following code is failing for some reason:

var error = 0;
var error_message = "Errors have occured during the process of your form!\nPlease make the following corrections:\n\n";
var bid = document.make_bid.customer_bid.value;

if (IsNumeric(bid) == false) {
error_message = error_message + "* Bid must be numeric!\n";
error = 1;

bid gets the value of document.make_bid.customer_bid.value ok but the statement "if (IsNumeric(bid) == false)" is failing whether the input field contents are numeric or not!

Any help gratefully received!



 9:02 pm on Mar 5, 2003 (gmt 0)

Sorry folks, it doesn't work because I am stupid!
I forgot to include the following code (forgetting that IsNumeric isn't a javascript function):

function IsNumeric(strString)
// check for valid numeric strings
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
blnResult = false;
return blnResult;


 12:42 pm on Mar 6, 2003 (gmt 0)

IsNumeric("0-0-2...5-1") returns true;

Guessing that a negative Bid is not accepatble i would use this function instead

function isNumber(str){
numdecs = 0;
for (i = 0; i < str.length; i++){
mychar = str.charAt(i);
if ((mychar >= "0" && mychar <= "9") mychar == "."){
if (mychar == ".")
else return false;

if (numdecs > 1)
return false;

return true;


 12:47 pm on Mar 6, 2003 (gmt 0)

I hope you do not rely on those JavaScript checks and check any user submitted values again in your server side script. If not, you really should treat any user submitted data as tainted and highly insecure.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved