I have these numbers
10999
and 8094
and 456
And all i want to do is add a comma in the right place if it needs it so it looks like this
10,999
and 8,094
and 456
These are all within a p tag like this <p class="points">10999</p>
etc.
Can it be done?
I've attempted it here with the help of other posts http://jsfiddle.net/pdWTU/1/ but can't seem to get it to work
Thanks
Jamie
UPDATE
Messed around a bit and managed to figure it out here http://jsfiddle.net/W5jwY/1/
Going to look at the new Globalization plugin for a better way of doing it
Thanks
Jamie
Take a look at Numeral.js. It can format numbers, currency, percentages and has support for localization.
another approach:
Another amazing plugin: http://www.teamdf.com/web/jquery-number-format/178/
Timothy Pirez answer was very correct but if you need to replace the numbers with commas Immediately as user types in textfield, u might want to use the Keyup function.
Another way to do it:
Works on all browsers, this is all you need.
Wrote this to be compact, and to the point, thanks to regex. This is straight JS, but you can use it in your jQuery like so:
or