我想验证friend字段。它可能是电子邮件地址或手机号码。如何验证两个输入值(电子邮件/手机)?
我的场景是:
$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'])));
如果推荐类型是移动的,那么我会验证它,比如:
$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'))));
电子邮件也是如此,但我想同时检查同一字段的两个验证(电子邮件/手机)。
我建议您编写自定义验证器(FriendValidator)。您可以在中找到示例https://docs.phalconphp.com/en/latest/reference/validation.html(检查IpValidator)然后您将在表单中使用FriendValidator。