How to add commas to numbers, presently I'm producing an output like this 1,2,3,4,5,6,7,890 - trying to have a result that outputs the following 1,234,567,890 - using keyup which might cause issues, please advise
numberWithCommas : function () {
var goal = $("#foo");
goal.val(goal.val().toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
},
Update:I found that replace(/\B(?=(\d{3})+(?!\d))/g, ',');
fixed the issue of too many commas