Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stojankukrika's avatar

Laravel validation years input year-year

HI. Do anybody have some idea how to validate input text field which have two years like year begin and year end, like yyyy-yyyy? Year can't be less then 1900 and not bigger then current year.

0 likes
5 replies
UhOh's avatar

You could do custom, but a quickie is....

        'year' => 'required|digits:4|integer|min:1900|max:'.(date('Y')+1),

the +1 is to account for a new year registration in Australia for example. You don't want to accidentally cut them off because they are ahead. Or, maybe more precise, use \Carbon\Carbon::tomorrow()->year.

27 likes
xmarks's avatar

@uhoh I created an account just to upvote you.

I have been looking for a similar solution on an off for a little over a month now.

Kudos m8

Please or to participate in this conversation.