fix(input-amount): return undefined for non numbers with spaces
This commit is contained in:
parent
f32aab6533
commit
18b714d056
2 changed files with 5 additions and 0 deletions
|
|
@ -110,6 +110,10 @@ function parseHeuristic(value) {
|
||||||
* @param {object} options Locale Options
|
* @param {object} options Locale Options
|
||||||
*/
|
*/
|
||||||
export function parseAmount(value, options) {
|
export function parseAmount(value, options) {
|
||||||
|
const containsNumbers = value.match(/\d/g);
|
||||||
|
if (!containsNumbers) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
const matchedInput = value.match(/[0-9,.\- ]/g);
|
const matchedInput = value.match(/[0-9,.\- ]/g);
|
||||||
if (!matchedInput) {
|
if (!matchedInput) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ describe('parseAmount()', () => {
|
||||||
it('ignores non-number characters and returns undefined', () => {
|
it('ignores non-number characters and returns undefined', () => {
|
||||||
expect(parseAmount('A')).to.equal(undefined);
|
expect(parseAmount('A')).to.equal(undefined);
|
||||||
expect(parseAmount('EUR')).to.equal(undefined);
|
expect(parseAmount('EUR')).to.equal(undefined);
|
||||||
|
expect(parseAmount('EU R')).to.equal(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns undefined when value is empty string', () => {
|
it('returns undefined when value is empty string', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue