I want to validate password using ant design with react. But, ant design doesn't have any validation.How can I do that ? Please help me.
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>
);
});
What do you like best about Ant Design React? Its very easy to use and well documented which help to easily implement and use. ANT provide almost all type of components and design which is required to create an website.
Use validator rule:
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>
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