android 将手机号中间隐藏为星号(*)和手机号码判断

来源:互联网 发布:深圳网站建设方维网络 编辑:程序博客网 时间:2024/05/23 14:03


  截取手机号码的方法很简单:


  //截取手机号码 方法一                                        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();    }


阅读全文
0 0
原创粉丝点击