K
K
kr_ilya2019-11-23 16:19:42
JavaScript
kr_ilya, 2019-11-23 16:19:42

How to allow only 2 decimal places to be entered?

It is necessary that in the input field you can enter any number > 1 and, if this is a floating point number, then with no more than two characters after it
. And you need to do this through the rules for the field

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-11-23
@kr_ilya

val => (val.split('.')[1] || '').length < 3 || 'Не более двух знаков после запятой'

S
Sanes, 2019-11-23
@Sanes

The usual input type number can do this. Add step="0.01"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question