Why the rules are not working? i am using antd inputs, now i want to validate the fields, what thing i need to do to use the rules for the inputs?
<Form form={form} onFinish={onFinish} onFinishFailed={onFinishFailed}
autoComplete="off">
<Form.Item className="form-item" label={'name'} rules={[
{
required: true,
message: 'Please input your name!',
},
]}>
<Input name='name' />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
submit
</Button>
</Form.Item>
</Form>
i want to validate if 'name' just have letters not numbers, how can i do that?
CodePudding user response:
Try this:
<Form form={form} onFinish={onFinish} onFinishFailed={onFinishFailed}
autoComplete="off">
<Form.Item className="form-item" label={'name'}
rules={[
{
pattern: new RegExp(/^[a-zA-Z]*$/),
message: 'No Numbers Allowed'
},
{
required: true,
message: 'Please input your name!',
}
]}>
<Input name='name' />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
submit
</Button>
</Form.Item>
</Form>;