java 手机号脱敏,身份证号脱敏 工具类
import mons.lang3.StringUtils;/*** * @title: 脱敏工具类* @author: wll* @since: -9-3 9:54:04*/public class CommonUtils {// 手机号码前三后四脱敏public static String encryptMobile(String mobile) {if (StringUtils.isEmpty(mobile) || (mobile.length() != 11)) {return mobile;}return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");}// 身份证前三后四脱敏public static String encryptIdNo(String id) {if (StringUtils.isEmpty(id) || (id.length() < 8)) {return id;}return id.replaceAll("(?<=\\w{3})\\w(?=\\w{4})", "*");}// 护照前2后3位脱敏,护照一般为8或9位public static String encryptPassportNo(String id) {if (StringUtils.isEmpty(id) || (id.length() < 8)) {return id;}return id.substring(0, 2) + new String(new char[id.length() - 5]).replace("\0", "*") + id.substring(id.length() - 3);}}