文章参考:http://www.codes51.com/article/detail_94157.html
代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [email protected]"验证邮箱的合法性"; NSString *[email protected]"[email protected]"; NSLog(@"--%i-",[self isValidateEmail:email]); }
//用正则表达式 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][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-
时间: 2024-10-10 08:17:17