Home > Backend Development > PHP Tutorial > 关于PHP汉字正则验证没法通过的问题,还请高手指点,先谢谢了!

关于PHP汉字正则验证没法通过的问题,还请高手指点,先谢谢了!

WBOY
Release: 2016-06-23 13:04:15
Original
926 people have browsed it

$name = $_POST['name'];//$this->error($name); 这里可以输出“小明”if(!preg_match('/^[u4E00-u9FA5]{2,4}$/',$name)) {	$this->error('真实姓名应由2-4个汉字组成!');}
Copy after login


但是老是提示“真实姓名应由2-4个汉字组成!”,没法通过

if(!preg_match('/^1[0-9]{10}$/',$_POST['mobile'])) {
$this->error('请输入正确的手机号码!!');
}
输入正确的手机号码可以通过,想JS+PHP两重验证。JS部分已经OK了



回复讨论(解决方案)

你的 /^[u4E00-u9FA5]{2,4}$/ 是 js 的正则表达式规则串
php 要写作 '/^[\x{4e00}-\x{9fa5}]{2,4}$/u'

哦,还有这分别,谢谢了!搞定

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