JS detects if the username contains Chinese characters

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax code entered the function javascript name registered user registration

Web effects detect whether the user name contains Chinese characters
This verification code is more suitable for user registration verification, it can verify that the user entered the registered username that we do not want to appear in the string or Chinese characters, such as the following I defined letters as letters and numbers and _ lines, so that you can verify that the user submitted the database tutorial does not contain Chinese characters.
*/

function Checkifenglish (String)
{
var letters = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890_";
var i;
var C;
for (i = 0; i < string.length i + +)
{
c = String.charat (i);
if (Letters.indexof (c) < 0)
return false;
}
return true;
}

var str = ' 122 China ';
var str1 = ' FDAFSA_456776111CN ';
if (Checkifenglish (str))
{
Alert (' lawful username ');
}
Else
{
Alert (' String contains Chinese ');
}

If (Checkifenglish (str1))
{
 alert (' Legal user name ');
}
Else
{
 alert (contains Chinese in string);
}
 

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.