## 7.5 Validation Non Domain and Command Object 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 Annotation

Classes which define the static constraints property and are marked with the @Validateable annotation may be made validateable by the framework. Consider this example:

    // src/groovy/com/mycompany/myapp/User.groovy
    package com.mycompany.myappimport org.codehaus.groovy.grails.validation.Validateable@Validateable
    class User {
        ...    static constraints = {
            login(size:5..15, blank:false, unique:true)
            password(size:5..15, blank:false)
            email(email:true, blank:false)
            age(min:18, nullable:false)
        }
    }

You need to tell the framework which packages to search for @Validateable classes by assigning a list of Strings to the grails.validateable.packages property in Config.groovy.

    // grails-app/conf/Config.groovy...grails.validateable.packages = ['com.mycompany.dto', 'com.mycompany.util']...

The framework will only search those packages (and child packages of those) for classes marked with @Validateable.

#### Registering Validateable Classes

If a class is not marked with @Validateable, it may still be made validateable by the framework. The steps required to do this are to define the static constraints property in the class (as described above) and then telling the framework about the class by assigning a value to the grails.validateable.classes property in Config.groovy.

    // grails-app/conf/Config.groovy...grails.validateable.classes = [com.mycompany.myapp.User, com.mycompany.dto.Account]...