我正在经历尴尬的局面。
除required
的{{1}}字段外,所有规则都正常工作。
first_name
并且,在将'FirstNameLength' => ['first_name', 'string', 'min' => 3, 'tooShort'=>'First name should contain atleast 3 character'],
'FirstNameTrim' => ['first_name', 'filter', 'filter' => 'trim'],
'FirstNameRequired' => ['first_name', 'required','message'=>'* First name is required'],
'FirstNameRequired' => ['first_name','match','pattern'=>"/^[a-zA-Z']+$/",'message' => '* First Name can only contain alphabets charater'],
纳入规则之后,它正在发生。如果我删除或评论pattern
规则,则表明它正在运行。
pattern
我的动机是不允许除'FirstNameLength' => ['first_name', 'string', 'min' => 3, 'tooShort'=>'First name should contain atleast 3 character'],
'FirstNameTrim' => ['first_name', 'filter', 'filter' => 'trim'],
'FirstNameRequired' => ['first_name', 'required','message'=>'* First name is required'],
//'FirstNameRequired' => ['first_name','match','pattern'=>"/^[a-zA-Z']+$/",'message' => '* First Name can only contain alphabets charater'],
以外的任何space
,number
或special character
。并且,这种模式规则可以正常工作。但是,唯一的问题是现在它没有采用'
规则。
欢迎任何帮助/提示/建议。
答案 0 :(得分:1)
似乎你正在重新定义/覆盖键FirstNameRequired
,然后最后覆盖前一个..
我建议您使用常规表示法来验证规则(没有FirstNameRequired键
['first_name', 'required','message'=>'* First name is required'],
['first_name','match','pattern'=>"/^[a-zA-Z']+$/",'message' => '* First Name can only contain alphabets charater'],