What is the best way to do a full date value validation using the DateBox widget?
The following just prevents incomplete input like "1.1." but allows for example: "333.333.333"
final DateTimeFormat format = DateTimeFormat.getFormat("dd.MM.yyyy");
dateBox.setFormat(new DefaultFormat(format));
Any suggestions?
Something like this:
try {
Date date = DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).parseStrict(value);
// Do something with date
} catch (IllegalArgumentException e) {
// Show error message
}
You can use a different format, obviously, or you can try to parse all formats one by one if you allow your users a freedom to enter dates as 1/1/2013
as well as Jan 1, 2013
, January 1, 2013
, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With