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