设置隐藏手机号码

2019-08-06  本文已影响0人  清风兑酒

//151 1111 1111 -> 151 **** 1111

private String dealPhoneNumber(String phoneNumber) {
        if (StringUtil.isNotEmpty(phoneNumber)) {
            int len = phoneNumber.length();
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < len; i++) {
                if (i > 2 && i < 7) {
                    builder.append("*");
                } else {
                    builder.append(phoneNumber.charAt(i));
                }

                if (i == 2 || i == 6) {
                    if (i != len - 1)
                        builder.append(" ");
                }
            }

            return builder.toString();
        }
        return null;
    }
上一篇下一篇

猜你喜欢

热点阅读