'Email validation in React ant design form
I am working with ant design in React.js. I'm trying to validate email with ant design rules. My regex does not work.
<Form.Item>
{getFieldDecorator('email', {
initialValue:null,
rules: [
{
required: false,
pattern: new RegExp("/\S+@\S+\.\S+/"),
message:
'Enter a valid email address!',
},
],
})(
<Input
className="form-control"
type="text"
placeholder="Email"
/>,
)}
</Form.Item>
Solution 1:[1]
<Form.Item
name="email"
label="E-mail"
rules={[
{
type: 'email',
message: 'The input is not valid E-mail!',
},
{
required: true,
message: 'Please input your E-mail!',
},
]}
>
<Input />
</Form.Item>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hoà ng Long |
