Skip to content

Instantly share code, notes, and snippets.

@Casear
Last active September 7, 2016 16:23
Show Gist options
  • Save Casear/db1c8844254107785269805cffe60af7 to your computer and use it in GitHub Desktop.
Save Casear/db1c8844254107785269805cffe60af7 to your computer and use it in GitHub Desktop.
身分證字號檢查
module.exports = function(id){
id = id.toUpperCase()
if (!/^[A-Z][1-2][0-9]{8}$/.test(id))
return false
var map = {
"A":1,
"B":10,
"C":19,
"D":28,
"E":37,
"F":46,
"G":55,
"H":64,
"I":39,
"J":73,
"K":82,
"L":2,
"M":11,
"N":20,
"O":48,
"P":29,
"Q":38,
"R":47,
"S":56,
"T":65,
"U":74,
"V":83,
"W":3,
"X":12,
"Y":21,
"Z":30
}
result = map[id[0]]
for(var i=1;i<9;i++){
result+=(id.charCodeAt(i)-48)*(9-i)
}
result+=id.charCodeAt(9)-48
return result%10===0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment