Re: How to format textbox value before sum?



JRS: In article <B6adnXAmDdmFs5DZRVn-vw@xxxxxxxxxxx>, dated Tue, 7 Mar
2006 01:54:30 remote, seen in news:comp.lang.javascript, Randy Webb
<HikksNotAtHome@xxxxxxx> posted :

var n = +f[i].value.replace(' ','').replace('.','').replace(',','');

Will remove any spaces, commas or periods (dot). Makes me wonder what
happens if it has a decimal part to it though......

In a function UpdateBudget, one should not expect decimal parts. "A
billion here, a billion there - it soon adds up to real money" (approx).

Assuming your answer to have only the obvious answer-affecting error,

var n = +f[i].value.replace(/[\. ,]/g, "")

in which, in my system, the \ is not actually needed.

--
© 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: Email Validation
    ... phoebe posted: ... The best you could do by that is to check for the presence of at & dot, ... But a RegExp test is simpler and more effective; ... TP/BP/Delphi/jscr/&c, FAQ items, links. ...
    (microsoft.public.scripting.jscript)
  • Re: Scan frequencies for a Sony KV-20S20
    ... the EU prefers commas to delimit decimals. ... God only ... What is wrong with a dot, ...
    (sci.electronics.repair)
  • Re: How to format textbox value before sum?
    ... One textbox contains for example the value "2 100". ... Maybe it's easier to say that space, dot or comma should be eliminated. ... Test it for all digits after removing spaces commas and periods. ... if it contains non-digits you tell the user they have incorrect input. ...
    (comp.lang.javascript)
  • Re: Optimize this code
    ... More briefly done with a RegExp as in ... This counts commas by a simpler implementation of the ped3estrian ... If the first and last characters cannot be commas, ... TP/BP/Delphi/jscr/&c, FAQ items, links. ...
    (comp.lang.javascript)
  • Re: Newbie: input file with commas like this: (, ,)
    ... I.e. commas and periods are token constituent characters. ... Any tricky cases? ... Could the data contain instances of the dot which are in fact ...
    (comp.lang.lisp)

Loading