手机号码中间4位|身份证号码|姓名,脱敏处理,星号*代替!

项目中用到的数据脱敏处理Function,没什么墨水,都是项目里拷贝出来保存的。


// 姓名脱敏
function hideName(str) {
	if (null != str && str != undefined) {
		if (str.length <= 3) {
			return "*" + str.substring(1, str.length);
		} else if (str.length > 3 && str.length <= 6) {
			return "**" + str.substring(2, str.length);
		} else if (str.length > 6) {
			return str.substring(0, 2) + "****" + str.substring(6, str.length)
		}
	} else {
		return "";
	}
}
// 手机号码脱敏
function hidePhone(phone) {
	if (phone == null) {
		return '未设置'
	} else {
		return phone.replace(/^(.{3})(?:\w+)(.{4})$/, "\$1****\$2");
	}
}
// 身份证脱敏
function hideIdentity(Identity) {
	return Identity.replace(/^(.{1})(?:\w+)(.{1})$/, "\$1****************\$2");
}

module.exports = {
	hideName,
	hidePhone,
	hideIdentity
}
发布了18 篇原创文章 · 获赞 10 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/a350110085/article/details/104952902