Reputation: 2848
I need to validate an email address which was in the format [email protected]
As I am new I dont know how to validate the email address.
Please suggest me how to get out of this.
Upvotes: 1
Views: 3045
Reputation: 3928
NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
if ([emailTest evaluateWithObject:userMailTextField.text] == YES)
{
//---- Code for action do you want
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Message" message:@"Email id is not in proper format" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
Upvotes: 1
Reputation: 13763
Same way you validate it in any language: examine the string directly, use a regex, etc.
Do some google searches on email validation first though. You'll find it's an area that's incredibly difficult to get right.
Upvotes: 1
Reputation: 2411
there you will find the answer :-) What are best practices for validating email addresses in Objective-C for iOS 2.0?
Upvotes: 2