public static String phoneNumberToMaskFormat(final String phoneNumber)
{
if (StringUtils.isEmpty(phoneNumber))
{
return "";
}
final String cleanNumber = phoneNumber.replaceAll("[\\(\\)\\- ]*", "");//去除符號()-
if (StringUtils.isNotEmpty(cleanNumber) && cleanNumber.length() > 4)
{
//去符號讓第2-5個數字替換成星
//例:(02)2960-3456=>0****03456
//例:(037)364220=>0****4220
return cleanNumber.replaceAll("^(\\d{1})(\\d{4})(.*)$", "$1****$3");
}
//cleanNumber不超過4碼時
return "******";
}
public static String mobileNumberToMaskFormat(final String mobileNumber)
{
if (StringUtils.isEmpty(mobileNumber))
{
return "";
}
//留頭4字及尾3字,中間3字替換成星
//例:0912123456=>0912***456
if (mobileNumber.length() == 10)
{
return mobileNumber.replaceAll("^(.{4})(.*)(.{3})$", "$1***$3");
}
//mobileNumber不為10碼時
return "******";
}
沒有留言:
張貼留言