手机号运营商判断

2021-03-16  本文已影响0人  笨小孩_8bf3

判断是否是手机号

- (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];

}

//判断移动

- (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 = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", CM];

    return[regextestcmevaluateWithObject: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 = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", CM];

    return[regextestcmevaluateWithObject: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 = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", CM];

    return[regextestcmevaluateWithObject:phoneNum];

}

//判断运营商

- (NSString*)getPhoneNumType:(NSString*)phoneNum{

    return[selfisChinaMobile:phoneNum]?@"中国移动": ([selfisChinaUnicom:phoneNum]?@"中国联通":([selfisChinaTelecom:phoneNum]?@"中国电信":@"未知"));

}

上一篇下一篇

猜你喜欢

热点阅读