根据三大运营商出现的号段(号段来自百度百科)

判断是否是手机号

+ (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]? @"中国电信": @"未知"));

}

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/guozhihe/p/12923555.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!