Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to override validation error message with our own custom message #231

Open
neeraj87 opened this issue Oct 12, 2022 · 0 comments
Open

Comments

@neeraj87
Copy link

Code:

import Joi from 'joi';
import joiPhoneNumber from 'joi-phone-number';

const customJoi = Joi.extend(joiPhoneNumber);
const joiresponse = customJoi.string().phoneNumber({ defaultCountry: 'US', format: 'e164', strict: true }).validate('+11111111111').messages({
      'value.invalid':
        'Please enter a valid phone number',
    });
console.log(joiresponse);

I get the following error

customJoi.string(...).phoneNumber(...).validate(...).messages is not a function","stack":"TypeError: customJoi.string(...).phoneNumber(...).validate(...).messages is not a function

Is there a way to add our own custom message for validation error? Currently the message I receive says

"value" did not seem to be a phone number"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant