-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Michael Edgar edited this page Apr 26, 2018
·
4 revisions
Validators is a Java library for Bean validation covering common validation scenarios without the baggage of additional third-party dependencies.
Use the @DateTime
constraint to validate that a sequence of characters matches at least one of the date patterns provided.
class TestBean {
@DateTime(patterns = "yyyy-MM-dd", message = "Invalid ISO date")
String isoDate;
public Date getIsoDate() {
try {
return new SimpleDateFormat("yyyy-MM-dd").parse(isoDate);
} catch (ParseException e) {
// Exception will not occur if the bean instance has been validated successfully.
}
return null;
}
}
The @Expression
constraint should be used in scenarios where either multiple fields must be considered or where slightly more complicated logic is necessary to check for an individual field's validity.