Tuesday, April 3, 2007

Validating Numeric Values in Textbox in Forms

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"


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.


Unknown said...

Nice! But for me it was more pleasing to see that it is opening here in my office.

sara said...

Assalamu alaika brother Fahd..

Dunno if you remember me, but I sure do remember you..
I just wanted to ask, do you have any idea where did brother Jawad go?

With respect,

Moin Peerzada said...

Hi, are you the Fahd who blogs frequently at Chowrangi ? You are the inspiration for my blog. Hope you will enjoy my writing as much as I do yours. Take care.

Katherine H. Wheeler said...

FPTV of Foreign Policy magazine just released our interview with the Pakistani Ambassador to the US Mahmud Ali Durrani. Check it out and post it on your blog.