18位身份證校驗碼驗證算法
阿新 • • 發佈:2017-05-26
div style charat span true class fun cnblogs test
function checkCode(card){ if (/^\d{17}[\dxX]$/.test(card)) { var a = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]; var valide = [1,0,‘X‘,9,8,7,6,5,4,3,2]; var s = 0; for (var i = 0; i < card.length - 1; i++) { s += card.charAt(i) * a[i]; }var mod = s % 11; if (valide[mod] != card.charAt(17).toUpperCase()) { return false; } else { return true; } } return false; }
18位身份證校驗碼驗證算法