Home > Backend Development > PHP Tutorial > php的phalcon框架不能验证中文字符

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:34:39
Original
1165 people have browsed it

直接在php中验证可以验证

<code>$value = '电商';
preg_match('/^[a-zA-Z\x{4e00}-\x{9fa5}][a-zA-Z_\-\x{4e00}-\x{9fa5}]*$/u',$value,$m)
</code>
Copy after login
Copy after login

在phalcon的控制器的方法中就不能验证,

<code>public function registerAction()
    {
        if($this->request->isPost())
        {
            $myValidator = new MyValidator();
            $errors = $myValidator->validateUsername($this->request->getPost('user_name'));
       }
    }
</code>
Copy after login
Copy after login

下面是调用的函数,

<code>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;

    }
</code>
Copy after login
Copy after login

回复内容:

直接在php中验证可以验证

<code>$value = '电商';
preg_match('/^[a-zA-Z\x{4e00}-\x{9fa5}][a-zA-Z_\-\x{4e00}-\x{9fa5}]*$/u',$value,$m)
</code>
Copy after login
Copy after login

在phalcon的控制器的方法中就不能验证,

<code>public function registerAction()
    {
        if($this->request->isPost())
        {
            $myValidator = new MyValidator();
            $errors = $myValidator->validateUsername($this->request->getPost('user_name'));
       }
    }
</code>
Copy after login
Copy after login

下面是调用的函数,

<code>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;

    }
</code>
Copy after login
Copy after login

http://stackoverflow.com/questions/4923319/php-check-if-the-string-has...

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template