Custom Date Format Validation in Laravel

Published on March 27, 2020 31 sec read

HIRE US 🖐
We're available to do freelance project. Take a look at our services!

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'
]);

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

Your email address will not be published. Required fields are marked *