Home >Backend Development >PHP Tutorial >yii2.0 rules verification rules collection

yii2.0 rules verification rules collection

伊谢尔伦
伊谢尔伦Original
2016-12-02 10:38:441132browse

required: required value verification attribute

[['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息']; #说明:CRequiredValidator 的别名, 确保了特性不为空.

email: email verification

['email', 'email']; #说明:CEmailValidator的别名,确保了特性的值是一个有效的电邮地址.

match: regular verification

[['字段名'],match,'pattern'=>'正则表达式','message'=>'提示信息'];      
[['字段名'],match,'not'=>ture,'pattern'=>'正则表达式','message'=>'提示信息']; /*正则取反*/ #说明:CRegularExpressionValidator 的别名, 确保了特性匹配一个正则表达式.

url: URL

['website', 'url', 'defaultScheme' => 'http']; #说明:CUrlValidator 的别名, 确保了特性是一个有效的路径.

captcha: verification code

['verificationCode', 'captcha']; #说明:CCaptchaValidator 的别名,确保了特性的值等于 CAPTCHA 显示出来的验证码.

safe: safe

['description', 'safe'];

compare: compare

['age', 'compare', 'compareValue' => 30, 'operator' => '>=']; #说明:compareValue(比较常量值) - operator(比较操作符)  #说明:CCompareValidator 的别名,确保了特性的值等于另一个特性或常量.

default : default value

['age', 'default', 'value' => null]; #说明:CDefaultValueValidator 的别名, 为特性指派了一个默认值.

exist : existence

['username', 'exist']; #说明:CExistValidator 的别名,确保属性值存在于指定的数据表字段中.

file : file

['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 : integer

['age', 'integer'];

number : number

['salary', 'number'];

double: double precision floating point type

['salary', 'double'];

date: date

[['from', 'to'], 'date'];

string: string

['username', 'string', 'length' => [4, 24]];

boolean: whether it is a Boolean value

['字段名', 'boolean', 'trueValue' => true, 'falseValue' => false, 'strict' => true]; #说明:CBooleanValidator 的别名

image: whether it is a valid image file

['primaryImage','image', 'extensions' => 'png, jpg,jpeg','minWidth' => 100,'maxWidth' => 1000,'minHeight' => 100,'maxHeight' => 1000,]

If you have any omissions, please leave a message Replenish. Learn from each other


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn