相关疑难解决方法(0)

Yup 模式中的可选字段验证

我正在使用react-hook-formwithyup进行表单验证,并希望某些字段是可选的(空)。

按照他们的文档,我正在使用nullable()optional()但它仍在验证中:

export const updateAddressSchema = yup.object({
  address: yup
    .string()
    .nullable()
    .optional()
    .min(5, "Address must be more than 5 characters long")
    .max(255, "Address must be less than 255 characters long"),
  city: yup
    .string()
    .nullable()
    .optional()
    .max(32, "City name must be less than 32 characters long"),
  postal_code: yup
    .string()
    .nullable()
    .optional()
    .length(10, "Postal code must be 10 characters long"),
  phone: yup
    .string()
    .nullable()
    .optional()
    .min(10, "Phone number must be more than 10 characters …
Run Code Online (Sandbox Code Playgroud)

html javascript validation reactjs yup

9
推荐指数
2
解决办法
3万
查看次数

标签 统计

html ×1

javascript ×1

reactjs ×1

validation ×1

yup ×1