1.隐藏手机号码中间四位,变成186****9877
/**
* 隐藏部分手机号码
* @param phone
* @return
*/
public static String hidePhoneNum(String phone){
String result = "";
if (phone != null && !"".equals(phone)) {
if (isMobileNum(phone)) {
result = phone.substring(0, 3) + "****" + phone.substring(7);
}
}
return result;
}
2.判断是否是手机号码
/**
* 检查是否是电话号码
*
* @return
*/
public static boolean isMobileNum(String mobiles) {
Pattern p = Pattern
.compile("^((13[0-9])|(14[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}