Wednesday, July 4, 2012

Symfony Email Validator Accepts Accents

Use this validator to ignore accents:

  1. Put this after sfCoreAutoload::register(); in config/ProjectConfiguration.class.php:
    require_once dirname(__FILE__).'/../lib/validator/sfValidatorEmail.class.php';
  2. Create lib/validator/sfValidatorEmail.class.php with this content:
class sfValidatorEmail extends sfValidatorRegex
{
   // const REGEX_EMAIL = '/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i';
  // const REGEX_EMAIL = '/^([^@öüóőúéáűíÖÜÓŐÚÉÁŰÍ\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i';
  
  const REGEX_EMAIL = '/^([A-Z0-9._%+-]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i';
  /**
   * @see sfValidatorRegex
   */
  protected function configure($options = array(), $messages = array())
  {
    parent::configure($options, $messages);
    $this->setOption('pattern', self::REGEX_EMAIL);
  }
}

No comments:

Post a Comment