当前位置:网站首页>JS mask important data of ID card and mobile phone number with * *
JS mask important data of ID card and mobile phone number with * *
2022-06-23 08:55:00 【& Super】
js use ** Mask the middle part of ID card and mobile phone number , Mask processing
One 、 Application scenarios
Examples will 18 ID card as well as 11 The mobile phone number of bit is masked
The example is 42333333330435 and 15765559657
The result of conversion to is shown in the figure :
Two 、 Realize the idea
The converted code is Create your own js File to copy the code into , Ideas can be passed on The head shows how many positions , Several digits are displayed at the end , Then calculate the number of stars in the middle , The data we want can be achieved by splicing recently .
// Set up ** Mask hide Parameters ( data Top three The last four )
function basecclusion(data, frontShow, afterShow) {
let dataLengh = data.length;
if (dataLengh > frontShow + afterShow) {
let obscuringStar = '*';
// Calculate the number of stars in the middle
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 '—'; // Returns... If it is not standardized '-'
}
}
// Customize Cover length
export function occlusion(data, frontShow, afterShow) {
return basecclusion(data, frontShow, afterShow);
}
// Cover length of ID card
export function occlusionToidCard(data) {
return basecclusion(data, 6, 4);
}
// Cell phone number cover length
export function occlusionToPhone(data) {
return basecclusion(data, 3, 4);
}-
3、 ... and 、 Usage method
Because of the secondary packaging There are three ways , I can be in basecclusion On the basis of your own settings , The following can be used to export
occlusionToidCard Used to process ID cards ,
occlusionToPhone Used to process mobile phone numbers ,
occlusion Dynamically set the length of the mask
import { occlusionToidCard, occlusionToPhone, occlusion} from '@/utils/processing.js';
let idCard=421127333330435
console.log( occlusionToidCard(text)) // Output 421127********0435
let phone=15765559657
console.log( occlusionToidCard(phone)) // Output 157****9657
let text='404840 my '
console.log(occlusion (text,2,3)) // Output '404**0 my ' Output front 2 individual And the end 3 A display
边栏推荐
- Flink错误--Caused by: org.apache.calcite.sql.parser.SqlParseException: Encountered “time“
- 986. Interval List Intersections
- 6、 Web Architecture Design
- usb peripheral 驱动 - configfs
- Leetcode topic analysis group anagrams
- Tencent cloud arm server evaluation practice
- Comprehensive analysis of news capture
- Summary ranges of leetcode topic resolution
- 125. Valid Palindrome
- C # advanced learning -- virtual method
猜你喜欢
随机推荐
Fraction to recursing decimal
Leetcode topic analysis 3sum closest
[advanced Android] kotlin notes
在小程序中实现视频通话及互动直播的一种方法
Set interface and set sub implementation classes
6、 Web Architecture Design
Install a WGet for your win10
528. Random Pick with Weight
Node request module cookie usage
驱动架构 & platform平台总线驱动模型
Keng dad's "dedication blessing": red packet technology explosion in Alipay Spring Festival Gala
Vue3表单页面利用keep-alive缓存数据的一种思路
【云原生 | Kubernetes篇】Kubernetes原理与安装(二)
Kernel log debugging method
How to restore visualizations and dashboards after kibana rebuilds the index
简易学生管理
6-shining laser application of calayer
点击添加下拉框
Optimize your gradle module with a clean architecture
438. Find All Anagrams in a String









