One, 11 mobile phone number in the middle of the four desensitization display, for example: 187** 1234
function noPassByMobile(str){ if(null ! = str && str ! = undefined){ var pat=/(\d{3})\d*(\d{4})/; return str.replace(pat,'$1****$2'); } else { return ""; }}
Two, name desensitization processing, rules: 3 words within the first word desensitization, 4-6 words desensitization before the two words, more than 6 words desensitization 3-6 words, example: Zhang SAN (3) Zhang Sanshui (Sanshui), Changsun Mowgli (** Mowgli), Rostoro driver (Roth XXXX grid)
function noPassByName(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 ""; }}
Three, ID number desensitization
Var idCard = '410184199312042029'; var idCard = '410184199312042029'; var id2 = idCard.replace(/^(.{6})(? :\d+)(.{4})$/, "$1****$2"); var id3 = idCard.replace(/^(.{2})(? :\w+)(.{1})$/, "\$1****\$2"); var id4 = idCard.replace(/^(.{4})(? :\w+)(.{4})$/, "\$1****\$2");