ThinkPHP5


think\Validate
library\think\Validate.php at line 19

Class Validate

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)

获取数据验证的场景

Constructor Detail

library\think\Validate.php at line 60

__construct

public void __construct(array rules, array message)

架构函数

Parameters:
rules - 验证规则
message - 验证提示信息

Method Detail

library\think\Validate.php at line 73

make

public static Validate make(array rules, array message)

实例化验证

Parameters:
rules - 验证规则
message - 验证提示信息

library\think\Validate.php at line 88

rule

public Validate rule(string|array name, mixed rule)

添加字段验证规则

Parameters:
name - 字段名称或者规则数组
rule - 验证规则

library\think\Validate.php at line 105

extend

public static void extend(string type, mixed callback)

注册验证(类型)规则

Parameters:
type - 验证规则类型
callback - callback方法(或闭包)

library\think\Validate.php at line 121

setTypeMsg

public static void setTypeMsg(string|array type, string msg)

获取验证规则的默认提示信息

Parameters:
type - 验证规则类型名称或者数组
msg - 验证提示信息

library\think\Validate.php at line 137

message

public Validate message(string|array name, string message)

设置提示信息

Parameters:
name - 字段名称
message - 提示信息

library\think\Validate.php at line 154

scene

public Validate scene(string|array name, mixed fields)

设置验证场景

Parameters:
name - 场景名或者场景设置数组
fields - 要验证的字段

library\think\Validate.php at line 174

batch

public Validate batch(bool batch)

设置批量验证

Parameters:
batch - 是否批量验证

library\think\Validate.php at line 188

check

public bool check(array data, mixed rules, string scene)

数据自动验证

Parameters:
data - 数据
rules - 验证规则
scene - 验证场景

library\think\Validate.php at line 284

checkItem

protected mixed checkItem(string field, mixed value, mixed rules, array data, string title, array msg)

验证单个字段规则

Parameters:
field - 字段名
value - 字段值
rules - 验证规则
data - 数据
title - 字段描述
msg - 提示信息

library\think\Validate.php at line 354

confirm

protected bool confirm(mixed value, mixed rule, array data)

验证是否和某个字段的值一致

Parameters:
value - 字段值
rule - 验证规则
data - 数据

library\think\Validate.php at line 367

different

protected bool different(mixed value, mixed rule, array data)

验证是否和某个字段的值是否不同

Parameters:
value - 字段值
rule - 验证规则
data - 数据

library\think\Validate.php at line 379

egt

protected bool egt(mixed value, mixed rule)

验证是否大于等于某个值

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 391

gt

protected bool gt(mixed value, mixed rule)

验证是否大于某个值

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 403

elt

protected bool elt(mixed value, mixed rule)

验证是否小于等于某个值

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 415

lt

protected bool lt(mixed value, mixed rule)

验证是否小于某个值

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 427

eq

protected bool eq(mixed value, mixed rule)

验证是否等于某个值

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 440

is

protected bool is(mixed value, string rule, array data)

验证字段值是否为有效格式

Parameters:
value - 字段值
rule - 验证规则
data - 验证数据

library\think\Validate.php at line 540

getImageType

protected void getImageType(mixed image)

library\think\Validate.php at line 557

activeUrl

protected bool activeUrl(mixed value, mixed rule)

验证是否为合格的域名或者IP 支持A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY类型

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 569

ip

protected bool ip(mixed value, mixed rule)

验证是否有效IP

Parameters:
value - 字段值
rule - 验证规则 ipv4 ipv6

library\think\Validate.php at line 584

fileExt

protected bool fileExt(mixed file, mixed rule)

验证上传文件后缀

Parameters:
file - 上传文件
rule - 验证规则

library\think\Validate.php at line 611

fileMime

protected bool fileMime(mixed file, mixed rule)

验证上传文件类型

Parameters:
file - 上传文件
rule - 验证规则

library\think\Validate.php at line 638

