当前位置:网站首页>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
边栏推荐
- Leetcode topic analysis count primes
- How to use the template library of barcode label software
- Object. Defineproperty() and data broker
- [qnx hypervisor 2.2 user manual]6.2 network
- Open source stealing malware mercurial found in the field for "educational purposes"
- How thingjs enables low threshold 3D visualization development
- MQTT+Flink实现实时消息的订阅与发布
- [cloud native | kubernetes] kubernetes principle and installation (II)
- Top 25 most popular articles on vivo Internet technology in 2021
- 297. Serialize and Deserialize Binary Tree
猜你喜欢

【学习资源】理解数学和热爱数学

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

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

'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册

Geoserver添加mongoDB数据源

Which is better, semrush or ahrefs? Which is more suitable for GoogleSEO keyword analysis
![[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24](/img/e1/97c92290a2a5e68f05cdbd5bf525e8.png)
[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24

社区文章|MOSN 构建 Subset 优化思路分享

测试-- 自动化测试selenium(关于API)

636. Exclusive Time of Functions
随机推荐
[cloud native | kubernetes] kubernetes principle and installation (II)
5、 Project management
Testing -- automated testing selenium (about API)
Vue3表单页面利用keep-alive缓存数据的一种思路
What exactly is RT?
GeoServer adding mongodb data source
How to restore visualizations and dashboards after kibana rebuilds the index
Arthas vmtool命令小结
MySQL故障案例 | ERROR 1071 (42000): Specified key was too long
最常用的5中流ETL模式
Object. Defineproperty() and data broker
In depth interpretation of poca smart contract platform gear: the road to parallel architecture public chain
Qualcomm 9x07 two startup modes
173. Binary Search Tree Iterator
Fraction to recursing decimal
通信方式总结及I2C驱动详解
Which is better, semrush or ahrefs? Which is more suitable for GoogleSEO keyword analysis
kernel log调试方法
Can portals be the next decentraland?
点击添加下拉框