![]() |
|
|
+ Search |
![]()
|
Apr 4th, 2008 19:47
ha mo, Iván Rivera, Robin Jaggassar,
You only have to remember that JavaScript sees all values of form
elements as text strings. The easiest way to check if a certain string
is a floating point number is applying to it the parseFloat() global
function, which returns the floating point number that corresponds to a
given string (parseFloat('42.4242') returns 42.4242 as a number), or NaN
(not a number) if the string given is not a valid representation for a
floating point number.
The global function isNaN() helps also, determining if a given number is
NaN or some other thing (a real number, infinite or minus infinite). So
your validation code could look like this:
myString=myForm.myInputText.value;
if (isNaN(parseFloat(myString))) alert('Not a number');
There is also a isInfinite() global function to help with the infinite
case, working the same way than isNaN().
I hope this was useful...
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com