Skip to content

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

@neeraj87

Description

@neeraj87

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions