Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate datetime-local input

According to MDN, I should use datetime-local type for a date and a time input:

<input type="datetime-local">

I can validate a date in laravel with this code (in a controller):

$this->validate($request, ['my_date' => 'required|date']);

But is there a way to validate a datetime-local?

like image 421
rap-2-h Avatar asked Sep 16 '25 09:09

rap-2-h


2 Answers

In your example:

$this->validate($request, ['my_date' => 'date_format:Y-m-d\TH:i']);
like image 66
Hamid Mohayeji Avatar answered Sep 18 '25 06:09

Hamid Mohayeji


You can use date_format:format or date to validate. All date validation is performed by php strtotime

The best way to know for sure is to test this. Create your rules function in the controller and test, that way you know for sure for your laravel version and your php version as you don't mention that information.

like image 27
Glenn Plas Avatar answered Sep 18 '25 06:09

Glenn Plas