Validate.php 916B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. /**
  9. * Utility Class allowing users to simply check expressions again Swift Grammar
  10. * @package Swift
  11. * @author Xavier De Cock <xdecock@gmail.com>
  12. */
  13. class Swift_Validate
  14. {
  15. /**
  16. * Grammar Object
  17. * @var Swift_Mime_Grammar
  18. */
  19. private static $grammar = null;
  20. /**
  21. * Checks if an email matches the current grammars
  22. * @param string $email
  23. */
  24. public static function email($email)
  25. {
  26. if (self::$grammar===null) {
  27. self::$grammar = Swift_DependencyContainer::getInstance()
  28. ->lookup('mime.grammar');
  29. }
  30. return preg_match(
  31. '/^' . self::$grammar->getDefinition('addr-spec') . '$/D',
  32. $email
  33. );
  34. }
  35. }