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

RoffDaniel's avatar

Date rules

Hi, everybody. Please tell me how I can correctly use the rules 'after_or_equal' and 'before_or_equal' if the format of the entered date is 'd. m. Y'? I specify the correct date, the validator does not swear(I send the form via AJAX), but I still get an error about an incorrect date...

Thank in advance!

public function rules()
    {
        return [
            'pName' => ['required', 'string', 'max:25', 'regex:/([A-Z]{1}[a-z]{1,24})_([A-Z]{1}[a-z]{1,24})/', 'unique:players,pName'],
            'pSex' => ['required'],
            'pSkin' => ['required'],
            'pBirthday' => ['required', 'date_format:d.m.Y', 'after_or_equal:-631162800', 'before_or_equal:1135987200'],
            'pBiography' => ['required', 'min:300', 'max:500']
        ];
    }
0 likes
9 replies
SilenceBringer's avatar

Hi @roffdaniel you need to pass date in the same format (d.m.Y) to after_or_equal and before_od_equal rules, not the timestamp

1 like
s4muel's avatar

use the same format

public function rules()
    {
        return [
            'pName' => ['required', 'string', 'max:25', 'regex:/([A-Z]{1}[a-z]{1,24})_([A-Z]{1}[a-z]{1,24})/', 'unique:players,pName'],
            'pSex' => ['required'],
            'pSkin' => ['required'],
            'pBirthday' => ['required', 'date_format:d.m.Y', 'after_or_equal:1.1.1950', 'before_or_equal:31.12.2005'],
            'pBiography' => ['required', 'min:300', 'max:500']
        ];
    }
1 like
RoffDaniel's avatar

@silencebringer For some reason, now the validator itself swears at an incorrect date, even if it is in the specified interval =(

    public function rules()
    {
        return [
            'pName' => ['required', 'string', 'max:25', 'regex:/([A-Z]{1}[a-z]{1,24})_([A-Z]{1}[a-z]{1,24})/', 'unique:players,pName'],
            'pSex' => ['required'],
            'pSkin' => ['required'],
            'pBirthday' => ['required', 'date_format:d.m.Y', 'after_or_equal:01.01.1950', 'before_or_equal:31.12.2005'],
            'pBiography' => ['required', 'min:300', 'max:500']
        ];
    }
SilenceBringer's avatar

@roffdaniel just checked - it works correctly for me. Can you dump validation data?

public function rules()
{
    dd($this->validationData());
}
1 like
RoffDaniel's avatar

@silencebringer

array:5 [▼
  "_token" => "oOUEfdNUGsvIZOlqvQUt0Zuq1PdUHqFKCcdvkqpW"
  "pName" => null
  "pSex" => null
  "pBirthday" => "01.01.2005"
  "pBiography" => null
]

Please or to participate in this conversation.