JavaScript: How to Remove All Commas From a Number
The following can be used in JavaScript to remove all commas from a number:
var StartNumber = ‘444,555,666‘;
var ReplacedNumber = StartNumber.replace(/\,/g,‘‘);
document.write(ReplacedNumber);
The preceding example uses the JavaScript replace function and utilizes a regular expression to replace all the commas in a number. In the regular expression, the backslash (\) before the comma is used as an escape character, meaning that the comma should be treated as a literal comma. The ‘g‘ means that the replace should be applied globally. Without this, only the first comma would be removed.
Related articles:
JavaScript replace Function
JavaScript Regular Expression Backslash
Ahh, finally a comma replace script that works for me! And it’s so simple! I kept trying other replace scripts, and they would all give me errors, but this one works great. Thanks!
thanks !! it worked well (Y)
Ditto JDub. This one WORKS! Thank you so much, Joey.
shouldn’t “FormNumber” in the 2nd line actually be StartNumber??
Worked great, thanks!
Bubba, good catch. This has been corrected in the post.
Worked great! Thanks!
Thanks dude. it worked fine.
Thats worked awesome, thanks for the info
Just what I needed….and works perfectly
thanks man! it helped me