Skip to content

Instantly share code, notes, and snippets.

@tombuildsstuff
Created August 6, 2015 08:47
Show Gist options
  • Save tombuildsstuff/2e44278ed46ff14f3515 to your computer and use it in GitHub Desktop.
Save tombuildsstuff/2e44278ed46ff14f3515 to your computer and use it in GitHub Desktop.
Phone number validation
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