E
E
Evgeny Zhurov2020-04-23 14:10:57
JavaScript
Evgeny Zhurov, 2020-04-23 14:10:57

What regular expression should be used to validate a number according to the requirements below?

Good afternoon.
When filling in some form fields, you need to limit the user's ability to enter numbers. Conditions:

The input type must be strictly number
Validation is done on the keyup and paste events
If the entered character does not match the rules, it is automatically erased (or if there are invalid characters in the inserted string, they are erased).
Only a positive integer or fractional number is considered valid. 0 is also considered valid.

In regular seasons, he is not strong, to shame and chagrin. Everything that I could dig up on the Internet does not work properly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-04-23
@Zhuroff

What regular expression should be used to validate a number according to the requirements below?
None, for no reason.
Validation is done on keyup and paste events
Why not fool around and just use the input event?
input with type="number" will already filter out invalid characters, although a valid number is far from necessary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question