Custom Date Format Validation in Laravel

avatar
Published: Mar 27, 2020 - Updated: Mar 16, 2022

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

Comments

No comments yet…