Laravel Input Validation Rules

Laravel provides a wide range of validation rules for form input.

Below is a table-style reference with examples.


Commonly Used Validation Rules

Rule

Description

Laravel Example

Sample Input

required

Field must not be empty

'name' => 'required'

'John'

string

Must be a string

'bio' => 'string'

'Hello World'

min

Minimum length (string) or value (number)

'password' => 'min:8'

'MySecurePwd'

max

Maximum length (string) or value (number)

'username' => 'max:20'

'Alpha123'

between

Value length or number range

'age' => 'between:18,60'

25

email

Must be a valid email

'email' => 'email'

'user@example.com'

regex

Must match regex pattern

'username' => 'regex:/^[a-zA-Z0-9]+$/'

'Alpha123'

boolean

Must be true/false or 0/1

'active' => 'boolean'

true

in

Must be in allowed list

'role' => 'in:admin,user'

'admin'

not_in

Must NOT be in given list

'status' => 'not_in:banned,blocked'

'active'

digits

Must be digits only with exact length

'pin' => 'digits:6'

'123456'

numeric

Must be a number

'price' => 'numeric'

100

integer

Must be an integer

'count' => 'integer'

42

confirmed

Must match another field (password_confirmation)

'password' => 'confirmed'

'secret123' + 'secret123'

same

Must be identical to another field

'password' => 'same:confirm_password'

'secret123'

date

Must be valid date

'dob' => 'date'

'2025-08-28'

after

Date must be after given date

'end_date' => 'after:start_date'

'2025-09-01'

before

Date must be before given date

'start_date' => 'before:end_date'

'2025-08-20'

image

Must be an image file

'photo' => 'image'

'image.png'

mimes

Allowed file types

'file' => 'mimes:pdf,docx,jpg,png'

report.pdf

unique

Must be unique in DB column

'email' => 'unique:users,email'

'new@example.com'

exists

Must exist in DB column

'user_id' => 'exists:users,id'

5


Example Laravel Validation

$request->validate([
  'name'   => 'required|string|max:50',
  'email'  => 'required|email|unique:users,email',
  'password' => 'required|min:8|confirmed',
  'age'   => 'required|integer|between:18,60',
  'username' => 'required|regex:/^[a-zA-Z0-9]+$/',
  'role'   => 'required|in:admin,user',
  'photo'  => 'nullable|image|mimes:jpg,png|max:2048',
]);

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.