cvs: pear /Validate Validate.php
| From: | David Coallier | Date: | Thu, 01 Mar 2007 22:11:01 +0000 |
| Subject: | cvs: pear /Validate Validate.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44929@lists.php.net to get a copy of this message | ||
davidc Thu Mar 1 22:11:01 2007 UTC
Modified files:
/pear/Validate Validate.php
Log:
Added development begin for bug 10044 but not used yet, however in place so I can work for remote
locations.
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate.php?r1=1.107&r2=1.108&diff_format=u
Index: pear/Validate/Validate.php
diff -u pear/Validate/Validate.php:1.107 pear/Validate/Validate.php:1.108
--- pear/Validate/Validate.php:1.107 Tue Jan 9 20:26:00 2007
+++ pear/Validate/Validate.php Thu Mar 1 22:11:01 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.107 2007/01/09 20:26:00 arpad Exp $
+ * @version CVS: $Id: Validate.php,v 1.108 2007/03/01 22:11:01 davidc Exp $
* @link http://pear.php.net/package/Validate
*/
@@ -53,6 +53,11 @@
define('VALIDATE_NAME', VALIDATE_EALPHA . VALIDATE_SPACE . "'" .
"-");
define('VALIDATE_STREET', VALIDATE_NUM . VALIDATE_NAME . "/\\ºª\.");
+define('VALIDATE_ITLD_EMAILS', 1);
+define('VALIDATE_GTLD_EMAILS', 2);
+define('VALIDATE_CCTLD_EMAILS', 4);
+define('VALIDATE_ALL_EMAILS', 8);
+
/**
* Validation class
*
@@ -77,6 +82,131 @@
class Validate
{
/**
+ * International Top-Level Domain
+ *
+ * This is an array of the known international
+ * top-level domain names.
+ *
+ * @access protected
+ * @var array $_iTld (International top-level domains)
+ */
+ var $_iTld = array(
+ 'arpa',
+ 'root',
+ );
+
+ /**
+ * Generic top-level domain
+ *
+ * This is an array of the official
+ * generic top-level domains.
+ *
+ * @access protected
+ * @var array $_gTld (Generic top-level domains)
+ */
+ var $_gTld = array(
+ 'aero',
+ 'biz',
+ 'cat',
+ 'com',
+ 'coop',
+ 'edu',
+ 'gov',
+ 'info',
+ 'int',
+ 'jobs',
+ 'mil',
+ 'mobi',
+ 'museum',
+ 'name',
+ 'net',
+ 'org',
+ 'pro',
+ 'travel',
+ 'asia',
+ 'post',
+ 'tel',
+ 'geo',
+ );
+
+ /**
+ * Country code top-level domains
+ *
+ * This is an array of the official country
+ * codes top-level domains
+ *
+ * @access protected
+ * @var array $_ccTld (Country Code Top-Level Domain)
+ */
+ var $_ccTld = array(
+ 'ac',
+ 'ad','ae','af','ag',
+ 'ai','al','am','an',
+ 'ao','aq','ar','as',
+ 'at','au','aw','ax',
+ 'az','ba','bb','bd',
+ 'be','bf','bg','bh',
+ 'bi','bj','bm','bn',
+ 'bo','br','bs','bt',
+ 'bu','bv','bw','by',
+ 'bz','ca','cc','cd',
+ 'cf','cg','ch','ci',
+ 'ck','cl','cm','cn',
+ 'co','cr','cs','cu',
+ 'cv','cx','cy','cz',
+ 'de','dj','dk','dm',
+ 'do','dz','ec','ee',
+ 'eg','eh','er','es',
+ 'et','eu','fi','fj',
+ 'fk','fm','fo','fr',
+ 'ga','gb','gd','ge',
+ 'gf','gg','gh','gi',
+ 'gl','gm','gn','gp',
+ 'gq','gr','gs','gt',
+ 'gu','gw','gy','hk',
+ 'hm','hn','hr','ht',
+ 'hu','id','ie','il',
+ 'im','in','io','iq',
+ 'ir','is','it','je',
+ 'jm','jo','jp','ke',
+ 'kg','kh','ki','km',
+ 'kn','kp','kr','kw',
+ 'ky','kz','la','lb',
+ 'lc','li','lk','lr',
+ 'ls','lt','lu','lv',
+ 'ly','ma','mc','md',
+ 'me','mg','mh','mk',
+ 'ml','mm','mn','mo',
+ 'mp','mq','mr','ms',
+ 'mt','mu','mv','mw',
+ 'mx','my','mz','na',
+ 'nc','ne','nf','ng',
+ 'ni','nl','no','np',
+ 'nr','nu','nz','om',
+ 'pa','pe','pf','pg',
+ 'ph','pk','pl','pm',
+ 'pn','pr','ps','pt',
+ 'pw','py','qa','re',
+ 'ro','rs','ru','rw',
+ 'sa','sb','sc','sd',
+ 'se','sg','sh','si',
+ 'sj','sk','sl','sm',
+ 'sn','so','sr','st',
+ 'su','sv','sy','sz',
+ 'tc','td','tf','tg',
+ 'th','tj','tk','tl',
+ 'tm','tn','to','tp',
+ 'tr','tt','tv','tw',
+ 'tz','ua','ug','uk',
+ 'us','uy','uz','va',
+ 'vc','ve','vg','vi',
+ 'vn','vu','wf','ws',
+ 'ye','yt','yu','za',
+ 'zm','zw',
+ );
+
+
+ /**
* Validate a number
*
* @param string $number Number to validate
@@ -263,6 +393,75 @@
}
/**
+ * Full TLD Validation function
+ *
+ * This function is used to make a much more proficient validation
+ * against all types of official domain names.
+ *
+ * @access protected
+ * @param string $email The email address to check.
+ * @param array $options The options for validation
+ * @return bool True if validating succeeds
+ */
+ function _fullTLDValidation($email, $options)
+ {
+ if (!is_array($options)) {
+ return false;
+ }
+
+ $validate = array();
+
+ switch ($options['tld']) {
+ /** 1 */
+ case VALIDATE_ITLD_EMAILS:
+ array_push($validate, 'itld');
+ break;
+
+ /** 2 */
+ case VALIDATE_GTLD_EMAILS:
+ array_push($validate, 'gtld');
+ break;
+
+ /** 3 */
+ case VALIDATE_ITLD_EMAILS | VALIDATE_GTLD_EMAILS:
+ array_push($validate, 'itld');
+ array_push($validate, 'gtld');
+ break;
+
+ /** 4 */
+ case VALIDATE_CCTLD_EMAILS:
+ array_push($validate, 'cctld');
+ break;
+
+ /** 5 */
+ case VALIDATE_CCTLD_EMAILS | VALIDATE_ITLD_EMAILS:
+ array_push($validate, 'cctld');
+ array_push($validate, 'itld');
+ break;
+
+ /** 6 */
+ case VALIDATE_CCTLD_EMAILS ^ VALIDATE_ITLD_EMAILS:
+ array_push($validate, 'cctld');
+ array_push($validate, 'itld');
+ break;
+
+ case VALIDATE_CCTLD_EMAILS | VALIDATE_ITLD_EMAILS | VALIDATE_GTLD_EMAILS:
+ case VALIDATE_ALL_EMAILS:
+ array_push($validate, 'cctld');
+ array_push($validate, 'itld');
+ array_push($validate, 'gtld');
+ break;
+ }
+
+ /**
+ * Debugging still, not implemented but code is somewhat here.
+ */
+ return true;
+
+
+ }
+
+ /**
* Validate an email
*
* @param string $email email to validate
@@ -285,6 +484,18 @@
extract($options);
}
+ /**
+
+ if (is_array($fullTLDValidation)) {
+ $valid = $this->_fullTLDValidation($email, $fullTLDValidation);
+
+ if (!$valid) {
+ return false;
+ }
+ }
+
+ */
+
// the base regexp for address
$regex = '&^(?: # recipient:
("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+")| #1 quoted name