0
点赞
收藏
分享

微信扫一扫

需求: java返回模糊后的手机号码

彪悍的鼹鼠 2022-01-08 阅读 72

1.测试代码

public class StringUtil {

    public static String blurPhoneNumber(String phoneNumber) throws Exception{
        if (!(phoneNumber instanceof String) || phoneNumber.length()!= 11) {
            throw new Exception("传入的号码不规范");
        }
        StringBuilder str = new StringBuilder(phoneNumber.substring(0, 3));
        str.append("****");
        str.append(phoneNumber.substring(7));
        System.out.println(str);
        return str.toString();
    }

    public static void main(String[] args) throws Exception {
        StringUtil.blurPhoneNumber("13600000000"); //136****0000
    }
}

2.模糊后的手机号码

 

举报

相关推荐

0 条评论