본문 바로가기
Study/Java

[JAVA] 숫자형식 포멧 방법

by 오늘만 사는 여자 2023. 1. 5.
728x90
반응형

//휴대폰

public static String makePhoneNumber(String Number) {

 

String regEx = "(\\d{3})(\\d{3,4})(\\d{4})";

 

if(!Pattern.matches(regEx, Number)) return null;

 

return Number.replaceAll(regEx, "$1-$2-$3");

}

 

//사업자번호

public static String makeNumber(String Number) {

 

String regEx = "(\\d{3})(\\d{2})(\\d{5})";

 

if(!Pattern.matches(regEx, Number)) return null;

 

return Number.replaceAll(regEx, "$1-$2-$3");

}

 

 

//법인번호

public static String makeNumber(String Number) {

 

String regEx = "(\\d{6})(\\d{7})";

 

if(!Pattern.matches(regEx, Number)) return null;

 

return Number.replaceAll(regEx, "$1-$2");

}

 
 
Reference : http://www.joshi.co.kr/index.php?mid=board_aCLN93&document_srl=305374
728x90
반응형

댓글