12 * obtain it through the world-wide-web, please send an email |
12 * obtain it through the world-wide-web, please send an email |
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Validate |
16 * @package Zend_Validate |
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @version $Id: EmailAddress.php 22668 2010-07-25 14:50:46Z thomas $ |
19 * @version $Id: EmailAddress.php 25057 2012-11-02 20:35:40Z rob $ |
20 */ |
20 */ |
21 |
21 |
22 /** |
22 /** |
23 * @see Zend_Validate_Abstract |
23 * @see Zend_Validate_Abstract |
24 */ |
24 */ |
30 require_once 'Zend/Validate/Hostname.php'; |
30 require_once 'Zend/Validate/Hostname.php'; |
31 |
31 |
32 /** |
32 /** |
33 * @category Zend |
33 * @category Zend |
34 * @package Zend_Validate |
34 * @package Zend_Validate |
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
35 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
37 */ |
37 */ |
38 class Zend_Validate_EmailAddress extends Zend_Validate_Abstract |
38 class Zend_Validate_EmailAddress extends Zend_Validate_Abstract |
39 { |
39 { |
40 const INVALID = 'emailAddressInvalid'; |
40 const INVALID = 'emailAddressInvalid'; |
50 /** |
50 /** |
51 * @var array |
51 * @var array |
52 */ |
52 */ |
53 protected $_messageTemplates = array( |
53 protected $_messageTemplates = array( |
54 self::INVALID => "Invalid type given. String expected", |
54 self::INVALID => "Invalid type given. String expected", |
55 self::INVALID_FORMAT => "'%value%' is no valid email address in the basic format local-part@hostname", |
55 self::INVALID_FORMAT => "'%value%' is not a valid email address in the basic format local-part@hostname", |
56 self::INVALID_HOSTNAME => "'%hostname%' is no valid hostname for email address '%value%'", |
56 self::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for email address '%value%'", |
57 self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'", |
57 self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'", |
58 self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network", |
58 self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network", |
59 self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format", |
59 self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format", |
60 self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format", |
60 self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format", |
61 self::INVALID_LOCAL_PART => "'%localPart%' is no valid local part for email address '%value%'", |
61 self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'", |
62 self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length", |
62 self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length", |
63 ); |
63 ); |
64 |
64 |
65 /** |
65 /** |
|
66 * As of RFC5753 (JAN 2010), the following blocks are no logner reserved: |
|
67 * - 128.0.0.0/16 |
|
68 * - 191.255.0.0/16 |
|
69 * - 223.255.255.0/24 |
|
70 * @see http://tools.ietf.org/html/rfc5735#page-6 |
|
71 * |
|
72 * As of RFC6598 (APR 2012), the following blocks are now reserved: |
|
73 * - 100.64.0.0/10 |
|
74 * @see http://tools.ietf.org/html/rfc6598#section-7 |
|
75 * |
66 * @see http://en.wikipedia.org/wiki/IPv4 |
76 * @see http://en.wikipedia.org/wiki/IPv4 |
67 * @var array |
77 * @var array |
68 */ |
78 */ |
69 protected $_invalidIp = array( |
79 protected $_invalidIp = array( |
70 '0' => '0.0.0.0/8', |
80 '0' => '0.0.0.0/8', |
71 '10' => '10.0.0.0/8', |
81 '10' => '10.0.0.0/8', |
|
82 '100' => '100.64.0.0/10', |
72 '127' => '127.0.0.0/8', |
83 '127' => '127.0.0.0/8', |
73 '128' => '128.0.0.0/16', |
|
74 '169' => '169.254.0.0/16', |
84 '169' => '169.254.0.0/16', |
75 '172' => '172.16.0.0/12', |
85 '172' => '172.16.0.0/12', |
76 '191' => '191.255.0.0/16', |
|
77 '192' => array( |
86 '192' => array( |
78 '192.0.0.0/24', |
87 '192.0.0.0/24', |
79 '192.0.2.0/24', |
88 '192.0.2.0/24', |
80 '192.88.99.0/24', |
89 '192.88.99.0/24', |
81 '192.168.0.0/16' |
90 '192.168.0.0/16' |
82 ), |
91 ), |
83 '198' => '198.18.0.0/15', |
92 '198' => '198.18.0.0/15', |
84 '223' => '223.255.255.0/24', |
|
85 '224' => '224.0.0.0/4', |
93 '224' => '224.0.0.0/4', |
86 '240' => '240.0.0.0/4' |
94 '240' => '240.0.0.0/4' |
87 ); |
95 ); |
88 |
96 |
89 /** |
97 /** |
175 if (array_key_exists('allow', $options)) { |
183 if (array_key_exists('allow', $options)) { |
176 $this->setHostnameValidator($options['hostname'], $options['allow']); |
184 $this->setHostnameValidator($options['hostname'], $options['allow']); |
177 } else { |
185 } else { |
178 $this->setHostnameValidator($options['hostname']); |
186 $this->setHostnameValidator($options['hostname']); |
179 } |
187 } |
|
188 } elseif ($this->_options['hostname'] == null) { |
|
189 $this->setHostnameValidator(); |
180 } |
190 } |
181 |
191 |
182 if (array_key_exists('mx', $options)) { |
192 if (array_key_exists('mx', $options)) { |
183 $this->setValidateMx($options['mx']); |
193 $this->setValidateMx($options['mx']); |
184 } |
194 } |
203 * @return Zend_Validate_Abstract Provides a fluent interface |
213 * @return Zend_Validate_Abstract Provides a fluent interface |
204 * @throws Zend_Validate_Exception |
214 * @throws Zend_Validate_Exception |
205 */ |
215 */ |
206 public function setMessage($messageString, $messageKey = null) |
216 public function setMessage($messageString, $messageKey = null) |
207 { |
217 { |
208 $messageKeys = $messageKey; |
|
209 if ($messageKey === null) { |
218 if ($messageKey === null) { |
210 $keys = array_keys($this->_messageTemplates); |
219 $this->_options['hostname']->setMessage($messageString); |
211 $messageKeys = current($keys); |
220 parent::setMessage($messageString); |
212 } |
221 return $this; |
213 |
222 } |
214 if (!isset($this->_messageTemplates[$messageKeys])) { |
223 |
|
224 if (!isset($this->_messageTemplates[$messageKey])) { |
215 $this->_options['hostname']->setMessage($messageString, $messageKey); |
225 $this->_options['hostname']->setMessage($messageString, $messageKey); |
216 } |
226 } |
217 |
227 |
218 $this->_messageTemplates[$messageKeys] = $messageString; |
228 $this->_messageTemplates[$messageKey] = $messageString; |
219 return $this; |
229 return $this; |
220 } |
230 } |
221 |
231 |
222 /** |
232 /** |
223 * Returns the set hostname validator |
233 * Returns the set hostname validator |