Validate
public class Validate
Constructor Summary | |
---|---|
void | __construct(array rules, array message) 架构函数 |
Method Summary | |
---|---|
static Validate | make(array rules, array message) 实例化验证 |
Validate | rule(string|array name, mixed rule) 添加字段验证规则 |
static void | extend(string type, mixed callback) 注册验证(类型)规则 |
static void | setTypeMsg(string|array type, string msg) 获取验证规则的默认提示信息 |
Validate | message(string|array name, string message) 设置提示信息 |
Validate | scene(string|array name, mixed fields) 设置验证场景 |
Validate | batch(bool batch) 设置批量验证 |
bool | check(array data, mixed rules, string scene) 数据自动验证 |
protected mixed | checkItem(string field, mixed value, mixed rules, array data, string title, array msg) 验证单个字段规则 |
protected bool | confirm(mixed value, mixed rule, array data) 验证是否和某个字段的值一致 |
protected bool | different(mixed value, mixed rule, array data) 验证是否和某个字段的值是否不同 |
protected bool | egt(mixed value, mixed rule) 验证是否大于等于某个值 |
protected bool | gt(mixed value, mixed rule) 验证是否大于某个值 |
protected bool | elt(mixed value, mixed rule) 验证是否小于等于某个值 |
protected bool | lt(mixed value, mixed rule) 验证是否小于某个值 |
protected bool | eq(mixed value, mixed rule) 验证是否等于某个值 |
protected bool | is(mixed value, string rule, array data) 验证字段值是否为有效格式 |
protected void | getImageType(mixed image) |
protected bool | activeUrl(mixed value, mixed rule) 验证是否为合格的域名或者IP 支持A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY类型 |
protected bool | ip(mixed value, mixed rule) 验证是否有效IP |
protected bool | fileExt(mixed file, mixed rule) 验证上传文件后缀 |
protected bool | fileMime(mixed file, mixed rule) 验证上传文件类型 |
protected bool | fileSize(mixed file, mixed rule) 验证上传文件大小 |
protected bool | image(mixed file, mixed rule) 验证图片的宽高及类型 |
protected bool | method(mixed value, mixed rule) 验证请求类型 |
protected bool | dateFormat(mixed value, mixed rule) 验证时间和日期是否符合指定格式 |
protected bool | unique(mixed value, mixed rule, array data, string field) 验证是否唯一 |
protected mixed | behavior(mixed value, mixed rule, array data) 使用行为类验证 |
protected bool | filter(mixed value, mixed rule) 使用filter_var方式验证 |
protected bool | requireIf(mixed value, mixed rule, array data) 验证某个字段等于某个值的时候必须 |
protected bool | requireCallback(mixed value, mixed rule, array data) 通过回调方法验证某个字段是否必须 |
protected bool | requireWith(mixed value, mixed rule, array data) 验证某个字段有值的情况下必须 |
protected bool | in(mixed value, mixed rule) 验证是否在范围内 |
protected bool | notIn(mixed value, mixed rule) 验证是否不在某个范围 |
protected bool | between(mixed value, mixed rule) between验证数据 |
protected bool | notBetween(mixed value, mixed rule) 使用notbetween验证数据 |
protected bool | length(mixed value, mixed rule) 验证数据长度 |
protected bool | max(mixed value, mixed rule) 验证数据最大长度 |
protected bool | min(mixed value, mixed rule) 验证数据最小长度 |
protected bool | after(mixed value, mixed rule) 验证日期 |
protected bool | before(mixed value, mixed rule) 验证日期 |
protected bool | expire(mixed value, mixed rule) 验证有效期 |
protected mixed | allowIp(string value, mixed rule) 验证IP许可 |
protected mixed | denyIp(string value, mixed rule) 验证IP禁用 |
protected mixed | regex(mixed value, mixed rule) 使用正则验证数据 |
protected bool | token(mixed value, mixed rule, array data) 验证表单令牌 |
void | getError() |
protected mixed | getDataValue(array data, string key) 获取数据值 |
protected string | getRuleMsg(string attribute, string title, string type, mixed rule) 获取验证规则的错误提示信息 |
protected array | getScene(string scene) 获取数据验证的场景 |
public void __construct(array rules, array message)
架构函数
public static Validate make(array rules, array message)
实例化验证
public Validate rule(string|array name, mixed rule)
添加字段验证规则
public static void extend(string type, mixed callback)
注册验证(类型)规则
public static void setTypeMsg(string|array type, string msg)
获取验证规则的默认提示信息
public Validate message(string|array name, string message)
设置提示信息
public Validate scene(string|array name, mixed fields)
设置验证场景
public Validate batch(bool batch)
设置批量验证
public bool check(array data, mixed rules, string scene)
数据自动验证
protected mixed checkItem(string field, mixed value, mixed rules, array data, string title, array msg)
验证单个字段规则
protected bool confirm(mixed value, mixed rule, array data)
验证是否和某个字段的值一致
protected bool different(mixed value, mixed rule, array data)
验证是否和某个字段的值是否不同
protected bool egt(mixed value, mixed rule)
验证是否大于等于某个值
protected bool gt(mixed value, mixed rule)
验证是否大于某个值
protected bool elt(mixed value, mixed rule)
验证是否小于等于某个值
protected bool lt(mixed value, mixed rule)
验证是否小于某个值
protected bool eq(mixed value, mixed rule)
验证是否等于某个值
protected bool is(mixed value, string rule, array data)
验证字段值是否为有效格式
protected void getImageType(mixed image)
protected bool activeUrl(mixed value, mixed rule)
验证是否为合格的域名或者IP 支持A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY类型
protected bool ip(mixed value, mixed rule)
验证是否有效IP
protected bool fileExt(mixed file, mixed rule)
验证上传文件后缀
protected bool fileMime(mixed file, mixed rule)
验证上传文件类型
protected bool fileSize(mixed file, mixed rule)
验证上传文件大小
protected bool image(mixed file, mixed rule)
验证图片的宽高及类型
protected bool method(mixed value, mixed rule)
验证请求类型
protected bool dateFormat(mixed value, mixed rule)
验证时间和日期是否符合指定格式
protected bool unique(mixed value, mixed rule, array data, string field)
验证是否唯一
protected mixed behavior(mixed value, mixed rule, array data)
使用行为类验证
protected bool filter(mixed value, mixed rule)
使用filter_var方式验证
protected bool requireIf(mixed value, mixed rule, array data)
验证某个字段等于某个值的时候必须
protected bool requireCallback(mixed value, mixed rule, array data)
通过回调方法验证某个字段是否必须
protected bool requireWith(mixed value, mixed rule, array data)
验证某个字段有值的情况下必须
protected bool in(mixed value, mixed rule)
验证是否在范围内
protected bool notIn(mixed value, mixed rule)
验证是否不在某个范围
protected bool between(mixed value, mixed rule)
between验证数据
protected bool notBetween(mixed value, mixed rule)
使用notbetween验证数据
protected bool length(mixed value, mixed rule)
验证数据长度
protected bool max(mixed value, mixed rule)
验证数据最大长度
protected bool min(mixed value, mixed rule)
验证数据最小长度
protected bool after(mixed value, mixed rule)
验证日期
protected bool before(mixed value, mixed rule)
验证日期
protected bool expire(mixed value, mixed rule)
验证有效期
protected mixed allowIp(string value, mixed rule)
验证IP许可
protected mixed denyIp(string value, mixed rule)
验证IP禁用
protected mixed regex(mixed value, mixed rule)
使用正则验证数据
protected bool token(mixed value, mixed rule, array data)
验证表单令牌
public void getError()
protected mixed getDataValue(array data, string key)
获取数据值
protected string getRuleMsg(string attribute, string title, string type, mixed rule)
获取验证规则的错误提示信息
protected array getScene(string scene)
获取数据验证的场景