校验金额
export const validateMoney = (rule, value, callback) => { if (value === "") { return callback(new Error("不能为空")); } if (value <= 0) { return callback(new Error("请输入大于0的金额")); } const reg = /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/; if (!reg.test(value)) { return callback(new Error("最多两位小数!")); } callback(); };
校验数量
export const validateNumber = (rule, value, callback) => { if (value === "") { return callback(new Error("不能为空")); } if (value <= 0) { return callback(new Error("请输入大于0的数量")); } const reg = /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,3})?$/; if (!reg.test(value)) { return callback(new Error("最多三位小数!")); } callback(); };
标签:const,value,js,callback,rule,Error,validate From: https://www.cnblogs.com/wjian0916/p/17457251.html