JQuery allow only two numbers after decimal point

前端 未结 7 928
春和景丽
春和景丽 2020-12-02 10:31

I found the following JQuery function here which prevents a user from entering anything that\'s not a number or a single decimal. The function works well but I\'d like to i

7条回答
  •  佛祖请我去吃肉
    2020-12-02 11:10

    It can also be done with a regular expression:

        $('.class').on('input', function () {
            this.value = this.value.match(/^\d+\.?\d{0,2}/);
        });
    

    Name the css selector .class to whatever you like and put it on the input.

提交回复
热议问题