本篇文章为大家展示了使用正则表达式怎么实现手机号中间4位数隐藏,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
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();
}
上述内容就是使用正则表达式怎么实现手机号中间4位数隐藏,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注天达云行业资讯频道。