rules: {
bankAccount: [{ required: true, trigger: 'blur', validator: bankAccountValid }]
}
var bankAccountValid = (rule, value, callback) => {
const strBin = '10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99'
if (!value) {
return callback(new Error('收款账户不能为空'))
} else if (!Number.isInteger(+value)) {
callback(new Error('银行卡号必须全为数字'))
} else if (value.trim().length < 12 || value.trim().length > 19) {
callback(new Error('银行卡号长度必须在12到19之间'))
} else if (strBin.indexOf(value.substring(0, 2)) === -1) {
callback(new Error('银行卡号开头6位不符合规范'))
} else {
callback()
}
}