Created
March 27, 2017 06:25
-
-
Save layerlre/a8cffb2713089235062334cb07e653bd to your computer and use it in GitHub Desktop.
Validate thai ID card
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
public class IDCardUtil { | |
public static boolean isValid(String idCard){ | |
if (idCard.length()!=13){ | |
return false; | |
} | |
int sum = 0; | |
for (int i = 0; i < 12; i++) { | |
sum += Character.getNumericValue(idCard.charAt(i))*(13-i); | |
} | |
return (11-sum%11)%10 == Character.getNumericValue(idCard.charAt(12)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment