Created
March 4, 2016 22:25
-
-
Save erikfloresq/dd42b1b18a6ed90136e7 to your computer and use it in GitHub Desktop.
Extended a String class for make function validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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