object with type { telegram?: string; whatsApp?: string } validate this object use yup…
- User
object with type { telegram?: string; whatsApp?: string } validate this object use yup with rule: one of telegram or whatsApp must be not empty
- Assistant
To validate an object with a schema that requires at least one of the fields
telegramorwhatsAppto be not empty using Yup, you can utilize the.test()method to create a custom validation rule.First, ensure you have Yup installed. If not, you can install it via npm or yarn:
- User
Rewrite this code using when
- Assistant
Certainly! You can use the
whenmethod in Yup to create conditional validations. Here's how you can rewrite the schema to ensure that at least one oftelegramorwhatsAppis not empty using thewhenmethod:javascript - User
add validation rule for telegram, if telegram is empty then nothing else matches regex
- Assistant