属于个人记录文章—持续更新中…
只能输入数字正则表达式:
/^[0-9]*$/
校验身份证号码是否符合规范
verfyCertificat(idCard) {
let regIdCard =
/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/
if (regIdCard.test(idCard)) {
if (idCard.length == 18) {
var idCardWi = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2)
var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2)
var idCardWiSum = 0
for (var i = 0; i < 17; i++) {
idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i]
}
var idCardMod = idCardWiSum % 11
var idCardLast = idCard.substring(17)
if (idCardMod == 2) {
if (idCardLast == 'X' || idCardLast == 'x') {
return true
} else {
return false
}
} else {
if (idCardLast == idCardY[idCardMod]) {
return true
} else {
return false
}
}
}
} else {
return false
}
},
|