根據三大運營商出現的號段(號段來自百度百科) 判斷是否是手機號 + (BOOL)isMobile:(NSString *)str { NSString *MOBILE = @"^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-35-8]|8[0-9]|9[189])\\d ...
根據三大運營商出現的號段(號段來自百度百科)
判斷是否是手機號
+ (BOOL)isMobile:(NSString *)str {
NSString *MOBILE = @"^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-35-8]|8[0-9]|9[189])\\d{8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
return [regextestmobile evaluateWithObject:str];
}
2、
//判斷移動
+ (BOOL)isChinaMobile:(NSString *)phoneNum{
NSString * CM = @"(^134[0-8]\\d{7}$)|(^1(3[5-9]|4[7]|5[0-27-9]|6[5]|7[28]|8[2-478]|9[8])\\d{8}$)|(^170[356]\\d{7})";
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
return [regextestcm evaluateWithObject:phoneNum];
}
//判斷聯通
+ (BOOL)isChinaUnicom:(NSString *)phoneNum{
NSString * CM = @"(^1(3[0-2]|4[5]|5[56]|6[67]|7[156]|8[56])\\d{8}$)|(^170[47-9]\\d{7}$)";
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
return [regextestcm evaluateWithObject:phoneNum];
}
//判斷電信
+ (BOOL)isChinaTelecom:(NSString *)phoneNum{
NSString * CM = @"(^1(3[3]|4[9]|5[3]|6[2]|7[37]|8[019]|9[19])\\d{8}$)|(^170[0-2]\\d{7}$)";
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
return [regextestcm evaluateWithObject:phoneNum];
}
//判斷運營商
+ (NSString *)getPhoneNumType:(NSString *)phoneNum{
return [self isChinaMobile:phoneNum]? @"中國移動": ([self isChinaUnicom:phoneNum]? @"中國聯通":([self isChinaTelecom:phoneNum]? @"中國電信": @"未知"));
}