1. 判断是否为中国大陆手机号码
- (BOOL)isWellFormedChineseMobileNumber {
BOOL isWellFormed;
if (self.length == 11) {
NSString *ChinaMobile = @"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
NSString *ChinaUnicom = @"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
NSString *ChinaTelecom = @"^((133)|(153)|(177)|(18[0,1,9]))\\d{8}|(1700)\\d{7}$";
NSPredicate *ChinaMobileInspect = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", ChinaMobile];
NSPredicate *ChinaUnicomInspect = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", ChinaUnicom];
NSPredicate *ChinaTelecomInspect = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", ChinaTelecom];
if (([ChinaMobileInspect evaluateWithObject:self] == YES) || ([ChinaUnicomInspect evaluateWithObject:self] == YES) || ([ChinaTelecomInspect evaluateWithObject:self] == YES)) {
isWellFormed = YES;
} else {
isWellFormed = NO;
}
} else {
isWellFormed = NO;
}
return isWellFormed;
}
2. 判断是否为邮箱地址
- (BOOL)isWellFormedEmailAddress {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailAddressInspect = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailAddressInspect evaluateWithObject:self];
}