yii2.0 rules verification rules collection

伊谢尔伦
Release: 2023-03-02 20:46:02
Original
1121 people have browsed it

required: required value verification attribute

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

email: email verification

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

match: regular verification

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

url: URL

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

captcha: verification code

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

safe: safe

['description', 'safe'];
Copy after login

compare: compare

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

default : default value

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

exist : existence

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

file : file

['primaryImage', 'file', 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024]; #说明:CFileValidator 的别名, 确保了特性包含了一个上传文件的名称.
Copy after login

filter : filter

[['username', 'email'], 'filter', 'filter' => 'trim', 'skipOnArray' => true]; #说明:CFilterValidator 的别名, 使用一个filter转换属性.
Copy after login

in : range

['level', 'in', 'range' => [1, 2, 3]]; #说明:CRangeValidator 的别名,确保了特性出现在一个预订的值列表里.
Copy after login

unique : uniqueness

['username', 'unique'] #说明:CUniqueValidator 的别名,确保了特性在数据表字段中是唯一的.
Copy after login

integer : integer

['age', 'integer'];
Copy after login

number : number

['salary', 'number'];
Copy after login

double: double precision floating point type

['salary', 'double'];
Copy after login

date: date

[['from', 'to'], 'date'];
Copy after login

string: string

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

boolean: whether it is a Boolean value

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

image: whether it is a valid image file

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

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template