I am new to ant design. I want to validate a field to take only alphabets and special characters but not numbers. This is the approach I have used so far. I am using ant design 4.
<Form.Item
label="First Name"
name="first_name"
rules={[
{ required: true, message: REQUIRED_ERROR_MESSAGE },
{
pattern: new RegExp("/^[A-Z@~`!@#$%^&*()_=+\\\\';:\"\\/?>.<,-]*$/i"),
message: "field does not accept numbers"
}
]}
>
<Input />
</Form.Item>
The above approach fails even if a user enters only letters. any help would be appreciated.
try removing the quotes that you currently have around your regular expression like this:
pattern: new RegExp(/^[a-zA-Z@~`!@#$%^&*()_=+\\\\';:\"\\/?>.<,-]+$/i),
here's an example on codesandbox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With