1 函数验证
代码语言:javascript复制 //函数
const checkPrice = (rule, value) => {
if (value.number > 0) {
return Promise.resolve();
}
return Promise.reject('Price must be greater than zero!');
};
//表单
<Form.Item
name="price"
label="Price"
rules={[
{
validator: checkPrice,
},
]}
>
<PriceInput />
</Form.Item>
2 正则表达式
代码语言:javascript复制rules={
[
{
required: true,
message: '请输入个数'
},
{
pattern:/^(d|[1-9]d|100)$/,
message:'请输入0~100之间的数字'
}
]
}