Created
October 26, 2013 22:45
-
-
Save appyaaron/7175465 to your computer and use it in GitHub Desktop.
Here is a quick and simple way to validate an email address in iOS.
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
//Place outside any other methods | |
- (BOOL)validateEmail:(NSString *)emailStr { | |
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | |
return [emailTest evaluateWithObject:emailStr]; | |
} | |
//Place where you wish to validate the email | |
if(![self validateEmail:[emailAddress text]]) { | |
//Didn't enter correct email value | |
} else { | |
//Did enter correct email value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment