您好,登錄后才能下訂單哦!
本篇文章為大家展示了如何在Laravel中使用validation實(shí)現(xiàn)驗(yàn)證,內(nèi)容簡明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
更改 resources\lang 目錄下邊的 validation.php
<?php return [ 'accepted' => ':attribute必須接受', 'active_url' => ':attribute必須是一個(gè)合法的 URL', 'after' => ':attribute 必須是 :date 之后的一個(gè)日期', 'after_or_equal' => ':attribute 必須是 :date 之后或相同的一個(gè)日期', 'alpha' => ':attribute只能包含字母', 'alpha_dash' => ':attribute只能包含字母、數(shù)字、中劃線或下劃線', 'alpha_num' => ':attribute只能包含字母和數(shù)字', 'array' => ':attribute必須是一個(gè)數(shù)組', 'before' => ':attribute 必須是 :date 之前的一個(gè)日期', 'before_or_equal' => ':attribute 必須是 :date 之前或相同的一個(gè)日期', 'between' => [ 'numeric' => ':attribute 必須在 :min 到 :max 之間', 'file' => ':attribute 必須在 :min 到 :max KB 之間', 'string' => ':attribute 必須在 :min 到 :max 個(gè)字符之間', 'array' => ':attribute 必須在 :min 到 :max 項(xiàng)之間', ], 'boolean' =>':attribute字符必須是 true 或false, 1 或 0 ', 'confirmed' => ':attribute 二次確認(rèn)不匹配', 'date' => ':attribute 必須是一個(gè)合法的日期', 'date_format' => ':attribute 與給定的格式 :format 不符合', 'different' => ':attribute 必須不同于 :other', 'digits' => ':attribute必須是 :digits 位.', 'digits_between' => ':attribute 必須在 :min 和 :max 位之間', 'dimensions' => ':attribute具有無效的圖片尺寸', 'distinct' => ':attribute字段具有重復(fù)值', 'email' => ':attribute必須是一個(gè)合法的電子郵件地址', 'exists' => '選定的 :attribute 是無效的.', 'file' => ':attribute必須是一個(gè)文件', 'filled' => ':attribute的字段是必填的', 'image' => ':attribute必須是 jpeg, png, bmp 或者 gif 格式的圖片', 'in' => '選定的 :attribute 是無效的', 'in_array' => ':attribute 字段不存在于 :other', 'integer' => ':attribute 必須是個(gè)整數(shù)', 'ip' => ':attribute必須是一個(gè)合法的 IP 地址。', 'json' => ':attribute必須是一個(gè)合法的 JSON 字符串', 'max' => [ 'numeric' => ':attribute 的最大長度為 :max 位', 'file' => ':attribute 的最大為 :max', 'string' => ':attribute 的最大長度為 :max 字符', 'array' => ':attribute 的最大個(gè)數(shù)為 :max 個(gè).', ], 'mimes' => ':attribute 的文件類型必須是 :values', 'min' => [ 'numeric' => ':attribute 的最小長度為 :min 位', 'file' => ':attribute 大小至少為 :min KB', 'string' => ':attribute 的最小長度為 :min 字符', 'array' => ':attribute 至少有 :min 項(xiàng)', ], 'not_in' => '選定的 :attribute 是無效的', 'numeric' => ':attribute 必須是數(shù)字', 'present' => ':attribute 字段必須存在', 'regex' => ':attribute 格式是無效的', 'required' => ':attribute 字段是必須的', 'required_if' => ':attribute 字段是必須的當(dāng) :other 是 :value', 'required_unless' => ':attribute 字段是必須的,除非 :other 是在 :values 中', 'required_with' => ':attribute 字段是必須的當(dāng) :values 是存在的', 'required_with_all' => ':attribute 字段是必須的當(dāng) :values 是存在的', 'required_without' => ':attribute 字段是必須的當(dāng) :values 是不存在的', 'required_without_all' => ':attribute 字段是必須的當(dāng) 沒有一個(gè) :values 是存在的', 'same' => ':attribute和:other必須匹配', 'size' => [ 'numeric' => ':attribute 必須是 :size 位', 'file' => ':attribute 必須是 :size KB', 'string' => ':attribute 必須是 :size 個(gè)字符', 'array' => ':attribute 必須包括 :size 項(xiàng)', ], 'string' => ':attribute 必須是一個(gè)字符串', 'timezone' => ':attribute 必須是個(gè)有效的時(shí)區(qū).', 'unique' => ':attribute 已存在', 'url' => ':attribute 無效的格式', /* |-------------------------------------------------------------------------- | Custom Validation Language Lines |-------------------------------------------------------------------------- | | Here you may specify custom validation messages for attributes using the | convention "attribute.rule" to name the lines. This makes it quick to | specify a specific custom language line for a given attribute rule. | */ 'custom' => [ 'attribute-name' => [ 'rule-name' => 'custom-message', ], ], 'attributes' => [ // 'name' => '名字', // 'age' => '年齡', ], ];
上述內(nèi)容就是如何在Laravel中使用validation實(shí)現(xiàn)驗(yàn)證,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。