Created
August 6, 2015 08:47
-
-
Save tombuildsstuff/2e44278ed46ff14f3515 to your computer and use it in GitHub Desktop.
Phone number validation
This file contains 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
static func isValidTelephone(value: String) -> Bool { | |
if let detector = NSDataDetector(types: NSTextCheckingType.PhoneNumber.rawValue, error: nil) { | |
let range = NSRange(location: 0, length: NSString(string: value).length); | |
let matches = detector.matchesInString(value, options: NSMatchingOptions.allZeros, range: range); | |
for match in matches { | |
if let matchType = match as? NSTextCheckingResult { | |
if matchType.resultType == NSTextCheckingType.PhoneNumber { | |
return true; | |
} | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment