JavaScript is a regular expression-based method that controls only Chinese characters, numbers, and English characters in the input box.

Source: Internet
Author: User
This article mainly introduces how to control the input box of JavaScript to only input Chinese characters, numbers, and English characters. The character input restriction function is implemented based on regular expression verification, which has some reference value, for more information about how to enter Chinese, numbers, and English characters in the # wiki/48.html "target =" _ blank "> JavaScript control input box, the character input restriction function is implemented based on regular expression verification and has some reference value. For more information, see

This example describes how to enter only Chinese characters, numbers, and English characters in the Javascript control input box. We will share this with you for your reference. The details are as follows:

1. Background:

A problem occurs: There is an input box that requires only Chinese characters, numbers, and English characters (that is, filter special strings)

2. JS code:

Function checkUsername () {// Regular Expression var reg = new RegExp ("^ [A-Za-z0-9 \ u4e00-\ u9fa5] + $ "); // obtain the value var username = document in the input box. getElementById ("username "). value. trim (); // determines if (! Reg. test (username) {alert ("enter Chinese characters, numbers, and English! "); // Enter invalid characters. Clear the input box $ (" # username "). val ("");}}

3. webpage HTML code:

 

The complete instance code is as follows:

 Test

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.