Reputation: 3989
In my play1.2.4
app,I need to make sure that a customer's MembershipCard
is valid at the moment of processing.Validity is determined by the expiry month and expiry year
together.
If the MembershipCard is
class MembershipCard extends Model{
public String memberShipNumber;
public String expiryMonth;
public String expiryYear;
}
In controller method which takes the user selected card details(from a dropdown list),I need to make sure that the card is valid.
The String values for ,say the month of January
is '1'
.For current year ,it will be '2012'
.
How can I do the validation on these fields?Do I need to write a custom validator? or can I use the built in 'InFuture
' validation ?(since that one is made for date comparisons)
Can someone please help?
Upvotes: 2
Views: 239
Reputation: 16439
Use a custom validator, it seems a better option as the InFuture validation will require you to transform the Strings to Dates in the request.
EDIT on comment
There is a sample in the source code of Play, the EqualsCheck validator. Create your own version and apply it using @CheckWith annotation.
Upvotes: 1