Skip to main content
Every constraint reports a message for people, in English by default, such as must have at least 2 characters. Change it in three places, from the broadest to the narrowest.

For the whole application

messages { } in the configuration changes the default message of a constraint everywhere. Each message is a property named after the constraint:
The others keep their default. The messages reference lists all of them, with their defaults and placeholders.

For one call

The same block inside Validity { } changes them for one validation only, which is how a server answers each request in its own language:

For one rule

Every constraint takes a message, which replaces the default for that call:
Constraints that take an argument also accept a message built from the value, for a message that depends on it:

Placeholders

A message can use placeholders in braces, filled in when the violation is built:
A placeholder the message has no value for is left as it is, so a typo shows up in the message instead of failing.

The message of a constraint is not always its name

Most messages are named after their constraint, but a few constraints share a name across types and need different words. The size rules of a map count entries, not items, and the Boolean rules cannot be named isTrue: The constraints reference gives the message of every constraint. The code of the violation is always the name of the constraint.

Messages of a country

The constraints of each country have their messages in a block of their own:
The blocks are brazil, bulgaria, canada, france, israel, netherlands, pakistan, poland, russia, slovenia, spain, thailand, ukraine and unitedStates.

Messages of a module

A module such as validity-phone adds its own block to messages:

Messages of your own constraints

Your custom constraints can have configurable messages too. Hold them in a class, declare a MessagesKey for it, and read the current messages from the key:
Users then change them in the same configuration, with module:
MessagesKey.current reads the messages of the configuration that is validating, so Validity { } for one call works for them too.