校验数字
<el-form-item
label="座位数:"
prop="carInfo.seatNum"
:rules="{ required: false, message: '请输入数字', trigger: 'blur' ,validator: checkNumber}"
>
<el-input v-model="quotaForm.carInfo.seatNum" placeholder="请输入"></el-input>
</el-form-item>
方法:
/* 校验数字 */
checkNumber(rule, value, callback) {
const regex = /^\d+$/;
if (value.length!==0 && (!value || !regex.test(value))) {
callback(new Error('请输入正整数!'));
} else {
callback();
}
},
校验数字和两位小数
<el-form-item
label="保费:"
prop="insur.bizKind.rmbSum"
:rules="[{ required: false, message: '请正确输入(数字或者两位小数)!', trigger: 'blur'},{
validator: checkMoney
}]"
>
<el-input v-model="quotaForm.insur.bizKind.rmbSum" placeholder="请输入"></el-input>
</el-form-item>
vb
`
/* 校验输入金额 */
checkMoney(rule, value, callback) {
const regex = /^\d+(\.\d{1,2})?$/;
if (value.length!==0 && (!value || !regex.test(value))) {
callback(new Error('请输入正整数或者两位小数!'));
} else {
callback();
}
},`