2

我正在使用 zend_validate_email 验证电子邮件地址。例如,对于电子邮件地址 aa@aa,它会抛出几条错误消息,包括描述 DNS 不匹配 (:S) 的技术性很强的信息。

我试图让它只显示一条我希望它显示的消息(例如:“请输入有效的电子邮件”)。

除了创建一个子类并覆盖 isValid 方法、清除错误消息数组之外,还有什么方法可以优雅地做到这一点?

谢谢!

4

1 回答 1

1
$validator = new Zend_Validate_EmailAddress();
// sets the message for all error types
$validator->setMessage('Please enter a valid email');
// sets the message for the INVALID_SEGMENT error
$validator->setMessage('Something with the part after the @ is wrong', Zend_Validate_EmailAddress::INVALID_SEGMENT);

有关错误和消息模板的完整列表,请参见 Zend_Validate_EmailAddress 类

于 2010-12-06T11:43:42.457 回答