问题
How to validate password confirmation in react form?
const validate = values => {
const errors = {};
if (!values.username) {
errors.username = 'Required';
}
if (!values.password) {
errors.password = 'Required';
}
if (!values.confirmpassword ) {
errors.confirmpassword = 'Required' ;
}
return errors;
};
export default validate;
Here is my validation page I tried confirm password validation during mismatches occurs... That doesn't works.. Is there anyone willing to help me??
回答1:
Try the following logic.
const validate = values => {
const errors = {};
if (!values.username) {
errors.username = 'Required';
}
if (!values.password) {
errors.password = 'Required';
}
if (!values.confirmpassword ) {
errors.confirmpassword = 'Required' ;
} else if (values.confirmpassword !== values.password) {
errors.confirmpassword = 'Password mismatched' ;
}
return errors;
};
export default validate;
来源:https://stackoverflow.com/questions/49671188/validate-confirmation-password-in-redux-form