package com.sinosun.travel.util; import org.apache.commons.lang.StringUtils;
/** * Created by caogu on 2018/8/24 17:07. * Copyright (c) Sinosun Technology
Co., Ltd 2018 */ public class CommonUtils { // 手机号码前三后四脱敏 public static String
mobileEncrypt(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
idEncrypt(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 idPassport(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); } }
热门工具 换一换