From e954ff62f264ec35db9d008b4258a3b21abfc2f5 Mon Sep 17 00:00:00 2001 From: asosunoff Date: Tue, 16 Nov 2021 14:23:32 +0300 Subject: [PATCH 1/3] call the method getNemberRegexp to get a correct regular expression --- src/number_format.js | 14 ++++---------- test/library/input.spec.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/number_format.js b/src/number_format.js index 20af6e38..ab70f555 100644 --- a/src/number_format.js +++ b/src/number_format.js @@ -426,7 +426,7 @@ class NumberFormat extends React.Component { } } - return (numStr.match(/\d/g) || []).join(''); + return (numStr.match(this.getNumberRegex(true)) || []).join(''); } removeFormatting(val: string) { @@ -442,7 +442,7 @@ class NumberFormat extends React.Component { //condition need to be handled if format method is provide, val = removeFormatting(val); } else { - val = (val.match(/\d/g) || []).join(''); + val = (val.match(this.getNumberRegex(true)) || []).join(''); } return val; } @@ -471,14 +471,8 @@ class NumberFormat extends React.Component { * @return {string} formatted Value */ formatAsNumber(numStr: string) { - const { - decimalScale, - fixedDecimalScale, - prefix, - suffix, - allowNegative, - thousandsGroupStyle, - } = this.props; + const { decimalScale, fixedDecimalScale, prefix, suffix, allowNegative, thousandsGroupStyle } = + this.props; const { thousandSeparator, decimalSeparator } = this.getSeparators(); const hasDecimalSeparator = numStr.indexOf('.') !== -1 || (decimalScale && fixedDecimalScale); diff --git a/test/library/input.spec.js b/test/library/input.spec.js index 186bda9f..21491ebc 100644 --- a/test/library/input.spec.js +++ b/test/library/input.spec.js @@ -30,6 +30,18 @@ describe('NumberFormat as input', () => { expect(wrapper.state().value).toEqual('1234567890'); }); + it('should accept and format custom numerals together with format input field', () => { + const wrapper = mount( + , + ); + simulateKeyInput(wrapper.find('input'), '۱۲۳۴۵۶۷۸۹۰', 0); + + expect(wrapper.state().value).toEqual('1234567890'); + }); + it('should render input as type text by default', () => { const wrapper = mount(); expect(wrapper.find('input').instance().getAttribute('type')).toEqual('text'); From 34cf9ab4c94963fd65b306f6031a8617b408f3fd Mon Sep 17 00:00:00 2001 From: asosunoff Date: Tue, 16 Nov 2021 14:30:15 +0300 Subject: [PATCH 2/3] call the method getNemberRegexp to get a correct regular expression --- src/number_format.js | 4 ++-- test/library/input.spec.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/number_format.js b/src/number_format.js index 20af6e38..1e78bc52 100644 --- a/src/number_format.js +++ b/src/number_format.js @@ -426,7 +426,7 @@ class NumberFormat extends React.Component { } } - return (numStr.match(/\d/g) || []).join(''); + return (numStr.match(this.getNumberRegex(true)) || []).join(''); } removeFormatting(val: string) { @@ -442,7 +442,7 @@ class NumberFormat extends React.Component { //condition need to be handled if format method is provide, val = removeFormatting(val); } else { - val = (val.match(/\d/g) || []).join(''); + val = (val.match(this.getNumberRegex(true)) || []).join(''); } return val; } diff --git a/test/library/input.spec.js b/test/library/input.spec.js index 186bda9f..21491ebc 100644 --- a/test/library/input.spec.js +++ b/test/library/input.spec.js @@ -30,6 +30,18 @@ describe('NumberFormat as input', () => { expect(wrapper.state().value).toEqual('1234567890'); }); + it('should accept and format custom numerals together with format input field', () => { + const wrapper = mount( + , + ); + simulateKeyInput(wrapper.find('input'), '۱۲۳۴۵۶۷۸۹۰', 0); + + expect(wrapper.state().value).toEqual('1234567890'); + }); + it('should render input as type text by default', () => { const wrapper = mount(); expect(wrapper.find('input').instance().getAttribute('type')).toEqual('text'); From 82329df3db05275bf78e0eb194821f12abd0fae9 Mon Sep 17 00:00:00 2001 From: asosunoff Date: Tue, 16 Nov 2021 14:32:09 +0300 Subject: [PATCH 3/3] fix --- src/number_format.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/number_format.js b/src/number_format.js index ab70f555..1e78bc52 100644 --- a/src/number_format.js +++ b/src/number_format.js @@ -471,8 +471,14 @@ class NumberFormat extends React.Component { * @return {string} formatted Value */ formatAsNumber(numStr: string) { - const { decimalScale, fixedDecimalScale, prefix, suffix, allowNegative, thousandsGroupStyle } = - this.props; + const { + decimalScale, + fixedDecimalScale, + prefix, + suffix, + allowNegative, + thousandsGroupStyle, + } = this.props; const { thousandSeparator, decimalSeparator } = this.getSeparators(); const hasDecimalSeparator = numStr.indexOf('.') !== -1 || (decimalScale && fixedDecimalScale);