添加仅字母验证形式的Yii2

时间:2018-12-24 07:13:24

标签: yii yii2 yii2-advanced-app

我想通过特殊字符验证我的姓名文本框

我尝试:-

public function rules() 
{
   [
       'full_name', 'match',
       'pattern' => '/^[a-zA-Z\s]+$/',
       'full_name' => 'full_name can only contain word characters'
   ]
}

1 个答案:

答案 0 :(得分:2)

尝试一下:

public function rules() 
{
    return [
         'full_name', 'match',
         'pattern' => '/^[a-zA-Z\s]+$/',
         'message' => 'full_name can only contain word characters'
    ];
}

引用Yii2 Core Match Validator