如何在反应Js中设置匹配密码 [英] How to set match password in react Js
本文介绍了如何在反应Js中设置匹配密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些帮助,如何匹配反应js中的密码。我使用ant设计第一个密码正在工作但是为了符合一致的密码我把声明它不工作我怎么能这样做
I need some help how could I match the password in react js. I used ant design the first password is working but for conform password I put statement its not working how could I do it
handlePasswordChange = event => {
this.setState({
password: event.target.value,
});
};
handleConfirmPassword = event => {
if (event.handleConfirmPassword !== event.handlePasswordChange) {
message.error('error');
}
};
这些很有趣,下面是蚂蚁设计
these are fun and below is the ant design
<FormItem {...styles.formItemLayout} label="Password">
{getFieldDecorator('Password', {
rules: [{ required: true, message: 'Password is Required!' }],
})(
<Input
onChange={this.handlePasswordChange}
name="password"
type="password"
value={password}
style={styles.margin}
/>,
)}
</FormItem>
<FormItem {...styles.formItemLayout} label="Confirm Password">
{getFieldDecorator('Confirm Password', {
rules: [{ required: true, message: 'Confirm your Password!' }],
})(
<Input
name="password"
type="password"
style={styles.margin}
onChange={this.handleConfirmPassword}
/>,
)}
</FormItem>
推荐答案
假设您的密码和confirmPassword都处于状态。
Assuming that both your password and confirmPassword are in state.
this.state = {
password: '',
confirmPassword: ''
}
handleSubmit = () => {
const { password, confirmPassword } = this.state;
// perform all neccassary validations
if (password !== confirmPassword) {
alert("Passwords don't match");
} else {
// make API call
}
}
这篇关于如何在反应Js中设置匹配密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文