验证身份证号码,较为完整的,可以验证身份证真伪
作者:互联网
下边的方法可以较为完整的验证身份证真伪,可到当前平台验证身份证真伪http://www.ip33.com/shenfenzheng.html
checkCode(val) {
var p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
var code = val.substring(17)
if (p.test(val)) {
var sum = 0
for (var i = 0; i < 17; i++) {
sum += val[i] * factor[i]
}
if (parity[sum % 11] == code.toUpperCase()) {
return true
}
}
return false
},
标签:10,val,验证,sum,真伪,身份证,var 来源: https://www.cnblogs.com/bingchenzhilu/p/14964200.html