//手机号码
+ (BOOL)validateMobile:(NSString*)mobile{
NSString *MOBILE = @"^1(3[0-9]|4[56789]|5[0-9]|6[2567]|7[0-9]|8[0-9]|9[189])\\d{8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
return[regextestmobile evaluateWithObject:mobile];
}
/**
判断运营商
各个运营商开头号码不同 需要根据运营商更新
@return 正则验证成功返回YES, 否则返回NO
*/
+(BOOL)isMobileNumberClassification:(NSString *)mobile{
// 中国联通号码格式验证 手机段: 130,131,132,145,146,155,156,166,175,176,185,186,1704,1707,1708,1709,171
NSString * CU = "(^1(3[0-2]|4[56]|5[56]|6[6]|7[156]|8[56])\\d{8}$)|(^1704\\d{7}$)|(^1707\\d{7}$)|(^1708\\d{7}$)|(^1709\\d{7}$)";
// 中国移动号段 134(0-8),135,136,137,138,139,147,148,150,151,152,157,158,159,165,178,182,183,184,187,188,198 ,1703,1705,1706
NSString * CM = "(^1(3[4-9]|4[78]|5[0-27-9]|6[6]|7[8]|8[2-478]|9[8])\\d{8}$)|(^1705\\d{7}$)";
//中国电信号段 133,149,153,173,174,177,180,181,189,199,191,1700,1701,1702
NSString * CT = "(^1(3[3]|4[9]|5[3]|7[347]|8[019]|9[19])\\d{8}$)|(^1700\\d{7}$)|(^1701\\d{7}$)|(^1702\\d{7}$)";
NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
if([regextestcu evaluateWithObject:mobile]) {
NSLog(@"手机运营商是====CU---中国联通");
returnYES;
}elseif([regextestcm evaluateWithObject:mobile]){
NSLog(@"手机运营商是====CM---中国移动");
}elseif([regextestct evaluateWithObject:mobile]){
NSLog(@"手机运营商是====CT---中国电信");
}else{
returnNO;
}
}