You then use method calls that match the property name for which the constraint applies in combination with named parameters to specify constraints:

    In this example we’ve declared that the property must be between 5 and 15 characters long, it cannot be blank and must be unique. We’ve also applied other constraints to the password, email and age properties.

    Note that constraints are only evaluated once which may be relevant for a constraint that relies on a value like an instance of java.util.Date.

    It’s very easy to attempt to reference instance variables from the static constraints block, but this isn’t legal in Groovy (or Java). If you do so, you will get a MissingPropertyException for your trouble. For example, you may try

    In this example, the obj argument to the custom validator is the domain instance that is being validated, so we can access its survey property and return a boolean to indicate whether the new value for the answer property, , is valid.