Re: trouble with replace
- From: Dr John Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 13 Aug 2005 15:47:35 +0100
JRS: In article <1123825897.593283.139680@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
, dated Thu, 11 Aug 2005 22:51:37, seen in news:microsoft.public.scripti
ng.jscript, Ben <b.eppel@xxxxxxxxx> posted :
>sorry for being too vague. What I want to do is remove all Currency
>symbols so that I can validate the number. I am in South Africa and so
>the symbol is "R" and so the value is likely to be input with a "R" - I
>need to remove all the valid non-numbers so that I can validate the
>remaining characters. Plus I want to remove decimal points so that the
>number can be stored as an integer.
Presuming that your customers know that the currency is Rand, it's
reasonable to remove a single leading R.
But unless you can guarantee that they will always put a decimal point
followed by exactly two digits it is most unwise just to remove the
point. R3 = R3.00 but 3 !- 300 .
You should validate with a RegExp for optional R followed by at least
one digit followed by (optional?) (point followed by two digits); or
remove leading R and validate the numeric part.
Once the numeric part is known valid, you can convert from String to
Number with a unary + and multiply by 100 (good : c is exact bur R.c
will have rounding errors).
See in <URL:http://www.merlyn.demon.co.uk/js-valid.htm> etc.
--
© 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.
.
- References:
- trouble with replace
- From: Ben
- Re: trouble with replace
- From: Martin Honnen
- Re: trouble with replace
- From: Ben
- trouble with replace
- Prev by Date: Re: 2 Qs re JS scripting
- Next by Date: Re: 2 Qs re JS scripting
- Previous by thread: Re: trouble with replace
- Next by thread: How do I keep count...
- Index(es):
Relevant Pages
|