Skip to content

Instantly share code, notes, and snippets.

@Arrlindii
Created August 5, 2018 22:58
Show Gist options
  • Select an option

  • Save Arrlindii/843deed64ad37fe6d4555460bc051276 to your computer and use it in GitHub Desktop.

Select an option

Save Arrlindii/843deed64ad37fe6d4555460bc051276 to your computer and use it in GitHub Desktop.
func validatedEmail(_ value: String) throws -> String {
do {
if try NSRegularExpression(pattern: "^[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$", options: .caseInsensitive).firstMatch(in: value, options: [], range: NSRange(location: 0, length: value.count)) == nil {
throw ValidationError("Invalid e-mail Address")
}
} catch {
throw ValidationError("Invalid e-mail Address")
}
return value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment