// /////////////////////////////////////////////
// Validation Support.
// ////////////////////////////////////////////
// Cannot book anyone younger than 18 or older than 100.
Validator crimeValidator = new DateRangeValidator(offsetDate(100),
offsetDate(18));
ValidatorController crimeValidation = ValidatorController.addAsFocusListener(
birth, crimeValidator);
// Crime codes must be correctly formatted.
ValidatorController.addAsFocusListener(crimeCode, crimeCodeFormatValidator);
// Phone numbers can be pushed into shape if they are almost correctly
// formatted.
ValidatorController.addAsFocusListener(phone, new USPhoneValidator());
// Creates a custom validator.
Validator statuteValidator = createStatuteValidator(crimeCode);
// Can add the same validator to multiple subjects to do multi-field
// validation.
crimeValidation.addValidator(statuteValidator);
ValidatorController.addAsFocusListener(dateOfCrime, statuteValidator);
// Cannot book someone for a crime more than 30 years old.
ValidatorController.addAsFocusListener(dateOfCrime, new DateRangeValidator(
offsetDate(30), new Date()));
}