Validating using regular expressions
Regular expressions provide a powerful technique for validating fields. Phone numbers and Zip codes can be easily verified using regular expressions. The @Pattern annotation allows us to use a regular expression to verify the correct usage of these types of fields.
We will use the
LicenseBeanFacade classes from the
ValidationApplication as discussed in the Validating persistent fields and properties recipe.
In order to illustrate the use of regular expressions we need to define allowable values for the restrictions field. This field may hold a combination of values reflecting driving constraints such as:
- C Requires the use of corrective lenses
- A Must be accompanied by an adult driver ...