您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php的phalcon框架不能验证中文字符

2026/2/14 11:21:33发布20次查看
直接在php中验证可以验证
$value = '电商';preg_match('/^[a-za-z\x{4e00}-\x{9fa5}][a-za-z_\-\x{4e00}-\x{9fa5}]*$/u',$value,$m)

在phalcon的控制器的方法中就不能验证,
public function registeraction() { if($this->request->ispost()) { $myvalidator = new myvalidator(); $errors = $myvalidator->validateusername($this->request->getpost('user_name')); } }

下面是调用的函数,
public function validateusername($value) { $error = false; if(!preg_match('/^[a-za-z\x{4e00}-\x{9fa5}][a-za-z_\-\x{4e00}-\x{9fa5}]*$/u',$value,$m)) { $error = true; print_r('world'); } else { $pattern = '/[\x{4e00}-\x{9fa5}]/u'; $str1 = preg_replace($pattern, '', $value, -1, $count); $length = strlen($str1) + $count * 2; if (!($length >= 2 && $length 'user name is invalid2.']; } else { $return = null; } return $return; }

回复内容: 直接在php中验证可以验证
$value = '电商';preg_match('/^[a-za-z\x{4e00}-\x{9fa5}][a-za-z_\-\x{4e00}-\x{9fa5}]*$/u',$value,$m)

在phalcon的控制器的方法中就不能验证,
public function registeraction() { if($this->request->ispost()) { $myvalidator = new myvalidator(); $errors = $myvalidator->validateusername($this->request->getpost('user_name')); } }

下面是调用的函数,
public function validateusername($value) { $error = false; if(!preg_match('/^[a-za-z\x{4e00}-\x{9fa5}][a-za-z_\-\x{4e00}-\x{9fa5}]*$/u',$value,$m)) { $error = true; print_r('world'); } else { $pattern = '/[\x{4e00}-\x{9fa5}]/u'; $str1 = preg_replace($pattern, '', $value, -1, $count); $length = strlen($str1) + $count * 2; if (!($length >= 2 && $length 'user name is invalid2.']; } else { $return = null; } return $return; }

http://stackoverflow.com/questions/4923319/php-check-if-the-string-has...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product