我创建了以下正则表达式来验证我的电子邮件
- (BOOL)isValidEmail
{
BOOL stricterFilter = YES;
NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:self];
}
但是当我输入以下内容时它失败了:
b. !@#$%^ bfv@mn.cn
我的正则表达式有问题吗?
答案 0 :(得分:0)
试试这个。这对我来说非常适合。
NSString *mailreg=@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *mailtest=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",mailreg];
return [mailtest evaluateWithObject:checkString];