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

后端 未结 5 1917
-上瘾入骨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:53

    $(document).on("keyup", ".ctc", function () 
     {
    
        if (!this.value.match(/^\s*\d*\.?\d{0,2}\s*$/) && this.value != "") {
            this.value = "";
            this.focus();
            alert("Please Enter only alphabets in text");
        }
    });
    

提交回复
热议问题