자바(java)
[java] java 휴대폰번호 마스킹 가운데 4자리 마스킹
웅겹사r☆
2023. 2. 17. 09:23
public static String phoneMasking(String phoneNo) throws Exception {
String regex = "(\\d{2,3})-?(\\d{3,4})-?(\\d{4})$";
Matcher matcher = Pattern.compile(regex).matcher(phoneNo);
if(matcher.find()) {
String target = matcher.group(2);
int length = target.length();
char[] c = new char[length];
Arrays.fill(c, '*');
return phoneNo.replace(target, String.valueOf(c));
}
return phoneNo;
}