身份证号加密

1.身份证号加密

const cardId="612422199504232621"

idCardNoFormat (str) {

if(!str){return ""};

const newStr = String(str).replace(/^(.{4})(?:\w+)(.{4})$/, "\$1****\$2");

return newStr;

}

加密后:cardId=idCardNoFormat(cardId) "6124****2621"

2.手机号加密

const phone ="15129037628"

phoneNoFormat (str) {

if(!str){return ""};

const newStr = String(str).replace(/^(.{3})(?:\w+)(.{4})$/, "\$1****\$2");

return newStr;

}

加密后 phone=phoneNoFormat(phone) "151****7628"

你可能感兴趣的:(react.js)