当用户输入无效的电子邮件地址时,我无法让 Zend_Validate_EmailAddress 只显示 1 条错误消息。代码是
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email: ')
->addFilter('StringTrim')
->addFilter('StripTags')
->addValidator('EmailAddress',true, array(... error msgs ...))
->addValidator(new Zend_Validate_Db_NoRecordExists(array( ... db + table + col details ... ),true, array(... error msgs ...)))
->setRequired(true);
$this->addElement($email);
当用户输入无效的电子邮件user@email
(没有 tld)时,它会显示多个错误,例如
'email' is no valid hostname for email address 'user@email'
'email' does not match the expected structure for a DNS hostname
'email' appears to be a local network name but local network names are not allowed
我不能使用addErrorMessage('...')
,因为我需要为无效电子邮件和数据库中已存在的电子邮件显示不同的消息。因此,任何想法如何使 EmailAddress 验证仅返回 1 条错误消息。