Only Chinese, digital, and English can be entered in the JavaScript control input box

Source: Internet
Author: User

1. Background of the problem

Encounter a problem: there is an input box that requires only Chinese, numeric, and English (that is, filter special strings)


2. JS Code

function Checkusername ()

{

Regular expressions

var reg = new RegExp ("^[a-za-z\d\u4e00-\u9fa5]+$");

Get the value in the input box

var username = document.getElementById ("username"). Value.trim ();

Determine what is in the input box

if (Username.length >0)

{

Alert ("Please input Chinese, digital and English!) ");

Enter illegal characters, empty the input box

$ ("#username"). Val ("");

}

}


3. Page code

<input type= "text" id= "username" onkeyup= "Checkusername()"/>

Only Chinese, digital, and English can be entered in the JavaScript control input box

Related Article

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.