JRS: In article <nN*********************@wagner.videotron.net>, seen in
news:comp.lang.javascript, Jeff <pr*******@hotmail.com> posted at Sat,
11 Oct 2003 14:18:47 :-
It's possible to check if it's a valid number in <INPUT...
I try typeof and parseFloat and it's not working. It's seem impossible to
test (with a if) the value "NaN"!!
There is another trap with isNaN(). AIUI, it accepts a too-big number
which means infinity. Infinity is unlikely to be valid in most
applications.
Is the number to be integer? positive? non-negative? if 22 is allowed,
do you need also to accept 2.2e1? How about 022 - is it allowed, and is
its value twenty-two or eighteen? How about 0XED for 237? - or, indeed,
CCXXXVII? If 022 is allowed, hoe about 000000000000000000000000000022?
For the most probable answers to those questions, you would do well to
check the string that <INPUT... "has" in .value with a RegExp. When the
test is passed, convert to number with a unary +, as in the FAQ, 4.21;
and then, if necessary, test the numeric value to be within range.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.