验证输入的代码:
public function rules() {
return [ [['name', 'email', 'subject', 'content'], 'required'],
[['date_added'], 'safe'],
[['email', 'subject'], 'string', 'max' => 255], [['email'], 'email'],
]; }
答案 0 :(得分:1)
您可以使用匹配模式
public function rules() {
return [ [['name', 'email', 'subject', 'content'], 'required'],
[['date_added'], 'safe'],
[['email', 'subject'], 'string', 'max' => 255], [['email'], 'email'],
[['name', 'match', 'pattern' => '/^[a-zA-Z]+$/',
'message' => 'Your username can only contain alphabetic characters']]
]; }
答案 1 :(得分:1)
托盘:
public function rules() {
return [ [['name', 'email', 'subject', 'content'], 'required'],
['name','match', 'pattern' => '[a-zA-Z][a-zA-Z., ]+$/;',
'message' => 'Name can only contain Alphabet and Spaces only'],
[['date_added'], 'safe'],
[['email', 'subject'], 'string', 'max' => 255], [['email'], 'email'],
]; }