JS 手机号、姓名、地址脱敏

188 阅读1分钟

手机号:

 // scope.row.customerPhone为你的手机号
 scope.row.customerPhone.replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2");
 
 // 实际运用
 <el-table-column prop="customerPhone" label="用户电话" width="140px">
    <template slot-scope="scope">
        {{ showInfo[`${scope.row.compensateOrderNo}`] === true ? scope.row.customerPhone :
        scope.row.customerPhone.replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2") }}
    </template>
</el-table-column>

姓名:

 // scope.row.customerNam为你的姓名
 scope.row.customerName.replace(/^(.).+$/,"$1**");
 
 // 实际运用
<el-table-column prop="customerName" label="用户名称" show-overflow-tooltip>
    <template slot-scope="scope">
        {{ showInfo[`${scope.row.compensateOrderNo}`] === true ? scope.row.customerName :
        scope.row.customerName.replace(/^(.).+$/,"$1**") }}
    </template>
</el-table-column>

地址:

 // scope.row.customerAddress为你的地址
 scope.row.customerAddress.replace(/^(.{6}).+$/,"$1***");
 
 // 实际运用
<el-table-column prop="customerAddress" label="用户地址" width="140px" show-overflow-tooltip>
    <template slot-scope="scope">
        {{ showInfo[`${scope.row.compensateOrderNo}`] === true ? scope.row.customerAddress :
        scope.row.customerAddress.replace(/^(.{6}).+$/,"$1***") }}
    </template>
</el-table-column>