feat: 新增dayjs依赖与证件号/营业执照号校验规则
parent
27ad12a765
commit
782effa256
|
|
@ -11,6 +11,7 @@
|
|||
"@ant-design/icons-vue": "^7.0.0",
|
||||
"ant-design-vue": "^4.2.0",
|
||||
"axios": "^1.7.0",
|
||||
"dayjs": "^1.11.10",
|
||||
"pinia": "^2.1.7",
|
||||
"vue": "^3.4.0",
|
||||
"vue-router": "^4.3.0"
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
"pinia": "^2.1.7",
|
||||
"axios": "^1.7.0",
|
||||
"ant-design-vue": "^4.2.0",
|
||||
"@ant-design/icons-vue": "^7.0.0"
|
||||
"@ant-design/icons-vue": "^7.0.0",
|
||||
"dayjs": "^1.11.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.0.0",
|
||||
|
|
|
|||
|
|
@ -31,3 +31,38 @@ export function passwordStrengthValidatorRule() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 18位身份证号,末位允许 X/x,不做校验码算术级校验(与手机号正则的"够用不过度设计"风格一致)
|
||||
const ID_CARD_REGEX = /^\d{17}[\dXx]$/
|
||||
// 统一社会信用代码/营业执照号:15-20位数字与大写字母组合,覆盖新旧两种编码位数
|
||||
const BUSINESS_LICENSE_REGEX = /^[0-9A-Z]{15,20}$/
|
||||
|
||||
export function isValidIdCard(idCard) {
|
||||
return ID_CARD_REGEX.test(idCard || '')
|
||||
}
|
||||
|
||||
export function isValidBusinessLicense(license) {
|
||||
return BUSINESS_LICENSE_REGEX.test(license || '')
|
||||
}
|
||||
|
||||
export function idCardValidatorRule() {
|
||||
return {
|
||||
validator: (_rule, value) => {
|
||||
if (!value) return Promise.reject(new Error('请输入证件号码'))
|
||||
if (!isValidIdCard(value)) return Promise.reject(new Error('请输入正确的18位身份证号'))
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function businessLicenseValidatorRule() {
|
||||
return {
|
||||
validator: (_rule, value) => {
|
||||
if (!value) return Promise.reject(new Error('请输入营业执照号'))
|
||||
if (!isValidBusinessLicense(value)) {
|
||||
return Promise.reject(new Error('请输入正确的营业执照号(15-20位数字/大写字母)'))
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue