title: Email validation swift 2
body: <p>how do I restrict users enter email address into the textfield.
  the problem is, my alert not shown, just signup without check the email field if valid or not </p>
  
  <pre><code>if ( username.isEmpty || email.isEmpty || password.isEmpty || phonenumper.isEmpty) {
  
      let alert = UIAlertController(title: "Sign Up Failed!", message:"Please enter your data for Signup", preferredStyle: .Alert)
      alert.addAction(UIAlertAction(title: "OK ", style: .Default) { _ in })
      self.presentViewController(alert, animated: true){}
  }
  
  else {
      if (isValidEmail(UserEmailTextFiled.text!)) {
          let alert = UIAlertController(title: "Inviled Email", message:"Please enter your Email", preferredStyle: .Alert)
          alert.addAction(UIAlertAction(title: "OK ", style: .Default) { _ in })
          self.presentViewController(alert, animated: true){}
  
      }else{
      //code
  
      }
  func isValidEmail(testStr:String) -&gt; Bool {
          let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
          let range = testStr.rangeOfString(emailRegEx, options:.RegularExpressionSearch)
          let result = range != nil ? true : false
          return result
      }
  </code></pre>