diff --git a/README.md b/README.md index e424961..f58e818 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ The options that you can set are: * `suffix`: the prefix to be displayed after the value entered by the user(example: "1234.23 €"). default: '' * `affixesStay`: set if the prefix and suffix will stay in the field's value after the user exits the field. default: true * `thousands`: the thousands separator. default: ',' + * `thousandsStay`: set if the thousands separator will stay in the field's value after the user exits the field. defualt: true * `decimal`: the decimal separator. default: '.' * `precision`: how many decimal places are allowed. default: 2 * `allowZero`: use this setting to prevent users from inputing zero. default: false diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index ec74807..0a1be09 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -62,7 +62,8 @@ decimal: ".", precision: 2, allowZero: false, - allowNegative: false + allowNegative: false, + thousandsStay: true }, settings); return this.each(function () { @@ -355,10 +356,14 @@ $input.val(setSymbol(getDefaultMask())); } } else { + var newValue = $input.val(); if (!settings.affixesStay) { - var newValue = $input.val().replace(settings.prefix, "").replace(settings.suffix, ""); - $input.val(newValue); + newValue = newValue.replace(settings.prefix, "").replace(settings.suffix, ""); } + if (!settings.thousandsStay) { + newValue = newValue.replace(new RegExp(settings.thousands,"g"), ""); + } + $input.val(newValue); } if ($input.val() !== onFocusValue) { $input.change();