使用DateBox小部件进行完整日期值验证的最佳方法是什么?
以下只是防止不完整输入,如"1.1.“,但允许例如:"333.333.333”
final DateTimeFormat format = DateTimeFormat.getFormat("dd.MM.yyyy");
dateBox.setFormat(new DefaultFormat(format));有什么建议吗?
发布于 2013-01-24 16:33:32
就像这样:
try {
Date date = DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).parseStrict(value);
// Do something with date
} catch (IllegalArgumentException e) {
// Show error message
}显然,您可以使用不同的格式,或者,如果允许用户自由地输入日期(如1/1/2013、Jan 1, 2013、January 1, 2013等),则可以尝试逐一解析所有格式。
https://stackoverflow.com/questions/14506104
复制相似问题