I
I
Ilya2018-03-13 12:21:30
JavaScript
Ilya, 2018-03-13 12:21:30

Why after autocomplete input regex gives wrong value?

I can't quite figure out what's wrong.
There is an input field where the amount is entered. After entering the value, the amount is converted for me like this

const newVal = value.Amount.toString().replace(/\s/, '').replace(/,/g, '.');

In the future, as the validator comes into operation, which checks for the regular expression, the condition, the regular expression is like this: When you enter "by hand", let's say the number 111.00, the value is converted to 111.00 and everything is OK, it's greater than zero, the regular expression returns true. But if you enter a value in the field through autocomplete, then the regular expression test will return false and then the validator will work and say that the number 111.00 must be greater than zero. What am I doing wrong?
/^(\d+\.|\d*[1-9])\d*$/.test(newVal)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-03-14
@Legendarniy

Solved a problem. When autocomplete, chrome, for example, does not put spaces at all, but a zero-width character. I did this and everything worked as it should. Trim and replacement of whitespace characters naturally removed. .replace(/[\u2060]/g, '')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question