Skip to content

Instantly share code, notes, and snippets.

@layerlre
Created March 27, 2017 06:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save layerlre/a8cffb2713089235062334cb07e653bd to your computer and use it in GitHub Desktop.
Save layerlre/a8cffb2713089235062334cb07e653bd to your computer and use it in GitHub Desktop.
Validate thai ID card
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