10

Here's a simple source, stating that this date must be in the past using Bean Validation :

@Past
private Date transactionDate;

Is there any BV annotation for validating that the date must be today or previous day?

Or perhaps I need to extend the constraint and provide my own?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Bertie
  • 17,277
  • 45
  • 129
  • 182

2 Answers2

15

Just found out the answer for this, @Past means today or any day before today.

So, using @Past suits my need without having to provide my own constraint.

Bertie
  • 17,277
  • 45
  • 129
  • 182
  • 7
    Hmm, I'm not sure about that. Or at least it's not true anymore. You have to use `@PastOrPresent` instead. – bagage Aug 22 '18 at 12:38
  • using @Past does not work for GET requests in Spring, any other methods for validating Date passed in a GET Method request – DaviesTobi alex Dec 23 '20 at 09:15
6

To get past and today you can use

@PastOrPresent
Dharman
  • 30,962
  • 25
  • 85
  • 135
prakash joy
  • 79
  • 1
  • 3