SimpleCheck.php 639 B

123456789101112131415161718192021
  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. public function validate($string, $config, $context) {
  9. // no support for named mailboxes i.e. "Bob <bob@example.com>"
  10. // that needs more percent encoding to be done
  11. if ($string == '') return false;
  12. $string = trim($string);
  13. $result = preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $string);
  14. return $result ? $string : false;
  15. }
  16. }
  17. // vim: et sw=4 sts=4