11.6 Applying Validation to Other Classes 3.0.10

See the light - agile, industrial strength, rapid web application development made easy

(Quick Reference) # 11.6 Applying Validation to Other Classes - Reference Documentation Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari Version: 3.0.10 ## 11.6 Applying Validation to Other Classes Domain classes and command objects support validation by default. Other classes may be made validateable by defining the static `constraints` property in the class (as described above) and then telling the framework about them. It is important that the application register the validateable classes with the framework. Simply defining the `constraints` property is not sufficient. #### The Validateable Trait Classes which define the static `constraints` property and implement the Validateable trait will be validateable. Consider this example:

    // src/groovy/com/mycompany/myapp/User.groovy
    package com.mycompany.myappimport grails.validation.Validateableclass User implements Validateable {
        ...    static constraints = {
            login size: 5..15, blank: false, unique: true
            password size: 5..15, blank: false
            email email: true, blank: false
            age min: 18
        }
    }
| Quick Reference (hide)