gpt4 book ai didi

reactjs - 我想使用 ant design 的 React 来验证密码

转载 作者:行者123 更新时间:2023-12-03 14:07:40 30 4
gpt4 key购买 nike

我想使用 ant design 和 React 来验证密码。但是,ant design 没有任何验证。我该怎么做呢?请帮助我。

 const LoginForm = Form.create()(props => {
const { getFieldDecorator } = props.form;
return (
<Form onSubmit={props.onSubmit} className="form-size form-margin">
<FormItem>
{getFieldDecorator("email", {
rules: [
{
type: "email",
message: "The input is not valid E-mail!"
},
{ required: true, message: "Please input your username!" }
]
})(<Input placeholder="Email" />)}
</FormItem>
<FormItem>
{getFieldDecorator("password", {
rules: [{ required: true, message: "Please input your Password!" }]
})(<Input type="password" placeholder="Password" />)}
</FormItem>
<FormItem>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
</FormItem>
<span style={{ color: "red" }}>
{props.loginStatus ? "" : props.loginMessage}
</span>
</Form>
);
});

最佳答案

使用validator规则:

  const validatePassword = (rule, value, callback) => {
if (value && value !== "Secret") {
callback("Error!");
} else {
callback();
}
};

<FormItem>
{getFieldDecorator("password", {
rules: [
{ required: true, message: "Please input your Password!" },
{ validator: validatePassword }
]
})(
<Input
type="password"
placeholder="Password"
/>
)}
</FormItem>

关于reactjs - 我想使用 ant design 的 React 来验证密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51203041/

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