Regular instance of preg_match username in php

Source: Internet
Author: User
Tags php regular expression

Example: letters, numbers, and Chinese characters

The Code is as follows:
If (preg_match ("/['.,:;*?~ '! @ # $ % ^ & + =) (<>{}] | [|/| \ | "|/", $ User )){
Echo 'do not enclose some special characters in the name. Please only use letters, numbers, and Chinese characters. Of course, you must select Simplified Chinese GB2312 in your browser, do not select traditional Chinese or Chinese HZ. Come back and wait for you! ';
Exit ();
}

Example: All letters

The Code is as follows:
<? Php

If (mb_ereg ("^ [w-.] {1, 32} $", $ str )){
Echo 'yes ';
} Else {
Echo 'no http://www.111cn.net /';
}

?>

Some common Regular Expressions

The username must start with a number or letter and end with a length of 4 ~ 18 characters

The Code is as follows:

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

The Code is as follows:

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




UTF-8Preg_match ("/^ [a-z0-9_x80-xff] + [^ _] $/g", $ );Under gbk:Preg_match ("/^ [a-z0-9 _". chr (0xa1). "-". chr (0xff). "] + [^ _] $/", $)
The Code is as follows:

User name verification in Chinese

The Code is as follows:
Articles you may be interested in
  • Php username regular expression, including Chinese characters, with a length of 4-16 characters
  • Verify the php Regular Expression of the user name url in the email format
  • Php username Regular Expression (Chinese, English, numbers, letters)
  • Regular Expression of numbers and letters (user name verification)
  • Php regular code for verifying username Validity
  • Php common Regular Expression mailbox Username Password ip html Tag
  • Preg_match: Regular Expression used to determine the user name
  • Php Regular Expression verification Username
 

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.