网上找了好多方法,会出现各种各样的问题
最简单的限制长度,加一个箭头上的值就行
如果需求只有限制纯数字输入可以直接在行间用这个方法就行
oninput="value=value.replace(/[^\d]/g,'')"
我们是这个需求时间小于24小时,纯数字输入,限制长度,如果需求是这三个都要满足,就用这个方法
代码中的this.ruleForm.working_hours_billing,是我input框中绑定的值,根据自己的需求来,代码如下
myFunction(value) {
if (value.replace(/[^\d]/g, "") !== "") {
if (Number(value.replace(/[^\d]/g, "")) > 24) {
this.$message.error(
this.$i18n.t("label.projectManagement.must.be.less.than.24.hours")
);
this.ruleForm.working_hours_billing = 0;
}
} else if (value.replace(/[^\d]/g, "") == "") {
this.$message.error("请输入有效数字");
if (Number(value.replace(/[^\d]/g, "")) === 0) {
this.ruleForm.working_hours_billing = "";
}
}
},