validate.js
640 Bytes
/**
* 校验身份证号码
*/
export function checkCardId(rule, value, callback) {
let cardIdReg = /^[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{3}([0-9]|X|x)$/
if (cardIdReg.test(value) || !value) {
return callback()
} else {
return callback(new Error('请输入正确的身份证号'))
}
}
/**
* 校验年龄
*/
export function checkAge(rule, value, callback) {
let ageReg = /^([1-9]\d?|1[01]\d|120)$/
if (ageReg.test(value) || !value) {
return callback()
} else {
return callback(new Error('请输入正确年龄'))
}
return
}