Validating string fields
Strings are used extensively in many Java applications. When strings are persisted to a database, the database column may be restricted in size. The entity can use annotations to enforce a size constraint of these fields.
We will use the
LicenseBeanFacade classes from the
ValidationApplication as discussed in the Validating persistent fields and properties recipe.
How to do it...
We can specify the size of a String using the @Size annotation. This annotation has a
min and a
max attribute. The
min attribute specifies the minimum length allowed while the
max attribute specifies the upper bound on the length of the string. Here we specify a minimum length of 12 characters and a maximum length of ...