【发布时间】:2020-02-07 02:15:02
【问题描述】:
所以我读到了这个:Regular expression works on regex101.com, but not on prod
我在 antd 中创建了以下规则:Demo
<Form.Item
validateStatus={usernameError ? "error" : ""}
help={usernameError || ""}
>
{getFieldDecorator("username", {
rules: [
{ required: true, message: "Please input your username!" },
{
type: "regexp",
pattern: new RegExp(
/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!#$%\-_=+<>])([a-zA-Z0-9!#$%\-_=+<>]+)$/
),
message: `Password Pattern`
}
]
})(
<Input
prefix={<Icon type="user" style={{ color: "rgba(0,0,0,.25)" }} />}
placeholder="Username"
/>
)}
</Form.Item>
正则表达式应匹配必须至少包含 1 个数字、1 个字母和 1 个特殊字符的任何内容。
从日志中可以看出,正则表达式在JS中可以正常工作,但是在antd中,该模式就不行了。
另外,我关注了this,并正确添加了type="regexp"
还缺少什么?
【问题讨论】:
-
“另外,我遵循了这个并且我正确地添加了 type="regexp" " - 它需要被删除而不是添加。您可以在那里查看附加的代码沙箱:)
-
@blueseal 啊...确实 xD 谢谢
标签: javascript regex antd