Only integer code instances can be entered in the required text box, and integer code instances in the text box

Source: Internet
Author: User

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/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.