标签:
//移动号段
static Pattern p1 = Pattern.compile("^((13[4-9])|(15[0-2,7-9])|(18[2-4,7-8]|14[5,7])|178)\\d{8}$");
static Pattern p2 = Pattern.compile("^(1705)\\d{7}$");
//联通号段
static Pattern p3 = Pattern.compile("^((13[0-2])|(15[5,6])|(18[5,6])|176)\\d{8}$");
static Pattern p4 = Pattern.compile("^(1709)\\d{7}$");
//电信号段
static Pattern p5 = Pattern.compile("^(133|153|(18[0-1,9])|177)\\d{8}$");
static Pattern p6 = Pattern.compile("^(1700)\\d{7}$");
//所有号段
public static Pattern allPhoneNumberPattern=Pattern.compile("[1](3[0-9]|4[57]|5[012356789]|8[0-9])[0-9]{8}");
public static Pattern PhoneNumberFor170Pattern=Pattern.compile("[1](7[0][059]|7[678][0-9])[0-9]{7}");
public static String replaceAllPattern = "([0-7]|[9])([0-5]|[7-9])\\d{11,}";
public static Pattern phoneNumberForLinePattern=Pattern.compile("[1](3[0-9]|4[57]|5[012356789]|8[0-9])[0-9]{8}");
public static Pattern phoneNumberFor86LinePattern=Pattern.compile("^\\+86[1](3[0-9]|4[57]|5[012356789]|8[0-9])[0-9]{8}$");
public static Pattern phoneNumberFor170LinePattern=Pattern.compile("[1](7[0][059]|7[678][0-9])[0-9]{7}");
public static Pattern phoneNumberFor86170LinePattern=Pattern.compile("^\\+86[1](7[0][059]|7[678][0-9])[0-9]{7}$");
/**
* 方法描述
* 是否为移动号段
* 134、135、136、137、138、139、150、151、152、157(TD专属号段)、158、159;182、183、184、187、188、1705、145、147
* @param phone
* @return
*/
public static boolean isMobile(String phone){
Matcher m1 = p1.matcher(phone);
Matcher m2 = p2.matcher(phone);
if(m1.matches() || m2.matches()){
return true;
}
return false;
}
/**
* 方法描述
* 是否为联通号段
* 130、131、132、155、156、185、186、1709
* @param phone
* @return
*/
public static boolean isTelecom(String phone){
Matcher m1 = p3.matcher(phone);
Matcher m2 = p4.matcher(phone);
if(m1.matches() || m2.matches()){
return true;
}
return false;
}
/**
* 方法描述
* 是否为电信号段
* 133、153、180、181、189、1700
* @param phone
* @return
*/
public static boolean isUnicom(String phone){
Matcher m1 = p5.matcher(phone);
Matcher m2 = p6.matcher(phone);
if(m1.matches() || m2.matches()){
return true;
}
return false;
}
public static void main(String[] args) {
System.out.println(isTelecom("13412345678"));
System.out.println(isTelecom("13052345678"));
System.out.println(isTelecom("18612345678"));
System.out.println(isTelecom("18412345678"));
System.out.println(isUnicom("13312345678"));
System.out.println(isUnicom("13412345678"));
System.out.println(isUnicom("18112345678"));
System.out.println(isUnicom("18912345678"));
}
标签:
原文地址:http://www.cnblogs.com/zhaojinhui/p/4964496.html