证件号部分内容怎么用星号****代替?

目前总结两种方式实现,话不多说,直接上代码。。。

1、通过substr()方法实现

  

 1 <script>
 2     export default {
 3         data() {
 4             return {
 5                 hideCode: '',
 6                 code: '232301222222228888'
 7             }
 8         },
 9         computed: {
10 
11         },
12         onLoad() {
13             this.hideCode = this.code.substr(0,6) + '********' + this.code.substr(14,17) 
14         },
15         methods: {
16             
17         }
18     }
19 </script>

2、通过正则表达式实现

          this.hideCode = this.code.replace(/^(d{6})d{8}(d+)/,"$1********$2")

效果:

原文地址:https://www.cnblogs.com/heisetianshi/p/15100313.html