JRS: In article <40**********************@news.newsgroups.ws>, seen in
news:comp.lang.javascript, Mark <an*******@devdex.com> posted at Sat, 12
Jun 2004 09:01:34 :
Hi - can anyone give me a sample of how I would ensure a value in a text
box was a decimal (it is used for entering money - so has to check for
no more than 2 decimal places, but still allow should no decimals be
input) - eg.
23 - ok
23.01 - ok
23.1 - ok
23.111 - not valid
Thanks for any help,
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
How do you propose, then, to reward us for our assistance?
The third case should NOT be allowed, since it could be intended to mean
either 23.01 or 23.10 - proper money format, in most countries, is an
integer optionally followed by (point digit digit).
The point is adequately explained in p.19 of the free booklet "your
guide to decimal money" - in which Lord Fiske asserts that copies are
being delivered to every household - published by HMSO about 1970.
The basic RegExp is of the form /^\d+(\.\d\d)?$/
See also <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.