手机号/身份证加星处理

目录

java

public class Test {  
    public static void main(String[] args) {  
        String phone = "18771632488";  
        System.out.println(phone.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"));  //11位 187****8976

        String idCard = "421302199208165464";  
        System.out.println(idCard.replaceAll("(\\d{4})\\d{10}(\\d{4})","$1****$2")); //18位 4107**********9807  只适用于纯数字不带字母
    }  
}  

javaScript

phone.substr(0, 3) + '****' + phone.substr(7);

cardNo = cardNo.substring(0, 6) + "********" + cardNo.substring(14, 18);

猜你喜欢

转载自www.cnblogs.com/xiaoyinger/p/12159630.html