利用正则表达式对手机号、身份证、姓名脱敏(**模糊化)

var phone ="13623021456";
var idcode ="440582199612056666";
var name ="陈妹";
var name1 ="陈美美";
var name2 ="欧阳美美";

phone =phone.replace(/^(.{3}).+(.{4})$/,"$1****$2");
idcode =idcode.replace(/^(.{4}).+(.{4})$/,"$1****$2");
name = name.replace(/^(.).+$/,"$1*");
name1 = name1.replace(/^(.).+(.)$/,"$1*$2");
name2 = name2.replace(/^(.{2}).+(.)/,"$1**$2");


console.log("phone",phone);
console.log("idcode",idcode);
console.log("name",name);
console.log("name1",name1);
console.log("name2",name2);

运行效果:

利用正则表达式对手机号、身份证、姓名脱敏(**模糊化)_第1张图片

你可能感兴趣的:(javascript学习笔记)