I'm using the following jQuery plug-in to automatically add commas to a number. The problem is, when a decimal amount (like $1,000.00) is entered, it's changing it to $1,000,.00.
How can the regex be updated to ignore the decimal point and any characters after it?
String.prototype.commas = function() {
return this.replace(/(.)(?=(.{3})+$)/g,"$1,");
};
$.fn.insertCommas = function () {
return this.each(function () {
var $this = $(this);
$this.val($this.val().replace(/(,| )/g,'').commas());
});
};