O
O
OWIII2020-01-21 10:51:42
JavaScript
OWIII, 2020-01-21 10:51:42

Doesn't validate for numbers in input type="number"?

I did the validation of the "TEXT" type input in js, I used the following pattern: ^[0-9]+$.
Everything worked great.
After that, I decided to change the input type to NUMBER and the pattern broke. The input does not validate the "-" and "+" signs.
What's the catch? Who will tell? How can I prevent pluses and minuses from being entered into an input of type number ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2020-01-21
@KickeRockK

The bottom line is that type="number", an entry with two "-" or "+" or "." makes the value empty and, on the basis of this, it is difficult to cut unnecessary ones.
So text is ok or event is blur.
There is this https://jsfiddle.net/kickerock/d2nLqcgh/2/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question