Skip to content

Custom Validation Messages Per Validator #189

@jmar777

Description

@jmar777

In some cases it would be useful to override the validation message on a per-validator basis. As an example, it is currently difficult to meet application requirements for user-facing error messages that include regular expressions (which output the regular expression itself in the error message).

Not sure what the best API would be, but here's an example of what I'm trying to propose:

var message = '{{key}} must be a hex color code';

var schema = {
    color: Joi.string().regex(/^#[a-fA-F0-9]{6}$/, { message: message ))
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions