标签:des http ar io os sp for strong on
IOS开发中怎样验证邮箱的合法性
文章参考:http://www.codes51.com/article/detail_94157.html
代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"验证邮箱的合法性"; NSString *email=@"123456@codes51.com"; NSLog(@"--%i-",[self isValidateEmail:email]); }
//用正则表达式 -(BOOL)isValidateEmail:(NSString *)email { 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:email]; }
输出:
2014-11-17 14:29:54.704 验证邮箱的合法性[29052:60b] --1-
标签:des http ar io os sp for strong on
原文地址:http://www.cnblogs.com/superken/p/4169152.html