JRS: In article <200420040733235484%denmarks (AT) domain (DOT) invalid>, seen in
news:comp.lang.javascript, Dennis M. Marks <denmarks (AT) domain (DOT) invalid>
posted at Tue, 20 Apr 2004 07:33:23 :
Quote:
What is the best way to validate a field as a positive or negative
integer? |
How about a zero one? Do you want to allow a floating-point form of a
value which happens to be integer, such as 1e6 or 3.000 ? How about
0xFF ?
OK = /^[+-]?\d+$/.test(field)
tests for optional sign followed by only decimal digits. \d{1,6} might
be preferred, likewise [+- ] .
See <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.
--
© 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> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.