Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Time regex

Working on a regex for time in the format: H:M:S. (00:00:00)

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

But getting error: preg_match(): No ending delimiter '/' found

like image 254
user3185936 Avatar asked Jan 22 '26 15:01

user3185936


2 Answers

It's much easier to use the date_format validation rule.

e.g.

'timeField' => 'required|date_format:H:i',
like image 101
Arvid Avatar answered Jan 24 '26 08:01

Arvid


Use array for rules instead of string with pipe as separator:

'Time' => array('regex:/^([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)$/'),
like image 41
Jarek Tkaczyk Avatar answered Jan 24 '26 08:01

Jarek Tkaczyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!