Simple JavaScript Number Formatter

This JavaScript code example provides us two functions to clean up and format numbers quite nicely.

One JavaScript check number function will take any decimal number, negative or positive, and formats it by adding commas every three digits. The other JavaScript number format function can strip any non-numeric characters from a string leaving you with a valid decimal number. It also considers the minus sign and the period to be numeric and will not strip them unless the minus sign is not at the beginning of the number or there is more than one period.

These JavaScript functions make use of regular expressions to do the heavy lifting.


Sampled by © JavaScriptBank.com
numberFormat():


stripNonNumeric():


stripNonNumeric() then numberFormat():

2000+ free JavaScripts
at www.JavaScriptBank.com