手機號碼中間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
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章