fileSize

protected bool fileSize(mixed file, mixed rule)

验证上传文件大小

Parameters:
file - 上传文件
rule - 验证规则

library\think\Validate.php at line 662

image

protected bool image(mixed file, mixed rule)

验证图片的宽高及类型

Parameters:
file - 上传文件
rule - 验证规则

library\think\Validate.php at line 689

method

protected bool method(mixed value, mixed rule)

验证请求类型

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 702

dateFormat

protected bool dateFormat(mixed value, mixed rule)

验证时间和日期是否符合指定格式

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 717

unique

protected bool unique(mixed value, mixed rule, array data, string field)

验证是否唯一

Parameters:
value - 字段值
rule - 验证规则 格式:数据表,字段名,排除ID,主键名
data - 数据
field - 验证字段名

library\think\Validate.php at line 758

behavior

protected mixed behavior(mixed value, mixed rule, array data)

使用行为类验证

Parameters:
value - 字段值
rule - 验证规则
data - 数据

library\think\Validate.php at line 770

filter

protected bool filter(mixed value, mixed rule)

使用filter_var方式验证

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 790

requireIf

protected bool requireIf(mixed value, mixed rule, array data)

验证某个字段等于某个值的时候必须

Parameters:
value - 字段值
rule - 验证规则
data - 数据

library\think\Validate.php at line 808

requireCallback

protected bool requireCallback(mixed value, mixed rule, array data)

通过回调方法验证某个字段是否必须

Parameters:
value - 字段值
rule - 验证规则
data - 数据

library\think\Validate.php at line 826

requireWith

protected bool requireWith(mixed value, mixed rule, array data)

验证某个字段有值的情况下必须

Parameters:
value - 字段值
rule - 验证规则
data - 数据

library\think\Validate.php at line 843

in

protected bool in(mixed value, mixed rule)

验证是否在范围内

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 855

notIn

protected bool notIn(mixed value, mixed rule)

验证是否不在某个范围

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 867

between

protected bool between(mixed value, mixed rule)

between验证数据

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 883

notBetween

protected bool notBetween(mixed value, mixed rule)

使用notbetween验证数据

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 899

length

protected bool length(mixed value, mixed rule)

验证数据长度

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 926

max

protected bool max(mixed value, mixed rule)

验证数据最大长度

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 945

min

protected bool min(mixed value, mixed rule)

验证数据最小长度

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 964

after

protected bool after(mixed value, mixed rule)

验证日期

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 976

before

protected bool before(mixed value, mixed rule)

验证日期

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 988

expire

protected bool expire(mixed value, mixed rule)

验证有效期

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 1011

allowIp

protected mixed allowIp(string value, mixed rule)

验证IP许可

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 1023

denyIp

protected mixed denyIp(string value, mixed rule)

验证IP禁用

Parameters:
value - 字段值
rule - 验证规则

library\think\Validate.php at line 1035

regex

protected mixed regex(mixed value, mixed rule)

使用正则验证数据

Parameters:
value - 字段值
rule - 验证规则 正则规则或者预定义正则名

library\think\Validate.php at line 1055

token

protected bool token(mixed value, mixed rule, array data)

验证表单令牌

Parameters:
value - 字段值
rule - 验证规则
data - 数据

library\think\Validate.php at line 1075

getError

public void getError()

library\think\Validate.php at line 1087

getDataValue

protected mixed getDataValue(array data, string key)

获取数据值

Parameters:
data - 数据
key - 数据标识 支持二维

library\think\Validate.php at line 1108

getRuleMsg

protected string getRuleMsg(string attribute, string title, string type, mixed rule)

获取验证规则的错误提示信息

Parameters:
attribute - 字段英文名
title - 字段描述名
type - 验证规则名称
rule - 验证规则数据

library\think\Validate.php at line 1145

getScene

protected array getScene(string scene)

获取数据验证的场景

Parameters:
scene - 验证场景

ThinkPHP5