Skip to content

Instantly share code, notes, and snippets.

@cmlenz
cmlenz / gist:8ef4ebdab696fc24335e
Created May 5, 2014 12:25
Using the data detector API for email validation. Still probably uses regular expression under the covers (NSDataDetector is a NSRegularExpression subclass), but at least uses a system method instead of a hand-coded regex pattern.
- (BOOL)isValidEmailAddress:(NSString *)text
{
NSError *error = NULL;
NSRange textRange = {0, [text length]};
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
if (!detector) {
NSLog(@"Could not instantiate link detector for email validation: %@", error);
return NO;
}