Custom Date Format Validation in Laravel
In this article, I’m going to share how to validate the custom date format in Laravel. Laravel has some date validation rules. Let’s take a look:
Date Validation Rules
- Validation: date
- Validation: date_format
- Validation: after
- Validation: after_or_equal
- Validation: before
- Validation: before_or_equal
Validation: date
$request->validate([
'date_of_birth' => 'date'
]);
Validation: date_format
$request->validate([
'date_of_birth' => 'date_format:m/d/Y'
]);
Validation: after
$request->validate([
'start_date' => 'date_format:m/d/Y|after:tomorrow'
]);
Validation: after_or_equal
$now=date('m/d/Y');
$request->validate([
'start_date' => 'date_format:m/d/Y|after_or_equal:'.$now
]);
Validation: before
$request->validate([
'end_date' => 'date_format:m/d/Y|before:start_date',
'start_date' => 'date_format:m/d/Y|after:tomorrow'
]);
Validation: before_or_equal
$request->validate([
'end_date' => 'date_format:m/d/Y|before_or_equal:start_date',
'start_date' => 'date_format:m/d/Y|after:tomorrow'
]);
Md Obydullah
Software Engineer | Ethical Hacker & Cybersecurity...
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.