修复bug

This commit is contained in:
zhouyanli
2026-08-22 08:08:01 +08:00
parent a078513221
commit 453f563a6e
8 changed files with 49 additions and 13 deletions

View File

@@ -543,6 +543,39 @@
}
}
// 18位居民身份证号码校验含出生日期与校验码
const isValidIdCard = (id) => {
const reg = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/
if (!reg.test(id)) return false
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
const checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
let sum = 0
for (let i = 0; i < 17; i++) {
sum += parseInt(id[i], 10) * weights[i]
}
return checkCodes[sum % 11] === id[17].toUpperCase()
}
// 按证件类型校验证件号码格式
const validateCardNo = () => {
const cardNo = (form.cardNo || '').toUpperCase()
const cardTypeId = String(form.cardType.id ?? '')
// 居民身份证18位含校验码
if (cardTypeId === '0') {
return isValidIdCard(cardNo)
}
// 护照:字母开头 + 7~8位数字
if (cardTypeId === '1') {
return /^[A-Z]\d{7,8}$/.test(cardNo)
}
// 港澳通行证H/M/C 开头 + 8位数字
if (cardTypeId === '2') {
return /^[HMC]\d{8}$/.test(cardNo)
}
// 其他类型:字母数字 5~18 位
return /^[A-Z0-9]{5,18}$/.test(cardNo)
}
const openCardType = () => {
showCardType.value = true
}
@@ -663,6 +696,10 @@
title: '请输入证件号',
icon: 'none'
})
if (!validateCardNo()) return uni.showToast({
title: '证件号码格式错误',
icon: 'none'
})
if (!form.relation && form.relation != 0) return uni.showToast({
title: '请选择关系',
icon: 'none'