Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 16
  • module version: 17.7.0
  • environment (e.g. node, browser, native): browser
  • used with (e.g. hapi application, another framework, standalone, ...): React

How can we help?

I have an input that can be either a phone number or an email. I'm used alternatives.try to achieve this, but I want to have different message for when the input is empty string and when it's not empty but also doesn't match to phone or email. How can I do this? The alterntatvies.match just give the same message for both situations.

  Joi.alternatives()
      .try(
        Joi.string().email({ tlds: { allow: false } }),
        Joi.string().pattern(
          /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/i
        )
      )
      .messages({
        'alternatives.match': 'Invalid input',
      })
0
© 2022 pullanswer.com - All rights reserved.