element el-form的表单自定义规则
<script lang="ts">
// import { AccountDTO } from "@/apis/accountGroup";
import Vue, { PropType } from "vue";
export default Vue.extend({
name: "riskManagement",
data() {
const moneyRules = (rule: any, value: any, callback: any) => {
const res = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
if (value != null && value != "") {
if (!res.test(value) || value > 1000000000 || value < 0) {
callback(new Error("最多保留两位小数,值范围在0-1000000000之间!"));
} else {
callback();
}
} else {
callback();
}
};
const numbersRules = (rule: any, value: any, callback: any) => {
const reg = /^\+?[1-9][0-9]*$/;
if (value != null && value != "") {
if (!reg.test(value) || value > 1000000000 || value < 0) {
callback(new Error("请输入整数,值范围在0-1000000000之间!"));
} else {
callback();
}
} else {
callback();
}
};
const rateRules = (rule: any, value: any, callback: any) => {
const res = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
if (value != null && value != "") {
if (!res.test(value) || value > 100 || value < 0) {
callback(new Error("最多保留两位小数,值范围在0-100之间!"));
} else {
callback();
}
} else {
callback();
}
};