Date comparison validation

My code is trying to dictate that the user’s date_of_birth shouldn’t be less than 18.

I couldn’t find a Validator method that fits for that task as I know ‘lessThan’ or ‘greaterThan’ aren’t fit for that.

I usually just add a custom rule to my validator like this:

->add('date_of_birth', 'at_least_18_years', [
    'rule' => function ($value, $context) {
        // Return true or false in here depending on the given value
    'message' => __('You are not at least 18 years old'),

Thanks I’ll try that.