SimpleCheck.php 824 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Primitive email validation class based on the regexp found at
  4. * http://www.regular-expressions.info/email.html
  5. */
  6. class HTMLPurifier_AttrDef_URI_Email_SimpleCheck extends HTMLPurifier_AttrDef_URI_Email
  7. {
  8. /**
  9. * @param string $string
  10. * @param HTMLPurifier_Config $config
  11. * @param HTMLPurifier_Context $context
  12. * @return bool|string
  13. */
  14. public function validate($string, $config, $context)
  15. {
  16. // no support for named mailboxes i.e. "Bob <bob@example.com>"
  17. // that needs more percent encoding to be done
  18. if ($string == '') {
  19. return false;
  20. }
  21. $string = trim($string);
  22. $result = preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $string);
  23. return $result ? $string : false;
  24. }
  25. }
  26. // vim: et sw=4 sts=4