gpt4 book ai didi

javascript - 如何在 React Js 中设置匹配密码

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:21 25 4
gpt4 key购买 nike

我需要一些帮助如何在 React js 中匹配密码。我使用了 ant design,第一个密码有效,但为了符合密码,我声明它不起作用,我该怎么做

handlePasswordChange = event => {
this.setState({
password: event.target.value,
});
};
handleConfirmPassword = event => {
if (event.handleConfirmPassword !== event.handlePasswordChange) {
message.error('error');
}
};

这些很有趣,下面是 Ant 设计

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

最佳答案

假设您的密码和确认密码都处于状态。

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

关于javascript - 如何在 React Js 中设置匹配密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51143800/

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