PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/community/PEAR/HTML/QuickForm/Rule/Email.php

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