Skip to content

Instantly share code, notes, and snippets.

@RhinoLu
Forked from tony1223/gist:ac9aec20561112e6e43c
Created November 1, 2015 13:43
Show Gist options
  • Save RhinoLu/ab3b0d88c79d6a479a46 to your computer and use it in GitHub Desktop.
Save RhinoLu/ab3b0d88c79d6a479a46 to your computer and use it in GitHub Desktop.
台灣身分證檢查
function identify(check){
var type = {a:10, b:11, c:12, d:13, e:14, f:15, g:16, h:17, j:18, k:19, l:20, m:21, n:22, p:23, q:24, r:25, s:26, t:27, u:28, v:29, w:32, x:30, y:31, z:33, i:34, o:35 };
var val = type[check[0].toLowerCase()] + check.substring(1);
var ranks = [1,9,8,7,6,5,4,3,2,1];
var checknum = 0;
for(var i = 0 ; i < ranks.length;++i){
checknum += parseInt(val[i],10) * ranks[i];
console.log(val[i],ranks[i],checknum);
}
var checkcode = check.substring(9,10);
if(checknum%10 == 0 && checkcode == 0){
return true;
}
return checkcode == (10 - checknum%10);
};
identify("身份證字號");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment