I need to add input validation for Dates entered by users. There is a startDate and endDate. The startDate needs to be current date or later. The endDate needs to be equal to OR after the startDate.
The date format i am using is YYYY-MM-dd
Already validating that the date is a proper date
In the request class we currently are using javax.validation like this:
@Pattern(regex = CommmonRegexp.DATE, message = "INVALID_FIELD")
How do i edit this to fit my needed constraints?
What i need: validate input for both dates making sure startDate only accepts current date or later, and endDate accepts only dates later than startDate
SimpleDateFormat
. That class is notoriously troublesome and long outdated. And since your format is the default ISO 8601 for aLocalDate
from java.time, the modern Java date and time API, use that class, and you don’t need any explicit formatter. - Ole V.V.SimpleDateFormat
, then check for boundaries with proper methods. - Luis Colorado