首页 > 代码库 > 遮蔽某几个字
遮蔽某几个字
开发项目总结常用方法:
/**
* 交易密碼隱碼
* @param payPwd
* @return
*/
public static String hidePayPwdCode ( String payPwd) {
if (null == payPwd) return null;
return getStats(payPwd.length());
}
/**
* 登入密碼隱碼
* @param loginPwd
* @return
*/
public static String hideLoginPwdCode ( String loginPwd) {
if (null == loginPwd) return null;
return getStats(loginPwd.length());
}
/**
* 銀行賬號
* @param bankAccount
* @return
* @throws Exception
*/
public static String hideAccCode(String accCode) {
if(accCode==null)return "";
int len=accCode.trim().length();
if(len==0)return "";
String strRes=accCode.trim();
if(len>=6)
strRes=accCode.trim().substring(0, 6);
String strEnd="";
if(len>3)
strEnd=accCode.trim().substring(len-3);
strRes+=getStats(len-9)+strEnd;
return strRes;
}
/**
* 信用卡隱碼
* @param phone
* @return
*/
public static String hideCardCode ( String cardNumber ) {
if(cardNumber==null)return "";
int len=cardNumber.trim().length();
if(len==0)return "";
String strRes=cardNumber.trim();
if(len>=8)
strRes=cardNumber.trim().substring(0, 8);
String strEnd="";
if(len>4)
strEnd=cardNumber.trim().substring(len-4);
strRes+=getStats(len-12)+strEnd;
return strRes;
}
/**
* 身分證字號隱碼
* @param personId
* @return
*/
public static String hidePersonIdCode ( String personId) {
if(personId==null)return "";
int len=personId.trim().length();
if(len==0)return "";
String strRes=personId.trim();
if(len>=7)
strRes=personId.trim().substring(0, 7);
strRes+=getStats(len-7);
return strRes;
}
/**
* 姓名
* @param userName
* @return
* @throws Exception
*/
public static String hideUserName(String userName) {
if(userName==null)return "";
int len=userName.trim().length();
if(len==0)return "";
String strRes=userName.trim();
if(len>=1)
strRes=userName.trim().substring(0, 1);
strRes+=getStats(len-1);
return strRes;
}
/**
* 住址隱碼
* @param addrCode
* @return
*/
public static String hideAddressCode ( String address) {
if(address==null)return "";
int len=address.trim().length();
if(len==0)return "";
String strRes=address.trim();
if(len>=6)
strRes=address.trim().substring(0, 6);
strRes+=getStats(len-6);
return strRes;
}
/**
* 電子郵件地址
* @param userName
* @return
* @throws Exception
*/
public static String hideEmailAddress(String emailAddress) {
if(emailAddress==null)return "";
int len=emailAddress.trim().length();
if(len==0)return "";
String[] aryEmail=emailAddress.split("@");
String strRes="";
len=aryEmail[0].trim().length();
if(len>3)
strRes=aryEmail[0].trim().substring(0, len-3);
strRes+=getStats(3);
if(aryEmail.length>1)
strRes+="@"+aryEmail[1];
return strRes;
}
/**
* 電話號碼
* @param phoneNumber
* @return
* @throws Exception
*/
public static String hidePhoneCode ( String phoneNumber ) {
if(phoneNumber==null)return "";
int len=phoneNumber.trim().length();
if(len==0)return "";
String strRes=phoneNumber.trim();
if(len>=5)
strRes=phoneNumber.trim().substring(0, 5);
String strEnd="";
if(len>2)
strEnd=phoneNumber.trim().substring(len-2);
strRes+=getStats(len-7)+strEnd;
return strRes;
}
/**
* 生日
* @param userName
* @return
* @throws Exception
*/
public static String hideBirthday(Integer birthday) {
if(birthday==null)return "";
int len=birthday.toString().trim().length();
if(len==0)return "";
String strRes=birthday.toString().trim();
if(len>=6)
strRes=birthday.toString().trim().substring(0, 6);
strRes+=getStats(len-6);
return strRes;
}
private static String getStats(int len){
if(len<=0)return "";
String strRes="";
for(int i=0;i<len;i++)
strRes+="*";
return strRes;
}
遮蔽某几个字