2010-08-10 57 views
1

我需要验证一个电子邮件地址的格式是dsfdsf @ .fdsf.com如何验证Iphone SDK中的电子邮件ID?

由于我是新的,我不知道如何验证电子邮件地址。

请建议我如何摆脱这一点。

+0

可能重复的[验证电子邮件地址的最佳实践](http://stackoverflow.com/questions/800123/best-practice-for-validating-email-address) – 2010-08-10 19:57:09

回答

1

相同的方式,验证它在任何语言的答案:直接检查字符串,使用正则表达式等

请在电子邮件验证一些谷歌搜索首先虽然。你会发现这是一个难以想象的领域。

1
NSString *emailRegEx = @"[A-Z0-9a-z._%+-][email protected][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]; 
}