×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
2
Language: PHP
Posted by: Massimo Zappino
Added: Jan 29, 2011 11:10 PM
Modified: Jan 30, 2011 12:40 PM
Views: 300
A custom validator for email address
  1. <?php
  2.  
  3. /**
  4.  * @see Zend_Validate_Abstract
  5.  */
  6. require_once 'Zend/Validate/Abstract.php';
  7.  
  8. class MyApp_Validate_EmailAddress extends Zend_Validate_EmailAddress
  9. {
  10.     const INVALID = 'emailInvalid';
  11.  
  12.  
  13.     /**
  14.      * Validation failure message template definitions
  15.      *
  16.      * @var array
  17.      */
  18.     protected $_messageTemplates = array(
  19.         self::INVALID => "Email address is not valid",
  20.     );
  21.     private $projectConfig;
  22.  
  23.     public function __construct($options = array())
  24.     {
  25.         parent::__construct($options);
  26.         $this->projectConfig = Zend_Registry::get('projectConfig');
  27.     }
  28.  
  29.     /**
  30.      *
  31.      * @param  string $value
  32.      * @return boolean
  33.      */
  34.     public function isValid($value)
  35.     {
  36.         if (!parent::isValid($value)) {
  37.             $this->_errors = array();
  38.             $this->_messages = array();
  39.             $this->_error(self::INVALID);
  40.             return false;
  41.         }
  42.  
  43.         return true;
  44.     }
  45.  
  46. }
  47.  

1 comment

Massimo Zappino 6 years ago
This validator is useful if you don't need the default Zend Framework default email validator which is much more restrictive.

Write a comment