diff --git a/src/router/modules/demo.ts b/src/router/modules/demo.ts index adf546f..f2613b7 100644 --- a/src/router/modules/demo.ts +++ b/src/router/modules/demo.ts @@ -94,6 +94,10 @@ const titleArr = [ key: 'rebindEvent', title: '重复绑定相同事件的执行机制', }, + { + key: 'reg', + title: '正则表达式', + }, ]; // @/views/demo/**/*.vue diff --git a/src/views/demo/reg/index.vue b/src/views/demo/reg/index.vue new file mode 100644 index 0000000..d32989b --- /dev/null +++ b/src/views/demo/reg/index.vue @@ -0,0 +1,17 @@ + + + diff --git a/src/views/demo/reg/reg.md b/src/views/demo/reg/reg.md new file mode 100644 index 0000000..3a4683e --- /dev/null +++ b/src/views/demo/reg/reg.md @@ -0,0 +1,42 @@ +## 身份证,手机号等前端脱敏 + +```javascript +/** + * 身份证号码脱敏方法 + * IdNum.replace(/^(.{2}).+(.{2})$/, '$1****$2') 前2后2中间4个*号 + * IdNum.replace(/^(.{4}).+(.{4})$/, '$1****$2') 前4后4中间4个*号 + * IdNum.replace(/^(.{2}).+(.{2})$/, '$1******$2') 前2后2中间6个*号 + * IdNum.replace(/^(.{6}).+(.{6})$/, '$1**$2') 前6后6中间2个*号 + * @param {string} IdNum + * @returns + */ +const IdNumberFilter = (IdNum) => { + if (IdNum != null) { + if (IdNum.length <= 8) { + // 当输入的身份证号码长度小于等于8位时,只显示前两位和后两位 + return IdNum.replace(/^(.{2}).+(.{2})$/, '$1****$2'); + } else { + // 当输入的身份证号码长度大于8位时,只显示前四位和后四位 + return IdNum.replace(/^(.{4}).+(.{4})$/, '$1****$2'); + } + } +}; +``` + +## 邮箱脱敏 + +```javascript +/** + * 邮箱脱敏方法 + * @param {string} email + * @returns + */ +const EmailFilter = (email) => { + if (email != null) { + // 匹配邮箱的前三位和@符号后的完整域名 + return email.replace(/^(.{3})[^@]*@(.*)$/, '$1****@$2'); + } +}; + +console.log(EmailFilter('thisistest778@qq.com')) +``` \ No newline at end of file