Javascript restricts input boxes (commonly used) _ javascript tips-JS tutorial

Source: Internet
Author: User
This article introduces how to use JavaScript to restrict the input box: the text box can only enter numbers and code, only numbers, only letters and Chinese characters, only English letters and numbers, and many more, if you are interested, you can learn 1. only numeric code can be entered in the text box (decimal point cannot be entered)

The Code is as follows:




2. Only numbers can be entered, and decimal points can be entered.

The Code is as follows:





3. Number and decimal point method 2

The Code is as follows:




4. Only letters and Chinese characters can be entered

The Code is as follows:




5. Only English letters and numbers are allowed. Chinese characters are not allowed.

The Code is as follows:




6. Only numbers and English chun numbers can be entered.

The Code is as follows:




7. After the decimal point, you can enter a maximum of two digits (numbers and Chinese characters). You cannot enter letters or operator numbers:

The Code is as follows:




8. A maximum of two digits (numbers, letters, and Chinese characters) can be entered after the decimal point. You can enter the operator number:

The Code is as follows:



// Only Chinese characters can be entered:

// Only numbers can be entered:

// Only English and numbers can be entered:

// You can enter only text or numbers or special characters in the control input box.
// The following characters cannot be entered! @ # $ % ^)


// Only spaces are allowed.
Onkeyup = "value = value. replace (/\ s/g ,'')"
// Only Chinese and English characters can be entered:
Onkeyup = "value = value. replace (/[^ \ a-zA-Z \ u4E00-\ u9FA5]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ a-zA-Z \ u4E00-\ u9FA5]/g ,''))"

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.