Phalcon-相同字段的条件验证

I want to validate friend field. It may be email-address or mobile number. How to validate both input values(email/mobile) ?

My scenario is:

$this->add('refer_type', new PresenceOf(array(
           'message' => self::fetchErrorMessage('Refer Type', 'ERROR_REQUIRED'))))
     ->add('refer_type', new InclusionIn(array(
           'message' => self::fetchErrorMessage('Refer Type', 'ERROR_VALID'),
           'domain' => ['mobile', 'email'])));

If refer type is mobile then I will validate it like:

$this->add('friend', new PresenceOf(array(
           'message' => self::fetchErrorMessage('Friend', 'ERROR_REQUIRED'))))
     ->add('friend', new Regex(array(
            'pattern' =>  '/^[0-9]*$/',
            'message' => self::fetchErrorMessage('friend', 'ERROR_VALID'))));

Same for email but I want to check both validation(email/mobile) at the same time regarding same field.

I suggest you to write custom validator (FriendValidator). You can find an example at https://docs.phalconphp.com/en/latest/reference/validation.html (Check IpValidator) Then you will use your FriendValidator in your Form.