Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT DateBox validation

Tags:

gwt

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?

like image 974
Jens Piegsa Avatar asked Oct 05 '22 06:10

Jens Piegsa


1 Answers

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.

like image 69
Andrei Volgin Avatar answered Oct 10 '22 04:10

Andrei Volgin