PHP username Regular expression (Chinese, English, digit, letter)

Source: Internet
Author: User
Tags lowercase php tutorial regular expression

PHP Tutorial User name Regular expression (Chinese, English, digit, letter)
Consists of a letter a~z (case-insensitive), a numeric 0~9, a minus sign, or an underscore
You can only start and end a number or letter with a 4~18 character length

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

The user name is uppercase or lowercase letters or underscores and begins with a letter with a length of 6-20

^[A-ZA-Z][WD_]{5,19}

User name: including English lowercase, Chinese characters, numbers, underscores, cannot be all numbers, underline cannot be at the end

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

Utf-8 under

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

GBK under:

Preg_match ("/^[a-z0-9_". Chr (0XA1). " -". Chr (0xFF)."] +[^_]$/", $a)

Can have Chinese user name verification

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


Because we write an expression that matches any part of a string. It will not only think ' mike_84′ is a legitimate string, it will also match similar '%! mike_84& ' This string that contains something we don't want to appear in. We need to use line anchors, ^ (caret) and $ (dollar) characters will limit our expression to the start and end of a string to ensure that the entire username fits our set, not part of it.

So the regular expression of the revised version looks like this:
/^[a-za-z0-9_]{3,16}$/

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.