cpp
复制代码
<a-form-item
label="市场价"
class="status-barcode"
name="marketPrice"
:rules="[
{ required: true, message: '' },
{ validator: validateNumber },
]"
>
<a-input
show-count
:maxlength="10"
v-model:value="formState.marketPrice"
placeholder="市场价"
/>
</a-form-item>
cpp
复制代码
const objRegExp = {
marketPrice: "市场价格",
};
const NumberRegCommodity = /^(?!0)\d{1,10}$/;
const validateNumber = (rule, value, callback) => {
if (!value) {
callback(`请填写${objRegExp[rule.field]}`);
return;
}
if (!NumberRegCommodity.test(value)) {
callback("仅限填写正数且首位不能为0");
}
};