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