Skip to content

Instantly share code, notes, and snippets.

@saru2020
Created May 21, 2019 14:21
Show Gist options
  • Select an option

  • Save saru2020/cb934031c04d8a9265dff63cc79f761a to your computer and use it in GitHub Desktop.

Select an option

Save saru2020/cb934031c04d8a9265dff63cc79f761a to your computer and use it in GitHub Desktop.
extension String {
/// Used to validate if the given string is valid email or not
///
/// - Returns: Boolean indicating if the string is valid email or not
func isValidEmail() -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
print("emailTest.evaluate(with: self): \(emailTest.evaluate(with: self))")
return emailTest.evaluate(with: self)
}
/// Used to validate if the given string matches the password requirements
///
/// - Returns: Boolean indicating the comparison result
func isValidPassword() -> Bool {
print("self.count >= 6: \(self.count >= 6)")
return self.count >= 6
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment