# 可用的驗證規則
### [](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`方法。
- 基本說明
- 基本操作
- October cms 安裝
- 后臺控制器路徑
- 圖標
- 獲取安裝網上的插件/主題
- 插件構造器使用
- 定時任務
- October后臺控制器
- vscode編輯器
- ajax操作
- 使用
- ajax更新組件
- ajax屬性API
- JavaScript API
- ajax綜合使用
- 主題
- 多語言主題
- 安裝市場主題
- 主題程序處理
- 主題
- 頁面
- 部件
- 布局
- 內容
- 組件
- 媒體
- 主題表單操作
- 表單使用
- 表單后端程序處理
- 插件
- 自定義插件
- 插件說明
- 插件導航條
- 插件數據庫設置
- 插件的設置管理
- 插件的配置文件config
- 組件
- app服務
- app容器
- 擴展行為
- 緩存
- Collection類
- Lazy Collections
- Collection方法
- 助手函數
- 數組助手函數
- 路徑助手函數
- 玄樂助手函數
- 其他助手函數
- 錯誤與記錄
- 事件處理
- HTML頁面
- 文件與目錄操作
- 散列和加密
- 郵件
- 郵件內容
- 郵件發送
- 分頁
- 模板解析器
- 動態解析器語法
- 隊列消息
- 請求與輸入
- 響應
- 視圖
- 路由器
- 配置
- 驗證操作
- 處理錯誤消息
- 錯誤消息與視圖
- 可用的驗證規則
- 有條件的驗證規則
- 驗證數組
- 錯誤消息
- 自定義驗證規則
- 模型操作
- 定義模型與其屬性
- 檢索模型
- 插入與更新
- 刪除模型
- 查詢范圍
- 事件操作
- 關聯操作
- 定義關系
- 關系類型
- 多肽關系
- 關系查詢
- 渴望加載
- 插入模型
- 數據庫操作
- 基本用法
- 數據表結構
- 查詢連貫操作
- 結果檢索
- select子句
- 插入更新
- where子句
- 排序,分組,限制和偏移
- 文件附件
- Collection操作
- 屬性操作
- 系列化json
- 數據庫屬性
- 數據庫行為
- 控制器
- 后臺控制器定義
- 后臺頁面
- 后臺組件
- 后臺表單
- 表單組件
- 表單視圖
- 表單行為
- 后臺列表
- 列表行為
- 列表過濾器
- 可用列類型
- 關系行為
- 關系行為類型
- 擴展關系行為
- 列表排序操作
- 導入導出操作
- 用于與權限
- corlate模板修改
- 修改頂部導航
- laravel問題
- 控制器不存在
- 控制器
- 路由組
- laravel筆記
- laravel 安裝
- 偽靜態配置
- 依賴注入 & 控制器
- 中間件
- 路由文件
- 視圖