PHP Regular Expression matching (Chinese and English), numbers, and underscores,

Source: Internet
Author: User
Tags php regular expression preg

PHP Regular Expression matching (Chinese and English), numbers, and underscores,

This example describes how to match Chinese characters, English letters, numbers, and underscores in PHP regular expressions. We will share this with you for your reference. The details are as follows:

I. Problems:

The user name must consist of Chinese characters, English letters, numbers, or underscores (_), and must not contain any other character.

Ii. solution:

You can use regular expressions to verify Chinese characters, English letters, numbers, and underscores.

The Code is as follows:

$ Username = 'customer's house jb51.net @#...... ^ & * '; $ Preg ='/[\ w \ x {4e00}-\ x {9fa5}] +/U '; // $ preg = '/[\ x80-\ xff _ \ w] +/U'; preg_match ($ preg, $ username, $ arr); print_r ($ arr );

Running result:

Array ([0] => helper house jb51)

PS: here we will provide two very convenient Regular Expression tools for your reference:

JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript

Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg

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.