我的所有验证均具有以下内容:
const validations = {
password: {
presence: true
},
confirmPassword:{
equality: {
attribute: "password",
message: "Passwords do not match",
comparator: function(v1, v2) {
return v1 === v2
}
}
}
}
我想单独显示错误,所以我有以下内容:
let passwordError = validate('password', this.state.password);
let confirmPasswordError = validate("confirmPassword", { confirmPassword: this.state.confirmPassword, password: this.state.password});
密码验证效果很好。确认密码的存在验证有效,但相等性检查无效。
最佳答案
已经使用 console.log 检查变量 v1 和 v2 的值了吗?例如对我来说变量 v1 即将到来:
{confirmPassword:"12345", 密码:"12345"}
然后就做:
v1.confirmPassword === v1.password
关于javascript - 验证 js 确认react-native的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56028063/