以 redux 形式验证确认密码 [英] validate confirmation password in redux form

查看:68
本文介绍了以 redux 形式验证确认密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以反应形式验证密码确认?

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

推荐答案

试试下面的逻辑.

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;

这篇关于以 redux 形式验证确认密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