validate confirmation password in redux form

孤人 提交于 2020-02-05 06:34:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!