How to validate time in laravel

Laravel Questions editorial team
Editorial team · 11 October 2026

You want a time field that accepts only values from 16:00 to 22:00. The between:16:00,22:00 rule looks right, but it does not do this.

Why between is wrong

between is a size rule. For a string it compares the length of the text, not the time. 19:30 is five characters, so a window of 3,8 accepts it and a window of 6,8 rejects it, whatever the clock says. On Laravel 10, 16:00 is also rejected as a size limit and throws a NumberFormatException.

The rules that work

public function rules(): array
{
    return [
        'time' => ['required', 'date_format:H:i', 'after_or_equal:16:00', 'before_or_equal:22:00'],
    ];
}
  • date_format:H:i makes the value a 24-hour HH:MM. 7pm, 19, 25:00 and 19:30:00 fail.
  • after_or_equal:16:00 and before_or_equal:22:00 compare the times, and both ends are allowed.

This accepts 16:00, 19:30 and 22:00, and rejects 15:59, 22:01 and 23:59.

Use it in a form request or inline:

$request->validate([
    'time' => ['required', 'date_format:H:i', 'after_or_equal:16:00', 'before_or_equal:22:00'],
]);

For JSON clients, a failure returns status 422 with the errors under time.

Tested on Laravel 10.x (PHP 8.1) and 12.x (PHP 8.3): the tests run the accepted and rejected values above, show that between is length-based, and check the 422 response. Source: tests/laravel-verification/files/q908.

Our network