Skip to content

Instantly share code, notes, and snippets.

@erikfloresq
Created March 4, 2016 22:25
Show Gist options
  • Save erikfloresq/dd42b1b18a6ed90136e7 to your computer and use it in GitHub Desktop.
Save erikfloresq/dd42b1b18a6ed90136e7 to your computer and use it in GitHub Desktop.
Extended a String class for make function validation
extension String {
func isEmail() -> Bool {
let regex = try! NSRegularExpression(pattern: "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$", options: [.CaseInsensitive])
return regex.firstMatchInString(self, options:[], range: NSMakeRange(0, utf16.count)) != nil
}
func isDni() -> Bool {
let regex = try! NSRegularExpression(pattern: "^[0-9]{8}$", options: [.CaseInsensitive])
return regex.firstMatchInString(self, options:[], range: NSMakeRange(0, utf16.count)) != nil
}
func isPassword() -> Bool {
let regex = try! NSRegularExpression(pattern: "^[0-9]{6}$", options: [.CaseInsensitive])
return regex.firstMatchInString(self, options: [], range: NSMakeRange(0, utf16.count)) != nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment