Php username Regular Expression (Chinese, English, numbers, letters)-PHP source code

Source: Internet
Author: User
Ec (2); php tutorial username Regular Expression (Chinese, English, numbers, letters) by letter ~ Z (Case Insensitive), numbers 0 ~ 9. The combination of a minus sign or an underscore can only start with a number or a letter and end with a username of 4 ~ 18 characters ^ [a-za-z0-9] {1} [a-za-z0-9 |-| _] {2-16} [a-za-z0-9] {1} $ the username is an uppercase letter, lowercase letter, or underline, it must start with a letter and have a length of 6-20 ^ [a-za-z] [wd _] {5, 1 script ec (2); script

Php tutorial username Regular Expression (Chinese, English, numbers, letters)
By letter ~ Z (Case Insensitive), numbers 0 ~ 9. Combination of minus signs or underscores
The username must start with a number or letter and end with a length of 4 ~ 18 characters

^ [A-za-z0-9] {1} [a-za-z0-9 |-| _] {2-16} [a-za-z0-9] {1} $

The username is an uppercase letter, lowercase letter, or underscore, and starts with a letter. The username must be 6-20 characters long.

^ [A-za-z] [wd _] {5, 19}

Username: the username can contain lowercase letters, Chinese characters, numbers, and underscores (_). The username cannot contain only numbers, but cannot contain underscores (_).

/^ [A-z0-9_u4e00-u9fa5] + [^ _] $/g

UTF-8

Preg_match ("/^ [a-z0-9_x80-xff] + [^ _] $/g", $ );

Under gbk:

Preg_match ("/^ [a-z0-9 _". chr (0xa1). "-". chr (0xff). "] + [^ _] $/", $)

User name verification in Chinese

[A-za-z0-9] [u4e00-u9fa5]


Because the expression we write matches any part of a string. It not only considers 'Mike _ 84 'as a valid string, but also matches' %! The string mike_84 & 'contains something we don't want to see. We need to use row positioning points. The ^ (caret) and $ (dollar) characters will limit our expression to the start and end positions of a string, this ensures that the entire user name conforms to our settings, rather than part of the user name.

Therefore, the regular expression of the revised version is as follows:
/^ [A-za-z0-9 _] {} $/

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.