0

I'm using this to validate a 24h time format:

'start_time' => ['regex:/^(([01]?[0-9]|2[0-3]):[0-5][0-9])|null/'], 

But Laravel doesn't like it and return as not validated

I've tested the code on https://regex101.com/ and it's working correctly, am I missing something? The problem is with the null, because if I take it out, then the hour validator is fine, but not the null

BTW start_time is empty and Laravel convert it into null

TrOnNe
  • 1,632
  • 16
  • 30

1 Answers1

2

Just use laravels date format function

'start_time' => 'nullable|date_format:H:i', 

Docs

rchatburn
  • 732
  • 4
  • 13
  • Thanks, the problem here is that sometimes the user enters 00:00 AM, so with date_format:H:i I can't validate that, that's why I'm using regex – TrOnNe Mar 05 '18 at 15:45
  • 00:00 will pass, and in 24 hour there is no 00:00 AM only 00:00 – rchatburn Mar 05 '18 at 15:48