Questions about regular expressions

Source: Internet
Author: User
Ask the username for the regular expression. you can enter Chinese or English. how can I write the regular expression to judge it. It cannot be mixed between Chinese and English. it can contain less than 10 Chinese characters. You can use either of the following 30 letters. Let's talk about how to use regular expressions to deal with such problems ?, Question about regular expressions in Chinese & nbsp ;==
User name. you can enter either Chinese or English,
How can I write a regular expression to determine it.
Cannot mix Chinese and English,
Within 10 Chinese characters. You can use either of the following 30 letters.
Let's talk about how to use regular expressions to deal with such problems?
------ Solution --------------------
Chinese ===" \ x {4e00}-\ x {9fa5}

English a-z
Therefore, you can:

/^ ([\ X {4e00}-\ x {9fa5}] {1, 10}
------ Solution --------------------
[A-z] {1, 30}) $/iu
I wonder if you allow spaces

$ Pattern = "/^ ([\ x {4e00}-\ x {9fa5}] {1, 10}
------ Solution --------------------
[A-z] {1, 30}) $/iu ";
$ Test = array ("This is Chinese", "Chinese and English", "thisisenglish ");

Foreach ($ test as $ word ){
Echo $ word;
Echo ":";
Echo preg_match ($ pattern, $ word );
Echo"
";
}

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.