Last active
July 28, 2019 23:18
-
-
Save hansonkim/4782acd48d5d703ab8c853a4c1a2015b to your computer and use it in GitHub Desktop.
JAVA 사업자 등록번호 유효성 검사
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 사업자 번호 유효성 검사 | |
* 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