Question

I am working on a time regex (24 hours) in laravel, but cant get it working:

'Time' => 'regex:/^\d(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]$/'
Was it helpful?

Solution

Use something like this:

$rules = array(
    'time' => array('regex:/^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/')
);

Note: When using the regex pattern, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top