Validation field if empty

I validate the field, which I am allowed to be empty string, but I have a rule there so that the field is only numeric. If I don’t fill in the field, he asks for it. Why, if I have set the field can be empty?

        $validator
            ->scalar('phone')
            ->maxLength('phone', 50)
            ->allowEmptyString('phone')
            ->add('phone', [
                'numeric' => [
                    'message'=> 'Must be numeric.',
                ]
            ]);

Thank you

Try putting “allow empty” first? I am guessing that it runs them in order, and fails as soon as it hits one that’s invalid.

I changed the rules and it doesn’t work.

I add 'allowEmpty' => true, and this works

        $validator
            ->scalar('phone')
            ->maxLength('phone', 50)
            ->allowEmptyString('phone')
            ->add('phone', [
                'numeric' => [
                    'message'=> 'Must be numeric.',
                    'allowEmpty' => true,
                ]
            ]);