Edit form date birthday field validation rules

I’ve added simple birthday date field validation rules into my rules() method:




    public function rules()

    {

        $rules = [

            // ...

            ['birthday', 'date', 'format' => 'php:Y-m-d'],

            // ...

        ];

        // ...

    }



It is working correctly: only date in requested format is allowed.

But I also want to disable years in the future, years older than 90 from the past.

Is it possible to add such additional parameters to rules set for date field or I should write custom validator by myself?

I’ve solved my problem using the following validation rules:




// ...


// Minimum date today - 90 years

$minBirthday = new \DateTime();

$minBirthday->sub(new \DateInterval('P90Y'));


// Maximum date today - 18 years

$maxBirthday = new \DateTime();

$maxBirthday->sub(new \DateInterval('P18Y'));


$rules = [

    // ...

    ['birthday', 'date', 'format' => 'php:Y-m-d', 'min' => $minBirthday->format('Y-m-d'), 'max' => $maxBirthday->format('Y-m-d')]

];


// ...