Re: trouble with replace

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.
.



Relevant Pages

  • Re: re CalcPlus - FREE from Microsoft.
    ... No, do not validate Windows at this time, but take me to the download. ... Even where it sys you MUST validate you can always get it. ... >>> Includes Currency Convertor, ...
    (microsoft.public.windowsxp.basics)
  • Re: trouble with replace
    ... 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 characters are being replaced. ...
    (microsoft.public.scripting.jscript)
  • allow all currency symbols
    ... Is there a way I can validate the input on a textbox for currency ... including all currency symbols.. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How do I validate these fields
    ... digits is entered ... Validate by calculation: length= 4 ... "validate for 4 digit year". ... FileMaker Konferenz in Zürich Mai 2010 ...
    (comp.databases.filemaker)
  • help with cobol date
    ... I am trying to accept a date and validate it against today's date. ... I am getting the user to enter a date - 8 digits ddmmyyyy. ... date is comming out as YYMMDD, ... Is there a simplier way to check that the users date is less than ...
    (comp.lang.cobol)