There is an email validator in symfony that can be used in a form: http://symfony.com/doc/current/reference/constraints/Email.html
My question is: How can I use this val
I wrote a post about validating email address(es) (one or many) outside of forms
http://konradpodgorski.com/blog/2013/10/29/how-to-validate-emails-outside-of-form-with-symfony-validator-component/
It also covers a common bug where you validate against Email Constraint and forget about NotBlank
/**
* Validates a single email address (or an array of email addresses)
*
* @param array|string $emails
*
* @return array
*/
public function validateEmails($emails){
$errors = array();
$emails = is_array($emails) ? $emails : array($emails);
$validator = $this->container->get('validator');
$constraints = array(
new \Symfony\Component\Validator\Constraints\Email(),
new \Symfony\Component\Validator\Constraints\NotBlank()
);
foreach ($emails as $email) {
$error = $validator->validateValue($email, $constraints);
if (count($error) > 0) {
$errors[] = $error;
}
}
return $errors;
}
I hope this helps