Only integer code instances can be entered in the required text box, and integer code instances in the text box
The required text box can only enter integer code instances:
Sometimes you may need to specify that the content of the text box can only be an integer. The following code example can be provided for your reference.
The Code is as follows:
<! DOCTYPE html>
The above Code meets the expected requirements. Only an integer can be entered in the text box. The following describes the implementation process.
I. Code comments:
1. $ (function () {}). When the document structure is fully loaded, run the code in the function.
2. $ (". NumText"). keyup (function () {}), register the keyup event handler function for the text box.
3. $ (this ). val ($ (this ). val (). replace (/\ D | ^ 0/g, ''). Use the replace () function to replace non-numeric content with null values using a regular expression.
4. bind ("paste", function () {$ (this ). val ($ (this ). val (). replace (/\ D | ^ 0/g, '');}), register the paste event to handle ambiguity. Of course, the chained call is used here, it can prevent users from using ctrl + v to copy and paste.
Ii. Related reading:
1. For details about keyup events, refer to the keyup Events section of jQuery.
2. For more information about the val () function, see the val () method section of jQuery.
3. For more information about replace () functions, see the regular expression replace () function.
4. For details about paste events, refer to the paste event usage section of jquery.
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 11696.
For more information, see: http://www.softwhy.com/jquery/