title: how to check the entered email is in email format
body: <p>How to check whether the entered email is in coorect form. Like somename@gmail.com or any.</p>
  
  <p>here my code.I tried but i am getting error in my if statement</p>
  
  <pre><code>import UIKit
  
  extension String {
      func matchPattern(patStr:String)-&gt;Bool {
          var isMatch:Bool = false
          do {
              let regex = try NSRegularExpression(pattern: patStr, options: [.CaseInsensitive])
              let result = regex.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, characters.count))
  
              if (result != nil)
              {
                  isMatch = true
              }
          }
          catch {
              isMatch = false
          }
          return isMatch
      }
  }
  
  class RegisterVC: UIViewController {
  
  
  
      @IBOutlet weak var EmailField: UITextField!
  
  
      @IBOutlet weak var LocationField: UITextField!
  
      @IBOutlet weak var userNameField: UITextField!
  
  
  
      @IBOutlet weak var passWordField: UITextField!
  
  
  
      @IBOutlet weak var confirmPasswordField: UITextField!
  override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
      }
  @IBAction func SignUpBtnPress(sender: AnyObject) {
          let Email:NSString = EmailField.text!
          let Location:NSString = LocationField.text!
          let username:NSString = userNameField.text!
          let password:NSString = passWordField.text!
          let confirm_password:NSString = confirmPasswordField.text!
  
          if (Email.matchPattern("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$")==true)
          {
              print("this is e-mail!")
          }
  
          else if ( Email.isEqualToString("") || Location.isEqualToString("") || username.isEqualToString("") || password.isEqualToString("") || confirm_password.isEqualToString("") ) {
  
  
              let alertController = UIAlertController(title: "Alert", message: "All Field Are Mnditory.", preferredStyle: UIAlertControllerStyle.Alert)
              let DestructiveAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -&gt; Void in
                  print("Settings")
              }
  
              alertController.addAction(DestructiveAction)
  
              self.presentViewController(alertController, animated: true, completion: nil)
  
  
  
          } else if ( !password.isEqual(confirm_password) ) {
  
              let alertController = UIAlertController(title: "Alert", message: "Password Din't Match.", preferredStyle: UIAlertControllerStyle.Alert)
              let DestructiveAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -&gt; Void in
                  print("Password Din't Match")
              }
  
              alertController.addAction(DestructiveAction)
  
              self.presentViewController(alertController, animated: true, completion: nil)
  
          }
  
  
  
  
          print("login sucess")
  }
  </code></pre>
  
  <p>what i need is, if any user start tying the email id is in wrong format, i need to show alert.</p>
  
  <p>Thanks</p>