Validate.php 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. *
  11. * @author Xavier De Cock <xdecock@gmail.com>
  12. */
  13. class Swift_Validate
  14. {
  15. /**
  16. * Grammar Object
  17. *
  18. * @var Swift_Mime_Grammar
  19. */
  20. private static $grammar = null;
  21. /**
  22. * Checks if an e-mail address matches the current grammars.
  23. *
  24. * @param string $email
  25. *
  26. * @return bool
  27. */
  28. public static function email($email)
  29. {
  30. if (self::$grammar===null) {
  31. self::$grammar = Swift_DependencyContainer::getInstance()
  32. ->lookup('mime.grammar');
  33. }
  34. return (bool) preg_match(
  35. '/^' . self::$grammar->getDefinition('addr-spec') . '$/D',
  36. $email
  37. );
  38. }
  39. }