How can I validate that the text enterd by the user is numeric?
For example, I want to make sure that input_var.value is a number
if(input_var.value "is not a number"
{
alert('Enter numbers only.');
return false;
}
Another way:
if (isNaN(input_var.value)) {
alert('Enter numbers only.');
return false;
}
isNaN function returns true if the value is NaN(not a number), and false otherwise.
I've never used it before, so the function I wrote may not work as is, but isNaN is definitely the way to go in your case. Due to my lack of knowledge of the isNaN function, I would suggest trying to find someinfo on it. Might I suggest devguru.com ? That place has some swell quick refferences to stuff. Hope this at least helps point you in the right direction.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.