Suppose you have a HTML form and the form has a text box, in which you want user to only enter numeric value. In order to validate the numeric value you may use the javascript's isNan(
Lets have a running example to depict this concept.
function validateform(x)
{
if (isNaN(x.txtiprice.value))
{
alert('Kindly enter number in price.');
x.txtiprice.focus(); return false;
}
}
form id="frmCheckout" name="frmCheckout" onsubmit="return validateform(this);"
input id="txtiprice" maxlength="50" size="30" name="txtiprice"
inputname="btn" id="btn" value="Submit" type="submit"
/form
We have defined a funciton "validateform()" at the top and then have called it whenever the form "frmcheckout" will be submitted. In the validateform() function, the condion checks that if the value submitted in txtiprice text box is number or not and then return true or false.