프로그래밍/Java
[Java] 이름과 핸드폰번호에 대한 마스킹 처리
프리랜서_코더
2021. 1. 1. 20:02
public String maskingPhone(String phoneStr) {
phoneStr = phoneStr.replaceAll("-", "");
String result = "";
int strLength = phoneStr.length();
result += phoneStr.substring(0,3);
result += strLength == 10 ? "-***-" : "-****-";
result += phoneStr.substring((strLength - 4 ),(strLength));
return result;
}
//maskingPhone("010-111-1111");
//maskingPhone("010-1234-5678");
public String maskingName(String nameStr) {
String result = "";
int strLength = nameStr.length();
result += nameStr.substring(0,1);
if ( strLength == 2 ){
result += "*";
}else{
String mask = "";
for (int i = 0; i < ( strLength -2 ); i++) {
mask += "*";
}
result += mask;
result += nameStr.subSequence((strLength-1), strLength);
}
return result;
}
//maskingName("김김");
//maskingName("박박박");