How does the front end use filters to replace the numbers in the ID card number


foreword

In the actual project, the display of some information is not suitable for complete display, such as ID card number, mobile phone number, name, email address and so on. Therefore, programmers are required to replace the information.


提示:以下是本篇文章正文内容,下面案例可供参考

1. Examples

Example code:

<el-table-column
	prop="identityCard"
	label="身份证号"
	align="center"
	>
		<template slot-scope="scope">
			{
    
    {
    
    scope.row.identityCard | desensityIdCard}}
		</template>
	</el-table-column>

	<script>
	export default {
    
    
		filters: {
    
    
    		desensityIdCard(str) {
    
    
      		if (null != str && str != undefined) {
    
    
        		var pat = /(\d{4})\d*(\d{4})/;
        		return str.replace(pat, '$1***********$2');
      		} else {
    
    
		        return '';
      		}
    	  }
  	   },
	}
   </script>

Show results:
insert image description here

at last

This is the end of the shared content, if it is helpful to you, please give it a thumbs up ! ! !

Guess you like

Origin blog.csdn.net/daishu_shu/article/details/124407158