Skip to content

Override rule message with any.message() rule #1264

@dwelle

Description

@dwelle

I propose we add any.message() type to allow to define custom language on a granular level as such:

Joi.string()
    .min( 2 )
        .message("must be at least 2 letters long")
    .max( 255 )
        .message("must be up least 255 letters long")
    .regex(/somePattern/)
        .message("must consist of only this and that...")
    .regex(/someForbiddenPattern/, { invert: true })
        .message("must not contain something...")
    .regex(/someOtherForbiddenPattern/, { invert: true })
        .message("must not contain somethign else...")

Currently, it's either super inconvenient to define via .options({ language: { .... } }), or, such is in this case, impossible (AFAIK) due to multiple .regex types using the same language.

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions