php-关于PHP 正则验证用户名的问题?张思

WBOY
Release: 2016-06-02 11:28:31
Original
770 people have browsed it

正则php

基本都可以,但这个不行,用户名换成张三就OK,为什么?新手的痛苦,谢谢。

<code> <?php $_string='张思';    $_char_pattern='/[<>\'\"\\  ]/';    if(preg_match($_char_pattern,$_string)){        echo '用户名不得包含敏感字符!';    }else{        echo '没有敏感字符';    }?></code>
Copy after login

补充1:

对回答的回复:
空白的地方是2个空格,一个半角,一个全角

\s使用这个可以通过,单独使用半角空格也可以OK,加上全角过滤张思就过不去。

我刚学,这点还真心不懂;

谢谢回答,但愿能解决。

补充2:

JS验证可以通过张思!

<code>    if(/[\'\"\  ]/.test(fm.username.value)){            alert("用户名包含非法字符");            fm.username.focus();            return false;                   }</code>
Copy after login
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!