验证规则
string
length
['phone', 'string', 'length'=>11, 'notEqual' => '手机号长度不正确'],
[['password', 'name', 'code'], 'string', 'length' => [3,5] 'tooShort'=> '{attribute} 不能小于3个字符', 'tooLong' => '{$attribute} 不能大于5个字符'],
min
['username', 'string', 'min'=>3, 'tooShort' => '用户名最少三个字符'],
max
['username', 'string', 'max'=>5, 'tooLong' => '用户名最多五个个字符'],
boolean
trueValue, falseValue, strict
['is_vip', 'boolean ', 'trueValue'=>'1'//true值, 'falseValue' => '0'//false值,'strict'=>true//开启严格验证模式即为===比较,默认为false],
compare
message 占位符
- {attribute}: 正在验证字段的label名称
- {value}: 正在被验证字段的值
- {compareValue}: 被比较的label名称或值
- {compareAttribute}: 被比较的字段
- {compareValueOrAttribute}: 被比较的label名称或值
operator :操作符
- ==: 等于
- ===: 全等于
- !=: 不等于
- !==: 不全等
- >: 大于
- >=: 大于等于
- <: 小于
- <=: 小于等于
['age', 'compare', 'compareAttribute' => 'default_age', 'operator'=>'>' ,'message' => '{attribute} 必须大于{compareAttribute}'],
['default_age', 'safe'],