[Javascript] Number formatting

joel.goldstick at columbuswebmakers.com joel.goldstick at columbuswebmakers.com
Thu Jun 29 15:03:48 CDT 2006


Liam Rice wrote:
 > Hi there everybody, I'm having a few issues with number formatting from
 > an input field.


I was thinking Javascript thinks its a string.  So I googled this here:
http://www.siteexperts.com/tips/functions/ts23/page3.asp

I think you could change the regex to /[, ]/ and it will work for you


Remove Commas

A user may enter a number separated by commas. You may wish to remove 
the commas before storing the number. A reformatting function to do that 
would look like this:

function removeCommas( strValue ) {
   var objRegExp = /,/g; //search for commas globally
   //replace all matches with empty strings
   return strValue.replace(objRegExp,'');
}


-- 
Joel Goldstick
www.columbuswebmakers.com



More information about the Javascript mailing list