[Question about a regular expression]

Source: Internet
Author: User
[Ask a regular expression question] problem description: prohibit full letters, prohibit full numbers, prohibit special characters, prohibit punctuation marks, length 2 to 7 characters; if it is difficult to write down the above, only Chinese strings are allowed. The length should be 2 to 7 characters; special characters are prohibited; punctuation marks are prohibited; in short, it is to match a 2-7 Chinese character string. [ask a regular expression question]
Problem description:
Prohibit all letters;
Prohibit all numbers;
Special characters are prohibited;
Punctuation marks are prohibited;
It can contain 2 to 7 characters;


If the above is more difficult, you can directly write the following

Only Chinese strings are allowed;
It can be 2 to 7 characters in length;
Special characters are prohibited;
Punctuation marks are prohibited;




------ Solution --------------------
In short, it is to match a 2-7 Chinese character string.
------ Solution --------------------
In fact, this problem can be found by Baidu. The following is the reference code:
$ Str = "php programming ";
If (preg_match ("/^ [\ x {4e00}-\ x {9fa5}] + $/u", $ str )){
Print ("all strings are Chinese ");
} Else {
Print ("Not all strings are Chinese ");
}
------ Solution --------------------
You can add a character set to convert the length and then determine the corresponding length.

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.