Posted: 02-06-2020

Lavavel Date Validation

Lavavel Date Validation

Laravel 7 provides a rich set of date validation rules.

  • date
  • date_equals
  • date_format
  • after:date
  • after_or_equal:date
  • before:date
  • before_or_equal:date

 

date

The field under validation must be a valid date according to the strtotime PHP function


date_equals:date

The field under validation must be equal to the given date. The dates will be passed into the PHP strtotime function.


date_format

The field under validation must match the given format. You should use either date or date_format when validating a field, not both.This validation rule supports all formats supported by PHP's DateTime class.

start_date' => ['date_format:m/d/Y']

  

after:date

The field under validation must be a value after a given date. The dates will be passed into the strtotime PHP function

'start_date' => 'required|date|after:tomorrow'


Instead of passing a date string to be evaluated by strtotime, you may specify another field to compare against the date:

'finish_date' => 'required|date|after:start_date'



after_or_equal:date

The field under validation must be a value after or equal to the given date. For more information, see the after rule.

 

before:date

The field under validation must be a value preceding the given date. The dates will be passed into the PHP strtotime function.

 

before_or_equal:date

The field under validation must be a value preceding or equal to the given date. The dates will be passed into the PHP strtotime function.