JQuery restricts that only numbers and decimal places can be entered in the text box.
This article mainly introduces JQuery's method of limiting the number and decimal point of a text box.
The Code is as follows:
$ (Function (){
/* JQuery restricts that only numbers can be entered in the text box */
$ (". NumText"). keyup (function (){
$ (This). val ($ (this). val (). replace (/D | ^ 0/g ,''));
}). Bind ("paste", function () {// CTR + V event processing
$ (This). val ($ (this). val (). replace (/D | ^ 0/g ,''));
}).Css ("ime-mode", "disabled"); // the CSS setting input method is unavailable.
/* JQuery limits that only numbers and decimal places can be entered in the text box */
$ (". NumDecText"). keyup (function (){
$ (This). val ($ (this). val (). replace (/[^ 0-9.]/g ,''));
}). Bind ("paste", function () {// CTR + V event processing
$ (This). val ($ (this). val (). replace (/[^ 0-9.]/g ,''));
}).Css ("ime-mode", "disabled"); // the CSS setting input method is unavailable.
});
Add the class name to the text box to be verified, as shown in the following code:
The Code is as follows:
<Input type = "text" class = "txt NumText" Width = "100px" runat = "server"/>