Skip to content
zhaber edited this page Jul 28, 2012 · 4 revisions

A validator is a function that examines its input with respect to some requirements and produces a boolean result which indicates whether the input successfully passed the validation. This snippet shows how to implement a validator that tests if the supplied value is even:

boolean even(long value) {
  value % 2 == 0
}

The return type of a validator should be boolean or Boolean. The other option to indicate a failed validation result is using a ValidationException (see the Error Handling chapter)

The first validator's parameter is called a processed value parameter, as it represents a value of a parameter processed by a current rule.