💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 可用的验证规则 ### [](https://octobercms.com/docs/services/validation#available-validation-rules)可用的验证规则 以下是所有可用验证规则及其功能的列表: * [公认](https://octobercms.com/docs/services/validation#rule-accepted) * [有效网址](https://octobercms.com/docs/services/validation#rule-active-url) * [之后(日期)](https://octobercms.com/docs/services/validation#rule-after) * [Α](https://octobercms.com/docs/services/validation#rule-alpha) * [Alpha Dash](https://octobercms.com/docs/services/validation#rule-alpha-dash) * [字母数字](https://octobercms.com/docs/services/validation#rule-alpha-num) * [数组](https://octobercms.com/docs/services/validation#rule-array) * [之前(日期)](https://octobercms.com/docs/services/validation#rule-before) * [之间](https://octobercms.com/docs/services/validation#rule-between) * [布尔型](https://octobercms.com/docs/services/validation#rule-boolean) * [已确认](https://octobercms.com/docs/services/validation#rule-confirmed) * [日期](https://octobercms.com/docs/services/validation#rule-date) * [日期格式](https://octobercms.com/docs/services/validation#rule-date-format) * [不同](https://octobercms.com/docs/services/validation#rule-different) * [位数](https://octobercms.com/docs/services/validation#rule-digits) * [位数之间](https://octobercms.com/docs/services/validation#rule-digits-between) * [电子邮件](https://octobercms.com/docs/services/validation#rule-email) * [存在(数据库)](https://octobercms.com/docs/services/validation#rule-exists) * [图像文件)](https://octobercms.com/docs/services/validation#rule-image) * [在](https://octobercms.com/docs/services/validation#rule-in) * [整数](https://octobercms.com/docs/services/validation#rule-integer) * [IP地址](https://octobercms.com/docs/services/validation#rule-ip) * [最高](https://octobercms.com/docs/services/validation#rule-max) * [MIME类型](https://octobercms.com/docs/services/validation#rule-mimes) * [敏](https://octobercms.com/docs/services/validation#rule-min) * [不在](https://octobercms.com/docs/services/validation#rule-not-in) * [可空](https://octobercms.com/docs/services/validation#rule-nullable) * [数字](https://octobercms.com/docs/services/validation#rule-numeric) * [正则表达式](https://octobercms.com/docs/services/validation#rule-regex) * [需要](https://octobercms.com/docs/services/validation#rule-required) * [如果需要](https://octobercms.com/docs/services/validation#rule-required-if) * [必选](https://octobercms.com/docs/services/validation#rule-required-with) * [全部必需](https://octobercms.com/docs/services/validation#rule-required-with-all) * [不需](https://octobercms.com/docs/services/validation#rule-required-without) * [不需要全部](https://octobercms.com/docs/services/validation#rule-required-without-all) * [相同](https://octobercms.com/docs/services/validation#rule-same) * [尺寸](https://octobercms.com/docs/services/validation#rule-size) * [串](https://octobercms.com/docs/services/validation#rule-string) * [时区](https://octobercms.com/docs/services/validation#rule-timezone) * [唯一(数据库)](https://octobercms.com/docs/services/validation#rule-unique) * [网址](https://octobercms.com/docs/services/validation#rule-url) #### [](https://octobercms.com/docs/services/validation#rule-accepted)公认 验证中的字段必须为*yes*,*on*或*1*。这对于验证“服务条款”接受很有用。 #### [](https://octobercms.com/docs/services/validation#rule-active-url)active\_url 根据`checkdnsrr`PHP函数,验证中的字段必须是有效的URL。 #### [](https://octobercms.com/docs/services/validation#rule-after)之后:*日期* 验证下的字段必须是给定日期之后的值。日期将被传递到PHP`strtotime`函数中。 #### [](https://octobercms.com/docs/services/validation#rule-alpha)α 验证中的字段必须完全是字母字符。 #### [](https://octobercms.com/docs/services/validation#rule-alpha-dash)alpha\_dash 验证中的字段可能包含字母数字字符以及破折号和下划线。 #### [](https://octobercms.com/docs/services/validation#rule-alpha-num)alpha\_num 验证中的字段必须完全是字母数字字符。 #### [](https://octobercms.com/docs/services/validation#rule-array)数组 验证中的字段必须为数组类型。 #### [](https://octobercms.com/docs/services/validation#rule-before)之前:*日期* 验证中的字段必须是给定日期之前的值。日期将被传递到PHP`strtotime`函数中。 #### [](https://octobercms.com/docs/services/validation#rule-between)之间:*最小*,*最大* 验证中的字段的大小必须介于给定的*min*和*max之间*。字符串,数字和文件的评估方式与`size`规则相同。 #### [](https://octobercms.com/docs/services/validation#rule-boolean)布尔值 验证中的字段必须能够转换为布尔值。接受输入的是`true`,`false`,`1`,`0`,`"1"`和`"0"`。 #### [](https://octobercms.com/docs/services/validation#rule-confirmed)已确认 验证中的字段必须具有的匹配字段`foo_confirmation`。例如,如果正在验证的字段为`password`,`password_confirmation`则输入中必须存在匹配的字段。 #### [](https://octobercms.com/docs/services/validation#rule-date)日期 根据`strtotime`PHP函数,验证中的字段必须为有效日期。 #### [](https://octobercms.com/docs/services/validation#rule-date-format)date\_format:*格式* 验证中的字段必须匹配根据PHP函数定义的*格式*`date_parse_from_format`。 #### [](https://octobercms.com/docs/services/validation#rule-different)不同:*领域* 给定的*字段*必须与正在验证的字段不同。 #### [](https://octobercms.com/docs/services/validation#rule-digits)数字:*值* 验证中的字段必须为*数字,*并且必须具有精确的*value*长度。 #### [](https://octobercms.com/docs/services/validation#rule-digits-between)digits\_between:*最小*,*最大* 验证中的字段的长度必须介于给定的*min*和*max之间*。 #### [](https://octobercms.com/docs/services/validation#rule-email)电子邮件 验证下的字段必须格式化为电子邮件地址。 #### [](https://octobercms.com/docs/services/validation#rule-exists)存在:*表*,*列* 验证下的字段必须存在于给定的数据库表上。 #### 存在规则的基本用法 ~~~ 'state' => 'exists:states' ~~~ #### 指定自定义列名 ~~~ 'state' => 'exists:states,abbreviation' ~~~ 您还可以指定更多条件,这些条件将作为“ where”子句添加到查询中: ~~~ 'email' => 'exists:staff,email,account_id,1' ~~~ `NULL`作为“ where”子句值传递将添加对`NULL`数据库值的检查: ~~~ 'email' => 'exists:staff,email,deleted_at,NULL' ~~~ #### [](https://octobercms.com/docs/services/validation#rule-image)图片 验证中的文件必须是图像(jpeg,png,bmp或gif) #### [](https://octobercms.com/docs/services/validation#rule-in)在:*foo*,*bar*,... 验证下的字段必须包含在给定的值列表中。 #### [](https://octobercms.com/docs/services/validation#rule-integer)整数 验证中的字段必须具有整数值。 #### [](https://octobercms.com/docs/services/validation#rule-ip)ip 验证下的字段必须格式化为IP地址。 #### [](https://octobercms.com/docs/services/validation#rule-max)最大值:*值* 待验证的字段必须小于或等于最大*值*。字符串,数字和文件的评估方式与[`size`](https://octobercms.com/docs/services/validation#rule-size)规则相同。 #### [](https://octobercms.com/docs/services/validation#rule-mimes)哑剧:*foo*,*bar*,... 验证中的文件必须具有与列出的扩展名之一对应的MIME类型。 #### MIME规则的基本用法 ~~~ 'photo' => 'mimes:jpeg,bmp,png' ~~~ #### [](https://octobercms.com/docs/services/validation#rule-min)最小值:*值* 待验证的字段必须有一个最低*值*。字符串,数字和文件的评估方式与[`size`](https://octobercms.com/docs/services/validation#rule-size)规则相同。 #### [](https://octobercms.com/docs/services/validation#rule-not-in)not\_in:*foo*,*bar*,... 验证中的字段不得包含在给定的值列表中。 #### [](https://octobercms.com/docs/services/validation#rule-nullable)可为空 验证中的字段可能是`null`。这在验证可包含`null`值的原始值(例如字符串和整数)时特别有用。 #### [](https://octobercms.com/docs/services/validation#rule-numeric)数字 验证中的字段必须具有数字值。 #### [](https://octobercms.com/docs/services/validation#rule-regex)正则表达式:*模式* 验证中的字段必须匹配给定的正则表达式。 **注意:**使用`regex`模式时,可能需要在数组中指定规则而不是使用管道定界符,特别是在正则表达式包含管道字符的情况下。 #### [](https://octobercms.com/docs/services/validation#rule-required)需要 验证中的字段必须存在于输入数据中。 #### [](https://octobercms.com/docs/services/validation#rule-required-if)required\_if:*字段*,*值*,... 如果*field*字段等于任何*值*,则必须存在正在验证的*字段*。 #### [](https://octobercms.com/docs/services/validation#rule-required-with)required\_with:*foo*,*bar*,... *仅当*存在任何其他指定字段时,*才*必须存在正在验证的字段。 #### [](https://octobercms.com/docs/services/validation#rule-required-with-all)required\_with\_all:*foo*,*bar*,... *仅当*所有其他指定的字段都存在时,验证字段*才*必须存在。 #### [](https://octobercms.com/docs/services/validation#rule-required-without)required\_without:*foo*,*bar*,... *仅当*不存在任何其他指定字段*时*,*才*必须存在正在验证的字段。 #### [](https://octobercms.com/docs/services/validation#rule-required-without-all)required\_without\_all:*foo*,*bar*,... *仅当*不存在所有其他指定字段*时*,*才*必须存在正在验证的字段。 #### [](https://octobercms.com/docs/services/validation#rule-same)相同:*字段* 指定的*字段*值必须与验证中的*字段*值匹配。 #### [](https://octobercms.com/docs/services/validation#rule-size)大小:*值* 验证中的字段必须具有与给定*值*匹配的大小。对于字符串数据,*值*对应于字符数。对于数字数据,*值*对应于给定的整数值。对于文件,*大小*对应于以千字节为单位的文件大小。 #### [](https://octobercms.com/docs/services/validation#rule-string)字符串:*值* 验证下的字段必须是字符串类型。 #### [](https://octobercms.com/docs/services/validation#rule-timezone)时区 根据`timezone_identifiers_list`PHP函数,验证中的字段必须是有效的时区标识符。 #### [](https://octobercms.com/docs/services/validation#rule-unique)唯一的:*table*,*column*,*except*,*idColumn* 验证下的字段在给定的数据库表上必须是唯一的。如果`column`未指定该选项,则将使用字段名称。 #### 唯一规则的基本用法 ~~~ 'email' => 'unique:users' ~~~ #### 指定自定义列名 ~~~ 'email' => 'unique:users,email_address' ~~~ #### 强制唯一规则忽略给定的ID ~~~ 'email' => 'unique:users,email_address,10' ~~~ #### 添加其他where子句 您还可以指定更多条件,这些条件将作为“ where”子句添加到查询中: ~~~ 'email' => 'unique:users,email_address,NULL,id,account_id,1' ~~~ 在上面的规则,只有一个行`account_id`的`1`将被列入独特的检查。 #### [](https://octobercms.com/docs/services/validation#rule-url)网址 验证下的字段必须设置为URL格式。 > **注意:**此函数使用PHP的`filter_var`方法。