Home > Backend Development > PHP Tutorial > 【正则表达式】检测字符串只包含数字、字母、下划线、汉字,该如何解决

【正则表达式】检测字符串只包含数字、字母、下划线、汉字,该如何解决

WBOY
Release: 2016-06-13 12:00:27
Original
2538 people have browsed it

【正则表达式】检测字符串只包含数字、字母、下划线、汉字
RT
要验证一下用户名,只包含数字、字母、下划线、汉字,要求即使打乱顺序也能测出来
------解决方案--------------------
'/^[\x7f-\xffA-Za-z0-9_]+$/'
------解决方案--------------------

$s = '%';<br />var_dump(preg_match('/^\w+$/u', $s)); //int(0)<br />var_dump(preg_match('/^[\x7f-\xffA-Za-z0-9_]+$/', $s)); //int(1)
Copy after login

全角的标点不当做汉字



引用:
'/^[\x7f-\xffA-Za-z0-9_]+$/'
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