Skip to content

Commit

Permalink
Fixed #1613 - inputNumber with numeric prefix is not working as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Oct 7, 2020
1 parent a2581d9 commit a6bf122
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export class InputNumber extends Component {
this._index = d => index.get(d);
}

escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

getDecimalExpression() {
const formatter = new Intl.NumberFormat(this.props.locale, {useGrouping: false});
return new RegExp(`[${formatter.format(1.1).trim().replace(this._numeral, '')}]`, 'g');
Expand Down Expand Up @@ -193,7 +197,7 @@ export class InputNumber extends Component {
this.prefixChar = formatter.format(1).split('1')[0];
}

return new RegExp(`[${this.prefixChar||''}]`, 'g');
return new RegExp(`${this.escapeRegExp(this.prefixChar||'')}`, 'g');
}

getSuffixExpression() {
Expand All @@ -206,7 +210,7 @@ export class InputNumber extends Component {
this.suffixChar = formatter.format(1).split('1')[1];
}

return new RegExp(`[${this.suffixChar||''}]`, 'g');
return new RegExp(`${this.escapeRegExp(this.suffixChar||'')}`, 'g');
}

formatValue(value) {
Expand Down

0 comments on commit a6bf122

Please sign in to comment.