From 2bb73009795f1eb242b74d2cc284387df6faf038 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 9 Oct 2020 11:36:57 +0300 Subject: [PATCH] Fixed #531 - inputNumber with numeric prefix is not working as expected --- src/components/inputnumber/InputNumber.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/inputnumber/InputNumber.vue b/src/components/inputnumber/InputNumber.vue index 8ca32d0a3..c1abc24ac 100755 --- a/src/components/inputnumber/InputNumber.vue +++ b/src/components/inputnumber/InputNumber.vue @@ -189,6 +189,9 @@ export default { this.constructParser(); } }, + escapeRegExp(text) { + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + }, getDecimalExpression() { const formatter = new Intl.NumberFormat(this.locale, {useGrouping: false}); return new RegExp(`[${formatter.format(1.1).trim().replace(this._numeral, '')}]`, 'g'); @@ -219,7 +222,7 @@ export default { this.prefixChar = formatter.format(1).split('1')[0]; } - return new RegExp(`${this.prefixChar||''}`, 'g'); + return new RegExp(`${this.escapeRegExp(this.prefixChar||'')}`, 'g'); }, getSuffixExpression() { if (this.props.suffix) { @@ -231,7 +234,7 @@ export default { this.suffixChar = formatter.format(1).split('1')[1]; } - return new RegExp(`${this.suffixChar||''}`, 'g'); + return new RegExp(`${this.escapeRegExp(this.suffixChar||'')}`, 'g'); }, formatValue(value) { if (value != null) {