JRS: In article <11**********************@i40g2000cwc.googlegroups .com>
, dated Sun, 12 Mar 2006 11:36:01 remote, seen in
news:comp.lang.javascript,
bd***@hotmail.com posted :
Got it I think:
var NumericRegExp =/^\d+(\.[0]{0,2})?$/;
var regex = new RegExp(NumericRegExp);
if (!regex.test(a)){
alert(a + " is not a valid for this field.");
return false;
}
else {
alert("Ok");
}
That above allows 0 0. 0.00 the middle of which is poor practice and
not included in what you asked for. Decimal points, being little,
should always be guarded by at least one digit in each side.
OK = /^\d+(\.00)?$/.test(a)
I prefer the structure
OK = <test>
if (!OK) <complain>
return OK
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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.