Allow only 2 decimal points entry to a textbox using javascript or jquery?

后端 未结 5 1890
-上瘾入骨i
-上瘾入骨i 2021-01-15 10:26

I called a class called test for my textbox. When I entered the first value for e.g. the first value as 4., then suddenly the output coming as 4.00

5条回答
  •  失恋的感觉
    2021-01-15 10:42

    What about something like this:

    $(".test").keyup(function (event) {
    if ((pointPos = this.value.indexOf('.')) >= 0)
        $(this).attr("maxLength", pointPos+3);
    else
        $(this).removeAttr("maxLength");
    });
    

    Here is a working fiddle.

提交回复
热议问题