yii2.0-rules验证规则应用实例
Rules验证规则:
required : 必须值验证属性||CRequiredValidator 的别名, 确保了特性不为空.
[['字段名1','字段名2'],required] //字段1 2 必填 [['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息'];
email : 邮箱验证||CEmailValidator 的别名,确保了特性的值是一个有效的电邮地址.
['email', 'email'];
match : 正则验证||CRegularExpressionValidator 的别名, 确保了特性匹配一个正则表达式.
[['字段名'],'match','pattern'=>'正则表达式','message'=>'提示信息'];
[['字段名'],'match','not'=>ture,'pattern'=>'正则表达式','message'=>'提示信息']; /*正则取反*/
url : 网址||CUrlValidator 的别名, 确保了特性是一个有效的路径.
['website', 'url', 'defaultScheme' => 'http'];
captcha(验证码)||CCaptchaValidator 的别名,确保了特性的值等于 CAPTCHA 显示出来的验证码.
['verificationCode', 'captcha'];
safe : 安全
['description', 'safe'];
compare :(比较) CCompareValidator 的别名, 确保了特性的值等于另一个特性或常量.
['repassword', 'compare', 'compareAttribute' => 'password','message'=>'两次输入的密码不一致!'], //compareValue:比较常量值 operator:比较操作符
['age', 'compare', 'compareValue' => 30, 'operator' => '>='];
default : 默认值||CDefaultValueValidator 的别名, 为特性指派了一个默认值.
['age', 'default', 'value' => null];
exist : 存在||CExistValidator 的别名, 确保属性值存在于指定的数据表字段中.
['字段名', 'exist'];
file : 文件||CFileValidator 的别名, 确保了特性包含了一个上传文件的名称.
['primaryImage', 'file', 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024]
filter : 滤镜||CFilterValidator 的别名, 使用一个filter转换属性.
//'skipOnArray' => true 非必填
[['username', 'email'], 'filter', 'filter' => 'trim', 'skipOnArray' => true];
in : 范围||CRangeValidator 的别名, 确保了特性出现在一个预订的值列表里.
['level', 'in', 'range' => [1, 2, 3]];
unique : 唯一性||CUniqueValidator 的别名, 确保了特性在数据表字段中是唯一的.
['字段名', 'unique']
integer : 整数
['age', 'integer'];
number : 数字
['salary', 'number'];
double : 双精度浮点型
['salary', 'double'];
date : (日期)
[['from', 'to'], 'date'];
string : 字符串
['username', 'string', 'length' => [4, 24]];
boolean : 是否为一个布尔值||CBooleanValidator 的别名
['字段名', 'boolean', 'trueValue' => true, 'falseValue' => false, 'strict' => true];
image :是否为有效的图片文件
['primaryImage', 'image', 'extensions' => 'png, jpg', 'minWidth' => 100, 'maxWidth' => 1000, 'minHeight' => 100, 'maxHeight' => 1000]
each:遍历,ids 和 product_ids 是数字的集合
[['ids', 'product_ids'], 'each', 'rule' => ['integer']],
yii2.0-rules验证规则应用实例的更多相关文章
- [moka同学收藏]Yii2.0 rules验证规则
required : 必须值验证属性 [['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息']; #说明:CRequiredV ...
- Yii2.0 rules验证规则大全
required : 必须值验证属性 [['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息']; #说明:CRequiredV ...
- Yii2中rules验证规则
required : 必须值验证属性 [['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息']; #说明:CRequiredV ...
- Yii2 rules验证规则
Rules验证规则: required : 必须值验证属性||CRequiredValidator 的别名, 确保了特性不为空. [['字段名1','字段名2'],required] //字段 ...
- yii2 rules 验证规则
yii2 框架定义的约束 public $builtInValidators = [ 'boolean' => 'yii\validators\BooleanValidator', 'capt ...
- yii2中自定义验证规则rules
作者:白狼 出处:www.manks.top/article/yii2_custom_rules 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追 ...
- Yii CModel中rules验证规则[转]
array( array(‘username’, ‘required’), array(‘username’, ‘length’, ‘min’=>3, ‘max’=>12), array( ...
- Yii CModel中rules验证规则
array( array(‘username’, ‘required’), array(‘username’, ‘length’, ‘min’=>3, ‘max’=>12), array( ...
- ThinkPhp5.0模型验证规则
Tp5提供了模型数据规则的验证功能,用于在数据save或者update前验证数据的有效性.Tp5提供校验规则的类为\Think\Validate,默认提供的校验规则可以查看该文件. 在Model文件中 ...
随机推荐
- python常见的模块
Python内置模块名称 功能简介 详细解释/使用示例 os 和操作系统相关 os.path — Common pathname manipulations sys 和系统相关 sys — Syste ...
- poj-------(2240)Arbitrage(最短路)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15640 Accepted: 6563 Descri ...
- IO流 总结二
流只能操作数据. File 类 用来将文件或者文件夹封装成对象. 方便文件与文件夹进行操作 File对象可以作为参数传递给流的构造函数. 可以将已有的和已出现的文件或者文件夹封装成对象 File a ...
- 121. 122. 123. 188. Best Time to Buy and Sell Stock *HARD* 309. Best Time to Buy and Sell Stock with Cooldown -- 买卖股票
121. Say you have an array for which the ith element is the price of a given stock on day i. If you ...
- SELECTION-SCREEN 文本丢失
最近有点无聊....随便找点东西填了... 自从系统上线,经常出现程序的的文本丢失,然后选择界面就变成英文的了....一直在出现,就是解决不了,不知道到底是哪里的问题 严重怀疑是服务器上文件丢失... ...
- easyui numberbox不可编辑
今天又遇到了给easyui中numberbox设置不可编辑的功能,在(http://www.jeasyuicn.com/api/docTtml/index.htm)API中找到了一个方法:
- C#WPF做FTP上传下载获取文件列表
Xaml.cs: using Microsoft.Win32;using System;using System.Collections.Generic;using System.IO;using S ...
- mysql在一台服务器搭建主从1
1. 登录mysq的方法: mysql-S /tmp/mysql.sock 登录3306 mysql -S /tmp/mysql_slave.sock 登录3307 mysql -h 127.0. ...
- 【vmware vcp 5.1】安装及配置及笔记散记
ESXi的几个命令技巧: ------------------------------------------------- alt-f1: 进入console alt-f2: 返回DCUI alt- ...
- IoTimerInLineHook
#ifndef CXX_IOTIMERINLINEHOOK_H # include "IoTimerInlineHook.h" #endif ULONG32 SSDT_NtOpen ...