当前位置: 首页 > 后端技术 > PHP

Yii2规则通用规则

时间:2023-03-29 17:34:10 PHP

required:必填值校验属性[['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息'];#Description:CRequiredValidator的别名确保该功能不为空。email:邮箱验证['email','email'];#Description:CEmailValidator的别名,它确保该特征的值是一个有效的电子邮件地址。match:正则校验[['字段名'],match,'模式'=>'正则表达式','消息'=>'提示信息'];[['字段名'],match,'not'=>ture,'模式'=>'正则表达式','消息'=>'提示信息'];/regularnegation/#说明:CRegularExpressionValidator的别名确保特征匹配正则表达式。url:URL['网站','url','defaultScheme'=>'http'];#Description:CUrlValidator的别名,保证特征是有效路径。captcha:验证码['verificationCode','captcha'];#说明:CCaptchaValidator的别名,保证特征的值等于CAPTCHA验证码显示的值。安全:安全['描述','安全'];比较:比较['年龄','比较','比较值'=>30,'运算符'=>'>='];#说明:compareValue(Comparingconstantvalues)-operator(比较运算符)#说明:CCompareValidator的别名,它确保属性的值等于另一个属性或常量。默认值:默认值['age','default','value'=>null];#Description:CDefaultValueValidator的别名,为属性赋一个默认值。存在:存在['用户名','存在'];#Description:CExistValidator别名保证属性值存在于指定的数据表字段中。文件:文件['primaryImage','file','extensions'=>['png','jpg','gif'],'maxSize'=>102410241024];#Description:CFileValidator的别名确保该功能包含上传文件的名称。过滤器:过滤器[['用户名','电子邮件'],'过滤器','过滤器'=>'修剪','skipOnArray'=>true];#说明:CFilterValidator的别名,使用过滤器来转换属性。在:范围['水平','在','范围'=>[1、2、3]];#Description:CRangeValidatorCUniqueValidator的别名确保该特征出现在保留值列表中。unique:Uniqueness['username','unique']#说明:CUniqueValidator的别名保证特征在数据表字段中唯一。integer:integer['age','integer'];number:number['salary','number'];double:双精度浮点型['salary','double'];date:date[['从','到'],'日期'];字符串:字符串['用户名','字符串','长度'=>[4,24]];boolean:是否为布尔值['fieldname','boolean','trueValue'=>true,'falseValue'=>false,'strict'=>true];#说明:CBool??eanValidator的别名图片:是否为有效图片文件['primaryImage','image','extensions'=>'png,jpg,jpeg','minWidth'=>100,'maxWidth'=>1000,'minHeight'=>100,'maxHeight'=>1000,]