title: How to validate an email address in a Controller in Symfony 3.x
body: <p>I have integrated in my Symfony project the FOSUserBundle with the HWIOAUTHBundle. I have a facebook and a google login/registration next to the simple login form from FOSUserBundle. However, Facebook doesn't necessarily give me an email back, since it's not needed for a Facebook account (i.e when the user registers on Facebook via phone). In this case, when the user registers I set her/his email address to be the same as the facebook/google ID (because I can't leave email field empty). </p>
  
  <p>When somebody on my website orders an item, I need to send him an email containing a QR code that she/he will use to authenticate himself, thus I need a way to get a real e-mail address from the user.</p>
  
  <p>I have thought that when the user registers via Facebook and tries to purchase a product I'd redirect her/him to the profile edit page, show a notification that he/she should provide a correct email address and then she/he can move on with the purchase.</p>
  
  <p>However, I need to validate if their current email is a real (or at least real-looking) email address in the controller that handles the purchases.</p>
  
  <p>How can I use Symfony's validator in a controller to check if the user's email from <code>$user = $this-&gt;get('security.token_storage')-&gt;getToken()-&gt;getUser(); $user-&gt;getEmail();</code> really looks like an email?</p>
  
  <p>For now this is what I have:</p>
  
  <pre><code>if (!$this-&gt;get('security.authorization_checker')-&gt;isGranted('IS_AUTHENTICATED_FULLY')) {
      throw $this-&gt;createAccessDeniedException('some message');
  }
  
  $user = $this-&gt;get('security.token_storage')-&gt;getToken()-&gt;getUser();
  
  if ($user-&gt;isEnabled() == false) {
      throw $this-&gt;createAccessDeniedException('some message');
  }
  
  if (null == $user-&gt;getEmail() || $user-&gt;getFacebookId() == $user-&gt;getEmail() || $user-&gt;getGoogleId() === $user-&gt;getEmail()) {
      $session = new Session();
      $session-&gt;getFlashBag()-&gt;add('warning', 'Please provide a real email address, yata yata, etc.');
      return $this-&gt;redirectToRoute('fos_user_profile_edit');
  }
  </code></pre>
  
  <p>Thanks in advance!</p>