John Doe 2 John Doe 2 - 1 year ago 99
PHP Question

Laravel restrict input field for time index

How can I restrict the user in Laravel to write only a time index in an input field.



I am using Laravel 5.1


I tried Vinod VT suggestion like this in my Model

public static $rules = [
'input_chapter_img' => 'required|min:8|regex:^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$',

I got this:

preg_match(): No ending delimiter '/' found

Laravel got confused with this Pipe


So I did this:

'title' => [

Now it works perfectly.

Answer Source

Try this pattern,

<input type="text" id="time" pattern="^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$" required>

Which only accept this pattern hh:mm:ss


For Laravel validation rule

'name'  => array('required', 'regex:^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download