How To Validate Date Format in Laravel

In this post, I would like to show you date format validation in Laravel application, You should always validate forms to ensure that you receive data in the good format.

Date validation Rules

Here is the list of validation rules

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

How to use validation rules

You can validate date with date_format or date validation rules. In order to satisfy those two validation rules, the field must be a valid date according to the strtotime PHP function. With date_format:format method you can set the preferred date format, and the filed value must match the given format.

Here is the examples with both –

after:date : Used to ensure that a field contains valid date that occurs after provided date. Here’s an example.

You could also use after_or_equal:date same as shown above, the only difference is that the field under validation must be a value after or equal to the given date

You can even validate preceding dates with before:date and before_or_equal:date respectively. You can use this validation rules also just like above shown.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments Protection Status
Would love your thoughts, please comment.x