Click to See Complete Forum and Search --> : Checking for number entry


florida
04-15-2003, 07:14 AM
Trying to check if an entry into my month field is
a valid entry. My problem is checking to make sure if a number is entered. If a letter is entered I want an alert error. Here is my attempt:


function checkdate(theform)
{
if(theform.month.value<1 || theform.month.value>12) || theform.month.value != \d)
{
alert("invalid month");
return false;
}
}

pyro
04-15-2003, 07:31 AM
How about using regexp? It would look something like: /[0-9]/.test(theform.month.value)

florida
04-15-2003, 09:05 AM
Thanks!

florida
04-15-2003, 11:54 AM
Trying to get focus to work. This gets focus to work but corrupts the validation. any suggestions?

var nbr = Number(theform.month.value);
if (isNaN(nbr.value))
{
alert("Not a number.");
theform.month.focus();
}

florida
04-15-2003, 05:47 PM
It seems to return false everytime no matter number or what is entered. If I take away the focus part it works great but was hoping to get the focus part to work.

florida
04-16-2003, 09:35 AM
Thanks again!