Skip to main content
Version: 4.x

Failing with a message

When running enforce you can specify a custom failure message to be thrown on failure. This is done via the message modifier. All you need to do is add the message before the rules it refers to.

If a message is provided, it will override the default message of all rules that follow it.

enforce(value)
.message('Value must be a number')
.isNumber();
.message('Value must be positive')
.isPositive();