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

  1. Validation: date
  2. Validation: date_format
  3. Validation: after
  4. Validation: after_or_equal
  5. Validation: before
  6. 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'
]);

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.