截取手机号码的方法很简单:
//截取手机号码 方法一String phonenum = "15718807588";if(!TextUtils.isEmpty(phonenum) && phonenum.length() > 6 ){StringBuilder sb =new StringBuilder();for (int i = 0; i < phonenum.length(); i++) {char c = phonenum.charAt(i);if (i >= 3 && i <= 6) {sb.append('*');} else {sb.append(c);}}ToastUtil.showImgMessage(context,sb.toString()+"1");}
//方法二phonenum = phonenum.substring(0, 3) + "****" + phonenum.substring(7, 11);ToastUtil.showImgMessage(context,phonenum+"2");
//方法三:用****替换手机号码中间4位
String mobile = "15718807588";
String maskNumber = mobile.substring(0,3)+"****"+mobile.substring(7,mobile.length());
/*** 检查是否是电话号码* * @return*/public static boolean isMobileNum(String mobiles) {Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");Matcher m = p.matcher(mobiles);return m.matches();}