Need help adding commas to numbers. Currently, my output is 1,2,3,4,5,6,7,890 but I want it to be 1,234,567,890. I am using keyup which is causing some problems. Any suggestions?
numberWithCommas : function () {
var target = $("#foo");
target.val(target.val().toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
},
Update: I have discovered that
replace(/\B(?=(\d{3})+(?!\d))/g, ',');
solved the issue of excessive commas.