2018年最新电话号码正则表达式校验方法

版权声明:转载请注明出处:http://blog.csdn.net/kevindongkun https://blog.csdn.net/Kevindongkun/article/details/81334816

正则表达式

^1(3[0-9]|4[57]|5[^4]|6[6]|7[0-8]|8[0-9]|9[8-9])\\d{8}$

iOS使用方法

+ (BOOL)checkPhoneNumber:(NSString *)phoneNumber{
    /*
     ** 电信号段:133/153/180/181/189/177
     ** 联通号段:130/131/132/155/156/185/186/145/176
     ** 移动号段: 134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
     ** 虚拟运营商:170
     */
    NSString *MOBILE = @"^1(3[0-9]|4[57]|5[^4]|6[6]|7[0-8]|8[0-9]|9[8-9])\\d{8}$";
     NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
  return  [regextestmobile evaluateWithObject:phoneNumber];
}

Android使用方法:

public static boolean isMobileNO(String mobileNums) {
    /*
     ** 电信号段:133/153/180/181/189/177
     ** 联通号段:130/131/132/155/156/185/186/145/176
     ** 移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/149/178
     ** 虚拟运营商:170
     */
    String telRegex = "^((13[0-9])|(14[5,7])|(15[^4,\\D])|(166)|(17[0-8])|(18[^4,\\D])|(199)|(198))\\d{8}$";
    if (TextUtils.isEmpty(mobileNums))
        return false;
    else
        return mobileNums.matches(telRegex);
}

java使用方法:

public static boolean isMobileNO(String mobiles) {  
    boolean flag = false;  
    try {  
        Pattern p = Pattern  
                .compile("^((13[0-9])|(14[5,7])|(15[^4,\\D])|(166)|(17[0-8])|(18[^4,\\D])|(199)|(198))\\d{8}$");  
        Matcher m = p.matcher(mobiles);  
        flag = m.matches();  
    } catch (Exception e) {  
        flag = false;  
    }  
    return flag;  
} 

猜你喜欢

转载自blog.csdn.net/Kevindongkun/article/details/81334816