yii2.0 form表单rules校验字段规则大全
public function rules()
{
return [
['email, username, password,agree,verifyPassword,verifyCode', 'required'],
['email', 'unique', 'message' => '用户名已占用'],
['email, username', 'length', 'max' => 64],
['username', 'length', 'max' => 7, 'min' => 2, 'tooLong' => '用户名请输入长度为4-14个字符', 'tooShort' => '用户名请输入长度为2-7个字'],
['password', 'length', 'max' => 22, 'min' => 6, 'tooLong' => '密码请输入长度为6-22位字符', 'tooShort' => '密码请输入长度为6-22位字符'],
['email', 'email', 'message' => '邮箱格式错误'],
['verifyPassword', 'compare', 'compareAttribute' => 'password', 'message' => '请再输入确认密码'],
['agree', 'required', 'requiredValue' => true, 'message' => '请确认是否同意隐私权协议条款'],
['created', 'date', 'format' => 'yyyy/MM/dd/ HH:mm:ss'],
['superuser', 'in', 'range' => [0, 1]],
['name', 'match', 'pattern' => '/^[a-z0-9\-_]+$/'],
['id', 'numerical', 'min' => 1, 'max' => 10, 'integerOnly' => true],
['created', 'type', 'datetime'],
['filename', 'file', 'allowEmpty' => true, 'types' => 'zip, rar, xls, pdf, ppt', 'maxSize' => 1024 * 1024 * 10,'tooLarge' => '图片不要超过800K'],
];
}