cvs: pear /Validate Validate.php
| From: | David Coallier | Date: | Mon, 05 Mar 2007 16:07:38 +0000 |
| Subject: | cvs: pear /Validate Validate.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44986@lists.php.net to get a copy of this message | ||
davidc Mon Mar 5 16:07:38 2007 UTC
Modified files:
/pear/Validate Validate.php
Log:
Working version and fix for bug #10044. Added fullTLD validation depending on the valid/official
TLDs as found here:
http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate.php?r1=1.108&r2=1.109&diff_format=u
Index: pear/Validate/Validate.php
diff -u pear/Validate/Validate.php:1.108 pear/Validate/Validate.php:1.109
--- pear/Validate/Validate.php:1.108 Thu Mar 1 22:11:01 2007
+++ pear/Validate/Validate.php Mon Mar 5 16:07:38 2007
@@ -34,7 +34,7 @@
* @author Amir Mohammad Saied <amir@php.net>
* @copyright 1997-2006 Pierre-Alain Joye,Tomas V.V.Cox,Amir Mohammad Saied
* @license http://www.opensource.org/licenses/bsd-license.php
New BSD License
- * @version CVS: $Id: Validate.php,v 1.108 2007/03/01 22:11:01 davidc Exp $
+ * @version CVS: $Id: Validate.php,v 1.109 2007/03/05 16:07:38 davidc Exp $
* @link http://pear.php.net/package/Validate
*/
@@ -90,10 +90,10 @@
* @access protected
* @var array $_iTld (International top-level domains)
*/
- var $_iTld = array(
+ var $_itld = array(
'arpa',
'root',
- );
+ );
/**
* Generic top-level domain
@@ -104,7 +104,7 @@
* @access protected
* @var array $_gTld (Generic top-level domains)
*/
- var $_gTld = array(
+ var $_gtld = array(
'aero',
'biz',
'cat',
@@ -138,7 +138,7 @@
* @access protected
* @var array $_ccTld (Country Code Top-Level Domain)
*/
- var $_ccTld = array(
+ var $_cctld = array(
'ac',
'ad','ae','af','ag',
'ai','al','am','an',
@@ -445,6 +445,7 @@
array_push($validate, 'itld');
break;
+ /** 7 - 8 */
case VALIDATE_CCTLD_EMAILS | VALIDATE_ITLD_EMAILS | VALIDATE_GTLD_EMAILS:
case VALIDATE_ALL_EMAILS:
array_push($validate, 'cctld');
@@ -456,11 +457,51 @@
/**
* Debugging still, not implemented but code is somewhat here.
*/
- return true;
+ $self =& $this;
-
+ if (!is_a($this, 'Validate')) {
+ $self = new Validate;
+ }
+
+ $toValidate = array();
+
+ foreach ($validate as $valid) {
+ $tmpVar = '_' . (string)$valid;
+ $toValidate[$valid] = $this->{$tmpVar};
+ }
+
+
+ $e = $this->_executeFullEmailValidation($email, $toValidate);
+ return $e;
}
+
+ // {{{ protected function _executeFullEmailValidation
+ /**
+ * Execute the validation
+ *
+ * This function will execute the full email vs tld
+ * validation using an array of tlds passed to it.
+ *
+ * @access public
+ * @param string $email The email to validate.
+ * @param array $arrayOfTLDs The array of the TLDs to validate
+ * @return true or false (Depending on if it validates or if it does not)
+ */
+ function _executeFullEmailValidation($email, $arrayOfTLDs)
+ {
+ $emailEnding = explode('.', $email);
+ $emailEnding = $emailEnding[count($emailEnding)-1];
+
+ foreach ($arrayOfTLDs as $validator => $keys) {
+ if (in_array($emailEnding, $keys)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ // }}}
+
/**
* Validate an email
*
@@ -484,8 +525,6 @@
extract($options);
}
- /**
-
if (is_array($fullTLDValidation)) {
$valid = $this->_fullTLDValidation($email, $fullTLDValidation);
@@ -493,8 +532,6 @@
return false;
}
}
-
- */
// the base regexp for address
$regex = '&^(?: # recipient: