Skip to content

Commit 18b714d

Browse files
committed
fix(input-amount): return undefined for non numbers with spaces
1 parent f32aab6 commit 18b714d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

packages/input-amount/src/parsers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ function parseHeuristic(value) {
110110
* @param {object} options Locale Options
111111
*/
112112
export function parseAmount(value, options) {
113+
const containsNumbers = value.match(/\d/g);
114+
if (!containsNumbers) {
115+
return undefined;
116+
}
113117
const matchedInput = value.match(/[0-9,.\- ]/g);
114118
if (!matchedInput) {
115119
return undefined;

packages/input-amount/test/parsers.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ describe('parseAmount()', () => {
139139
it('ignores non-number characters and returns undefined', () => {
140140
expect(parseAmount('A')).to.equal(undefined);
141141
expect(parseAmount('EUR')).to.equal(undefined);
142+
expect(parseAmount('EU R')).to.equal(undefined);
142143
});
143144

144145
it('returns undefined when value is empty string', () => {

0 commit comments

Comments
 (0)