GWT Date Check

What is the best way to check the full date using a DateBox widget?

The following simply 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?

+5
source share
1 answer

Something like that:

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 the formats one by one if you allow your users to freely enter dates as 1/1/2013, as well as Jan 1, 2013, January 1, 2013etc.

+4
source

All Articles