gpt4 book ai didi

reactjs - React ant 设计表单中的电子邮件验证

转载 作者:行者123 更新时间:2023-12-04 14:31:56 25 4
gpt4 key购买 nike

我正在 React.js 中使用 Ant 设计。我正在尝试使用 ant 设计规则验证电子邮件。我的正则表达式不起作用。

<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>

最佳答案

在规则中,您可以直接使用带有值电子邮件的类型键而不是正则表达式模式。
代码示例 https://codesandbox.io/s/stackoverflowantdemail-9jckh?file=/index.js:916-1352

<Form.Item>
{getFieldDecorator("email", {
rules: [
{
required: true,
type: "email",
message: "The input is not valid E-mail!"
}
]
})(
<Input

placeholder="Email"
/>
)}
</Form.Item>

关于reactjs - React ant 设计表单中的电子邮件验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63869030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com