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

后端 未结 5 1886
-上瘾入骨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 11:03

    you can use the maxLength attribute for that, try

     $(".test").keyup(function (event) {
            var last = $(this).val()[$(this).val().length - 1];
            if (last == '.') {
                $(".test").attr("maxlength", $(this).val().length+2);
             }
        });
    

提交回复
热议问题