-
-
Save RhinoLu/ab3b0d88c79d6a479a46 to your computer and use it in GitHub Desktop.
台灣身分證檢查
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
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