John Doe 2 John Doe 2 - 5 months ago 17
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.

E.g.


01:15:00


I am using Laravel 5.1

EDIT

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' => [
'required',
'max:50',
'regex:/^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$/',
],


Now it works perfectly.

Answer

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

Jsfiddle

For Laravel validation rule

'name'  => array('required', 'regex:^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$,
Comments