正则匹配不正确?该如何解决

WBOY
Release: 2016-06-13 13:39:17
Original
902 people have browsed it

正则匹配不正确?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
if(! preg_match($user_name,'/[^\a-\z\A-\Z0-9\_@\.]/g'))
{
echo '不允许出现中文';
}

Copy after login

上述代码不能验证用户名不是英文数字下划线组成

------解决方案--------------------
参数顺序都反了
------解决方案--------------------
if(!preg_match('/^[a-z0-9_]+$/i',$user))
{
echo '不允许出现中文';
}

这样试试。
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!