I have a Java EE application and I want to check the date. Using String, I do this:
import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; ... @NotNull @Size(min = 1, max = 255) private String myString;
But now I have two dates that I want to check. The user can write a string in a text field in the interface system that will be transmitted via JSON (I have to use a text field, I cannot use datepicker).
So my backend has this in my domain class:
@DateTimeFormat(pattern = "dd.MM.yy") @Temporal(value=TemporalType.TIMESTAMP) private Date myStartDate; @DateTimeFormat(pattern = "dd.MM.yy") @Temporal(value=TemporalType.TIMESTAMP) private Date myEndDate;
I want to check for the format "dd.MM.yyyy". How can I do that?
And, I donโt think so, but is there an automatic check to check if there is a start date before the end date? I found only @Future and @Past .
So the only solution is to use @Pattern, regex ?!
Thank you in advance for your help, best regards.
Tim
source share