Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating a Numeric Textfield

Status
Not open for further replies.

Kush

Programmer
Sep 20, 2000
24
0
0
US
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;
}

Thanks for any help.
 
if (typeof(smth)!="number") {alert('allowed numbers only')} regards, vic
 
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.

if(isNaN(input_var.value))
{
alert('Enter numbers only.');
return false;
}
 
Ooops, dianal beat me to it. Sorry bout that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top