Skip to content

Instantly share code, notes, and snippets.

@hansonkim
Last active July 28, 2019 23:18
Show Gist options
  • Save hansonkim/4782acd48d5d703ab8c853a4c1a2015b to your computer and use it in GitHub Desktop.
Save hansonkim/4782acd48d5d703ab8c853a4c1a2015b to your computer and use it in GitHub Desktop.
JAVA 사업자 등록번호 유효성 검사
/**
* 사업자 번호 유효성 검사
* Created by Hanson on 2017-07-04.
*/
public class CRNValidator {
private final static int[] LOGIC_NUM = {1, 3, 7, 1, 3, 7, 1, 3, 5, 1};
public final static boolean isValid(String regNum) {
if (!isNumeric(regNum) || regNum.length() != 10)
return false;
int sum = 0;
int j = -1;
for (int i = 0; i < 9; i++) {
j = Character.getNumericValue(regNum.charAt(i));
sum += j * LOGIC_NUM[i];
}
sum += (int) (Character.getNumericValue(regNum.charAt(8)) * 5 /10);
int checkNum = (10 - sum % 10) % 10 ;
return (checkNum == Character.getNumericValue(regNum.charAt(9)));
}
public static boolean isNumeric(String str) {
if (str == null) {
return false;
}
int sz = str.length();
for (int i = 0; i < sz; i++) {
if (Character.isDigit(str.charAt(i)) == false) {
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment