Home  >  Article  >  Backend Development  >  正则匹配不正确?该如何解决

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

WBOY
WBOYOriginal
2016-06-13 13:39:17895browse

正则匹配不正确?

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 '不允许出现中文';
}


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

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

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