Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

64 of 85 people (75%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

how can I do a javascript edit check for floating point number on a form.

Feb 24th, 2009 23:22
haytham ali, 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.forums.msryat.org
http://www.msryat.org
http://www.dir.msryat.org
http://www.games.msryat.org
http://www.3lmbnat.com
http://www.dir.3lmbnat.com
http://www.vb.3lmbnat.com
http://www.qtryat.com
http://www.qtryat.com/vb
http://forums.msryat.org/forumdisplay.php?f=2
http://forums.msryat.org/forumdisplay.php?f=3
http://forums.msryat.org/forumdisplay.php?f=84
http://forums.msryat.org/forumdisplay.php?f=4
http://forums.msryat.org/forumdisplay.php?f=118
http://forums.msryat.org/forumdisplay.php?f=44
http://forums.msryat.org/forumdisplay.php?f=69
http://forums.msryat.org/forumdisplay.php?f=85
http://forums.msryat.org/forumdisplay.php?f=91
http://forums.msryat.org/forumdisplay.php?f=70
http://forums.msryat.org/forumdisplay.php?f=73
http://forums.msryat.org/forumdisplay.php?f=57
http://forums.msryat.org/forumdisplay.php?f=6
http://forums.msryat.org/forumdisplay.php?f=7
http://forums.msryat.org/forumdisplay.php?f=61
http://forums.msryat.org/forumdisplay.php?f=68
http://forums.msryat.org/forumdisplay.php?f=92
http://forums.msryat.org/forumdisplay.php?f=101
http://forums.msryat.org/forumdisplay.php?f=10
http://forums.msryat.org/forumdisplay.php?f=11
http://forums.msryat.org/forumdisplay.php?f=43
http://forums.msryat.org/forumdisplay.php?f=51
http://forums.msryat.org/forumdisplay.php?f=81
http://forums.msryat.org/forumdisplay.php?f=80
http://forums.msryat.org/forumdisplay.php?f=14
http://forums.msryat.org/forumdisplay.php?f=15
http://forums.msryat.org/forumdisplay.php?f=16
http://forums.msryat.org/forumdisplay.php?f=87
http://forums.msryat.org/forumdisplay.php?f=18
http://forums.msryat.org/forumdisplay.php?f=50
http://forums.msryat.org/forumdisplay.php?f=90
http://forums.msryat.org/forumdisplay.php?f=89
http://forums.msryat.org/forumdisplay.php?f=95
http://forums.msryat.org/forumdisplay.php?f=102
http://forums.msryat.org/forumdisplay.php?f=19
http://forums.msryat.org/forumdisplay.php?f=20
http://forums.msryat.org/forumdisplay.php?f=21
http://forums.msryat.org/forumdisplay.php?f=71
http://forums.msryat.org/forumdisplay.php?f=96
http://forums.msryat.org/forumdisplay.php?f=98
http://forums.msryat.org/forumdisplay.php?f=97
http://forums.msryat.org/forumdisplay.php?f=99
http://forums.msryat.org/forumdisplay.php?f=100
http://forums.msryat.org/forumdisplay.php?f=52
http://forums.msryat.org/forumdisplay.php?f=66
http://forums.msryat.org/forumdisplay.php?f=23
http://forums.msryat.org/forumdisplay.php?f=24
http://forums.msryat.org/forumdisplay.php?f=25
http://forums.msryat.org/forumdisplay.php?f=26
http://forums.msryat.org/forumdisplay.php?f=62
http://forums.msryat.org/forumdisplay.php?f=63
http://forums.msryat.org/forumdisplay.php?f=65
http://forums.msryat.org/forumdisplay.php?f=64
http://forums.msryat.org/forumdisplay.php?f=47
http://forums.msryat.org/forumdisplay.php?f=67
http://forums.msryat.org/forumdisplay.php?f=48
http://forums.msryat.org/forumdisplay.php?f=29
http://forums.msryat.org/forumdisplay.php?f=86
http://forums.msryat.org/forumdisplay.php?f=49
http://forums.msryat.org/forumdisplay.php?f=30
http://forums.msryat.org/forumdisplay.php?f=31
http://forums.msryat.org/forumdisplay.php?f=88
http://forums.msryat.org/forumdisplay.php?f=32
http://forums.msryat.org/forumdisplay.php?f=33
http://forums.msryat.org/forumdisplay.php?f=78
http://forums.msryat.org/forumdisplay.php?f=34
http://forums.msryat.org/forumdisplay.php?f=103
http://forums.msryat.org/forumdisplay.php?f=109
http://forums.msryat.org/forumdisplay.php?f=104
http://forums.msryat.org/forumdisplay.php?f=105
http://forums.msryat.org/forumdisplay.php?f=106
http://forums.msryat.org/forumdisplay.php?f=108
http://forums.msryat.org/forumdisplay.php?f=110
http://forums.msryat.org/forumdisplay.php?f=111
http://forums.msryat.org/forumdisplay.php?f=112
http://forums.msryat.org/forumdisplay.php?f=113
http://forums.msryat.org/forumdisplay.php?f=114
http://forums.msryat.org/forumdisplay.php?f=115
http://forums.msryat.org/forumdisplay.php?f=116
http://forums.msryat.org/forumdisplay.php?f=117
http://forums.msryat.org/forumdisplay.php?f=36
http://forums.msryat.org/forumdisplay.php?f=37
http://forums.msryat.org/forumdisplay.php?f=72
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