PHP regular matching method for Chinese and English, numbers and underlines

小云云
Release: 2023-03-19 18:58:01
Original
3795 people have browsed it

This article mainly introduces the method of PHP regular matching of Chinese and English, numbers and underscores, which can be used to verify user names. Friends who need it can refer to it. I hope it can help everyone.

1. Question:

The user name when registering is required to be composed of Chinese and English, numbers or underscores, and must not contain other characters.

2. Solution:

Just perform regular verification of Chinese, English, numbers and underscores on the input characters.

The code is as follows:


$username='脚本之家jb51.net@#……^&*';
$preg='/[\w\x{4e00}-\x{9fa5}]+/u';
//$preg='/[\x80-\xff_\w]+/u';
preg_match($preg,$username,$arr);
print_r($arr);
Copy after login

Running result:


Array
(
  [0] => 脚本之家jb51
)
Copy after login

Related recommendations:

Sharing tips on phpstorm regular matching to delete empty lines and comment lines

Detailed explanation of some regular matching expressions in jQuery

Detailed explanation of the method of matching Chinese with php and javascript

The above is the detailed content of PHP regular matching method for Chinese and English, numbers and underlines. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!