Required: Mandatory Value validation Property
[[‘字段名‘],required,‘requiredValue‘=>‘必填值‘,‘message‘=>‘提示信息‘]; #说明:CRequiredValidator 的别名, 确保了特性不为空.
Email: Email Verification
[‘email‘, ‘email‘]; #说明:CEmailValidator的别名,确保了特性的值是一个有效的电邮地址.
Match: Regular validation
[[‘字段名‘],match,‘pattern‘=>‘正则表达式‘,‘message‘=>‘提示信息‘]; [[‘字段名‘],match,‘not‘=>ture,‘pattern‘=>‘正则表达式‘,‘message‘=>‘提示信息‘]; /*正则取反*/ #说明:CRegularExpressionValidator 的别名, 确保了特性匹配一个正则表达式.
URL: url
[‘website‘, ‘url‘, ‘defaultScheme‘ => ‘http‘]; #说明:CUrlValidator 的别名, 确保了特性是一个有效的路径.
CAPTCHA: Verification Code
[‘verificationCode‘, ‘captcha‘]; #说明:CCaptchaValidator 的别名,确保了特性的值等于 CAPTCHA 显示出来的验证码.
Safe: Secure
[‘description‘, ‘safe‘];
Compare: Comparison
[‘age‘, ‘compare‘, ‘compareValue‘ => 30, ‘operator‘ => ‘>=‘]; #说明:compareValue(比较常量值) - operator(比较操作符) #说明:CCompareValidator 的别名,确保了特性的值等于另一个特性或常量.
Default: Defaults
[‘age‘, ‘default‘, ‘value‘ => null]; #说明:CDefaultValueValidator 的别名, 为特性指派了一个默认值.
exist: Presence
[‘username‘, ‘exist‘]; #说明:CExistValidator 的别名,确保属性值存在于指定的数据表字段中.
File: Files
[‘primaryImage‘, ‘file‘, ‘extensions‘ => [‘png‘, ‘jpg‘, ‘gif‘], ‘maxSize‘ => 1024*1024*1024]; #说明:CFileValidator 的别名, 确保了特性包含了一个上传文件的名称.
Filter: Filter
[[‘username‘, ‘email‘], ‘filter‘, ‘filter‘ => ‘trim‘, ‘skipOnArray‘ => true]; #说明:CFilterValidator 的别名, 使用一个filter转换属性.
In: Range
[‘level‘, ‘in‘, ‘range‘ => [1, 2, 3]]; #说明:CRangeValidator 的别名,确保了特性出现在一个预订的值列表里.
Unique: Uniqueness
[‘username‘, ‘unique‘] #说明:CUniqueValidator 的别名,确保了特性在数据表字段中是唯一的.
Integer: Integers
[‘age‘, ‘integer‘];
Number: Numeric
[‘salary‘, ‘number‘];
Double: dual-precision floating-point
[‘salary‘, ‘double‘];
Date: Day
[[‘from‘, ‘to‘], ‘date‘];
String: Strings
[‘username‘, ‘string‘, ‘length‘ => [4, 24]];
Boolean: Whether it is a Boolean value
[‘字段名‘, ‘boolean‘, ‘trueValue‘ => true, ‘falseValue‘ => false, ‘strict‘ => true]; #说明:CBooleanValidator 的别名
Yii2.0 Rules Validation Rule Daquan