Merge pull request #233 from ing-bank/fix/ignoreNonNumbersWithSpaces

fix(input-amount): return undefined for non numbers with spaces
This commit is contained in:
Thijs Louisse 2019-08-08 16:55:01 +02:00 committed by GitHub
commit 8b9b5ac5d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View file

@ -110,6 +110,10 @@ function parseHeuristic(value) {
* @param {object} options Locale Options
*/
export function parseAmount(value, options) {
const containsNumbers = value.match(/\d/g);
if (!containsNumbers) {
return undefined;
}
const matchedInput = value.match(/[0-9,.\- ]/g);
if (!matchedInput) {
return undefined;

View file

@ -139,6 +139,7 @@ describe('parseAmount()', () => {
it('ignores non-number characters and returns undefined', () => {
expect(parseAmount('A')).to.equal(undefined);
expect(parseAmount('EUR')).to.equal(undefined);
expect(parseAmount('EU R')).to.equal(undefined);
});
it('returns undefined when value is empty string', () => {