【发布时间】:2022-10-16 00:00:33
【问题描述】:
我正在使用 Yup 和 Formik 作为我的注册表单。不知何故,在我的密码上使用 Yup 提供的修剪方法时,没有出现错误消息,而所有其他验证方法都正常工作。
这是我的 Yup 架构的密码部分:
password: Yup.string()
.required('Password is required)
.min(8, 'Password must be at least 8 characters long')
.max(18, 'Password cannot be longer than 18 characters')
.matches(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])/,
'Password must contain at least one number as well as one uppercase, lowercase, and special character'
)
.trim('Password cannot include leading and trailing spaces')
.matches(
/^(?!.* )/,
'Password cannot contain two or more consecutive spaces'
)
【问题讨论】: