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.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets. Protection Status