次のjQueryプラグインを使用して、数値にコンマを自動的に追加しています。問題は、小数($ 1,000.00など)を入力すると、$ 1,000、.00に変更されることです。
小数点とその後の文字を無視するように正規表現を更新するにはどうすればよいですか?
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());
});
};