home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / QuickForm / Rule / Email.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.8 KB  |  73 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Email validation rule
  6.  * 
  7.  * PHP versions 4 and 5
  8.  *
  9.  * LICENSE: This source file is subject to version 3.01 of the PHP license
  10.  * that is available through the world-wide-web at the following URI:
  11.  * http://www.php.net/license/3_01.txt If you did not receive a copy of
  12.  * the PHP License and are unable to obtain it through the web, please
  13.  * send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category    HTML
  16.  * @package     HTML_QuickForm
  17.  * @author      Bertrand Mansion <bmansion@mamasam.com>
  18.  * @copyright   2001-2007 The PHP Group
  19.  * @license     http://www.php.net/license/3_01.txt PHP License 3.01
  20.  * @version     CVS: $Id: Email.php,v 1.6 2007/06/03 13:47:06 avb Exp $
  21.  * @link        http://pear.php.net/package/HTML_QuickForm
  22.  */
  23.  
  24. /**
  25.  * Abstract base class for QuickForm validation rules 
  26.  */
  27. require_once 'HTML/QuickForm/Rule.php';
  28.  
  29. /**
  30.  * Email validation rule
  31.  *
  32.  * @category    HTML
  33.  * @package     HTML_QuickForm
  34.  * @author      Bertrand Mansion <bmansion@mamasam.com>
  35.  * @version     Release: 3.2.10
  36.  * @since       3.2
  37.  */
  38. class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
  39. {
  40.     var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
  41.  
  42.     /**
  43.      * Validates an email address
  44.      *
  45.      * @param     string    $email          Email address
  46.      * @param     boolean   $checkDomain    True if dns check should be performed
  47.      * @access    public
  48.      * @return    boolean   true if email is valid
  49.      */
  50.     function validate($email, $checkDomain = false)
  51.     {
  52.         // Fix for bug #10799: add 'D' modifier to regex
  53.         if (preg_match($this->regex . 'D', $email)) {
  54.             if ($checkDomain && function_exists('checkdnsrr')) {
  55.                 $tokens = explode('@', $email);
  56.                 if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
  57.                     return true;
  58.                 }
  59.                 return false;
  60.             }
  61.             return true;
  62.         }
  63.         return false;
  64.     } // end func validate
  65.  
  66.  
  67.     function getValidationScript($options = null)
  68.     {
  69.         return array("  var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
  70.     } // end func getValidationScript
  71.  
  72. } // end class HTML_QuickForm_Rule_Email
  73. ?>