Custom `Yup` validation messages

See here for the original answer.

One way you can do this is via regex, by accepting any value that is not "none":

const NewUserSchema = Yup.object().shape({
  createDate: Yup.string().nullable().required('Create date is required'),
  boughtby: Yup.string().matches(/^(?!none).*$/, "Cannot be none").required("Cannot be none")
});

Tags

  1. nodejs (Private)
  2. react (Private)
  3. yup (Private)
  4. stack-overflow (Private)
  5. answer (Private)