reactjs - 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;
}
解决方案
试试这个,即使我遇到了同样的问题。希望它也适用于你。
const minLengthName = minLength(5);
现在像这样调用验证:
validate={[minLengthName, required ]}
推荐阅读
- python - 获取包含 3 个单词的短语
- php - Symfony 可选电话条目验证完整性错误:列“电话”不能为空
- ios - IOS中ArcGis地图中的长按手势
- sql - 关联的分区函数生成的分区多于方案中提到的文件组
- python - 预训练模型的层输出意外地产生不同的输出
- c++ - 为什么别名 int& 允许创建非函数类型 const (int&)?
- migration - Magento 从 1.9.3.2 迁移到 2.2.3 类别更改后不保存
- java - 画布到图像绘制不成功
- c# - Crystal Report Asp.net 打印选项
- ssis - SSIS 表达式在 IF 之前清空所有内容