在 Yii2 表单中添加仅字母验证

Add letters only validation in a form Yii2

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

我试试这个:-

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

试试这个:

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

参考Yii2 Core Match Validator