Australia/Sydney
BlogApril 3, 2007

Validating Numeric Values in Textbox in Forms

Fahd Mirza
This is one of those "non-Oracle" posts, I would be dropping here once in a while.

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() function. isNan() function checks that if its argument is Not a Number, if it is not, then it returns true otherwise it returns true.

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.
Share this post:
On this page

Let's Partner

If you are looking to build, deploy or scale AI solutions — whether you're just starting or facing production-scale challenges — let's chat.

Subscribe to Fahd's Newsletter

Weekly updates on AI, cloud engineering, and tech innovations