身份证号、手机号脱敏展示以及苹果手机手机兼容性问题

 

var identifynumber = "513436200003276211";   //身份证号
identifynumber = identifynumber.replace(/(?<=\d{3})\d{12}(?=\d{2}[0-9A-Z]{1})/, "************");
console.log(identifynumber); // 513************211

var phoneNum = "18620792644";  //手机号
phoneNum = phoneNum.replace(/(?<=\d{3})\d{4}(?=\d{4})/, "****");
console.log(phoneNum);  //186****2644

  replace正则表达式替换方法,苹果手机不兼容。使用substring()截取的方式

var identifynumber = "513436200003276211";   //身份证号
identifynumber = identifynumber.substring(0,3) + "************"+identifynumber.substring(15,18);
console.log(identifynumber); // 513************211

var phoneNum = "18620792644";  //手机号
phoneNum = phoneNum.substring(0,3)+ "****" + phoneNum.substring(8,11);  //186****2644

  

 

posted @ 2021-03-29 10:39  L小洁  阅读(391)  评论(0编辑  收藏  举报