Bean Validation for @Past or today?
Asked Answered
H

2

11

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?

Horbal answered 19/3, 2011 at 4:1 Comment(0)
H
16

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.

Horbal answered 19/3, 2011 at 14:22 Comment(2)
Hmm, I'm not sure about that. Or at least it's not true anymore. You have to use @PastOrPresent instead.Tango
using @Past does not work for GET requests in Spring, any other methods for validating Date passed in a GET Method requestGrown
C
6

To get past and today you can use

@PastOrPresent
Crying answered 20/4, 2020 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.