Java Reference
In-Depth Information
Using ${ } in Expressions
Enclose the validation expression within
${ }
, or don't—the
choice is yours. Indeed,
expression="this < today"
and
expres-
sion="${this < today}"
are equivalent. Stripes automatically adds
${ }
for you if you leave it out.
Personally, I prefer using
${ }
because I find it makes it clearer
that an EL expression is being used. Whichever format you
choose, being consistent will certainly make your code more
readable.
prefix and a four-digit suffix, as in
(654) 456-4567
. To be lenient with our
users, we'll allow some flexibility with the input format:
• The parentheses around the area code are optional.
• The separators between each part of the phone number can be
hyphens, periods, or spaces, or they can be omitted altogether.
For example, all these phone numbers are acceptable:
(654) 456-4567
654-456-4567
654 456 4567
654.456.4567
(654)456 4567
6544564567
654 4564567
654.456-4567
Adding this validation is easy by building a regular expression mask
with the following constructs:
•
\(?
and
\)?
to represent an optional opening and closing paren-
thesis
•
[-. ]?
to accept an optional hyphen, period or space
•
\d
to represent a digit
•
{N}
to indicate the previous construct repeated
N
times
With these constructs, we can validate the phone number by adding
the following mask. Since the regular expression is in a Java
String
, we
have to use
\\
to represent
\
.
@ValidateNestedProperties({
/
*
previous validations...
*
/
@Validate(field="phoneNumber",
mask="\\(?\\d{3}\\)?[-. ]?\\d{3}[-. ]?\\d{4}")
})
Search WWH ::
Custom Search