首页 > 解决方案 > redux-form 验证:最小长度和匹配密码

问题描述

我正在尝试验证匹配的密码并确认密码和最小输入长度。这是我的代码:

<Field
              name='password'
              label='Password'
              component={renderField}
              as={Form.Input}
              type='password'
              icon='lock'iconPosition='left'
              placeholder='Password'
              validate={[minLength(5), required ]}/>
              <Field
                  name='password1'
                  label='Confirm Password'
                  icon="lock" iconPosition='left'
                  component={renderField}
                  as={Form.Input}
                  type='password'

                  placeholder='Confirm'
                  validate={[passwordValidate, required ]}/>

我不知道为什么它不起作用。这是我的验证码:

export const passwordValidate  = (value, allValues) =>
{
    value !== allValues.password ? 'Password does not match' : undefined;
}

export const minLength = len => value =>
{
    value && value.length < len ? `Must have greater than ${len}` : undefined;
}

标签: reactjsreduxredux-form

解决方案


试试这个,即使我遇到了同样的问题。希望它也适用于你。

const minLengthName = minLength(5);

现在像这样调用验证:

validate={[minLengthName, required ]}

推荐阅读