当前位置:网站首页>js 用**遮罩身份证以及手机号的重要数据
js 用**遮罩身份证以及手机号的重要数据
2022-06-23 08:46:00 【&超】
js 用**遮罩身份证以及手机号中间部位,进行掩码处理
一、应用场景
实例将 18位身份证 以及11位的手机号进行遮掩处理
样例为 42333333330435 和15765559657
转为的结果如图:
二、实现思路
转化的代码为 自己创建一个js文件将代码复制进去,思路是可以传 头部显示多少位置 ,末尾显示几位,然后进行计算中间的星星数,最近进行拼接则达到我们想要的数据。
// 设置**遮罩隐藏 参数( 数据 前三位 后四位)
function basecclusion(data, frontShow, afterShow) {
let dataLengh = data.length;
if (dataLengh > frontShow + afterShow) {
let obscuringStar = '*';
// 计算中间星星数
for (let i = 0; i < dataLengh - frontShow - afterShow; i++) {
obscuringStar += '*';
}
return data.substring(0, frontShow) + obscuringStar + data.substring(data.length - afterShow, data.length);
} else {
return '—'; // 不规范时返回'-'
}
}
// 自定义 遮盖长度
export function occlusion(data, frontShow, afterShow) {
return basecclusion(data, frontShow, afterShow);
}
// 身份证遮盖长度
export function occlusionToidCard(data) {
return basecclusion(data, 6, 4);
}
// 手机号遮盖长度
export function occlusionToPhone(data) {
return basecclusion(data, 3, 4);
}-
三、使用方法
因为进行了二次封装 有三个方法,自己可以在basecclusion基础上自己设置,进行导出目前可以用有以下
occlusionToidCard 用来处理身份证,
occlusionToPhone用来处理手机号,
occlusion 动态设置的遮掩的长度
import { occlusionToidCard, occlusionToPhone, occlusion} from '@/utils/processing.js';
let idCard=421127333330435
console.log( occlusionToidCard(text)) // 输出421127********0435
let phone=15765559657
console.log( occlusionToidCard(phone)) // 输出157****9657
let text='404840我的'
console.log(occlusion (text,2,3)) // 输出'404**0我的' 输出 前2个 和末尾3个显示
边栏推荐
- Hongmeng reads the resource file
- Monitor the cache update of Eureka client
- Install a WGet for your win10
- New engine, new capability, new experience, Tencent host security flagship release
- Le rapport d'analyse de l'industrie chinoise des bases de données a été publié en juin. Le vent intelligent se lève, les colonnes se régénèrent
- Open source technology exchange batch stream integrated data synchronization engine Chunjun data restore DDL function module analysis
- GeoServer adding mongodb data source
- Use newbeecoder UI implements data paging
- [advanced Android] kotlin notes
- How thingjs enables low threshold 3D visualization development
猜你喜欢

Which one is better for rendering renderings? 2022 latest measured data (IV)

力扣之滑动窗口《循序渐进》(209.长度最小的子数组、904. 水果成篮)

Why use growth neural gas network (GNG)?

The most commonly used 5-stream ETL mode

In June, China database industry analysis report was released! Smart wind, train storage and regeneration

Install a WGet for your win10

Introduction to typescript and basic types of variable definitions
![[cloud computing] GFS ideological advantages and architecture](/img/98/2a4ef0ca805add24d431dac9808903.png)
[cloud computing] GFS ideological advantages and architecture

Why do we say that the data service API is the standard configuration of the data midrange?

测试-- 自动化测试selenium(关于API)
随机推荐
通信方式总结及I2C驱动详解
Leetcode topic analysis count primes
In June, China database industry analysis report was released! Smart wind, train storage and regeneration
Restore the default routing settings of the primary network card
The most commonly used 5-stream ETL mode
Deep analysis and Simulation of vector
Summary of communication mode and detailed explanation of I2C drive
How to restore visualizations and dashboards after kibana rebuilds the index
Map interface and its sub implementation classes
6-shining laser application of calayer
Unity grid programming 06
In depth interpretation of poca smart contract platform gear: the road to parallel architecture public chain
自定义标签——jsp标签增强
Quartz Crystal Drive Level Calculation
Linux Mysql安装
Flink error --caused by: org apache. calcite. sql. parser. SqlParseException: Encountered “time“
6月《中國數據庫行業分析報告》發布!智能風起,列存更生
Leetcode topic analysis h-index II
438. Find All Anagrams in a String
usb peripheral 驱动 - configfs