-1

I need to change the validation method for emails, so I was wondering if regular Magento overwriting rules extend to Zend's validaton function: Zend_Validate::is($email, 'EmailAddress'). What's the best to overwrite it?

Charles
  • 50,943
  • 13
  • 104
  • 142
Jon Derring
  • 807
  • 2
  • 14
  • 24

2 Answers2

1

Write your own validator, and pass it to Zend_Validate::is() method.

Use Zend_Validate::addDefaultNamespaces() if you use a different namespace (ie: My_)

Zend_Validate:is($email, 'My_Validator_EmailAddress');

Alternatively, you can do:

$customValidator = new My_Validator_EmailAddress();
$isValid = $customaValidator->isValid($email);
Boris Guéry
  • 47,316
  • 8
  • 52
  • 87
  • I see, so I would have to modify either parameter to the function, or the call. There is no way to keep the line of code: Zend_Validate::is($email, 'EmailAddress') the same? – Jon Derring Feb 24 '11 at 12:04
  • Except editing the core file of the Validator, no. You may try to remove default namespace, add you own, and use the same name. Take a look at the source code of Zend_Validate::is() it'll show you how the class are loaded. – Boris Guéry Feb 24 '11 at 12:13
1

You can override this class by adding new file to local code pool: app/code/local/Zend/Validate.php But in this case you should copy all methods from the original class.

Roman Snitko
  • 3,655
  • 24
  • 29