title: TextField either phone number or Email format validation swift?
body: <p>I having one text field for forgot password ,here user enter either mobile number or email then we send OTP to that.</p>
  
  <p>I am trying to validations for that text field with my code but it is not working, any one give some idea on that please find my code with following.</p>
  
  <p>It needs to valid for either mailid or Phone number format.</p>
  
  <pre><code>if emaiTF.text == "" {
              print("Enter either valid phone or email")
          }else if let validphone = emaiTF.text, validphone.isValidPhone() || validphone.isValidEmail() {
              print("Enter either valid phone or email")
          }else{
              forGotPasswordApi()
          }
  </code></pre>
  
  <p>my validation methods like following.</p>
  
  <pre><code>extension String {
      func isValidEmail() -&gt; Bool {
          // here, `try!` will always succeed because the pattern is valid
          let regex = try! NSRegularExpression(pattern: "^[a-zA-Z0-9.!#$%&amp;'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$", options: .caseInsensitive)
          return regex.firstMatch(in: self, options: [], range: NSRange(location: 0, length: count)) != nil
      }
  
      // vrify Valid PhoneNumber or Not
      func isValidPhone() -&gt; Bool {
  
          let phoneRegex = "^[0-9]{10}$";
          let valid = NSPredicate(format: "SELF MATCHES %@", phoneRegex).evaluate(with: phoneRegex)
          return valid
      }
  }
  </code></pre>