隐藏号码中间4位数
var phone = " 18311110000 ";
var regPhone = /^(\d{3})\d{4}(\d{4})$/;
console.log(phone .trim().replace(regPhone, "$1****$2"))
隐藏部分姓名
var txt = " 卫欧尼 ";
/* 姓名中间部分隐藏 */
var formatName = function (name) {
var newStr;
if (name.length === 2) {
newStr = name.substr(0, 1) + '*';
} else if (name.length > 2) {
var char = '';
for (let i = 0, len = name.length - 2; i < len; i++) {
char += '*';
}
newStr = name.substr(0, 1) + char + name.substr(-1, 1);
} else {
newStr = name;
}
return newStr;
};
console.log(formatName(txt.trim()));