Skip to content

JS之正则-字符串脱敏以及解读

参考:
js手机号脱敏处理方法 - 简书
JavaScript 手机号码脱敏 - SegmentFault 思否

自己整理的 [正则表达式] [JS相关的正则函数]

replace的方案

javascript
let phonenumber = number.replace(number.phonenumber.substring(3,7), '****')
let phonenumber = number.replace(number.phonenumber.substring(3,7), '****')
js

// 方法1
var phone = '18801333333';
var reg = /^(\d{3})\d{4}(\d{4})/;
var newPhone = phone.replace(reg,'$1****$2');
console.log(newPhone);

// 方法2
let phonenumber = number.replace(number.phonenumber.substring(3,7), '****')

// 方法1
var phone = '18801333333';
var reg = /^(\d{3})\d{4}(\d{4})/;
var newPhone = phone.replace(reg,'$1****$2');
console.log(newPhone);

// 方法2
let phonenumber = number.replace(number.phonenumber.substring(3,7), '****')