Question

I have a DateTextField component in my application and I want the input of date using a predefined pattern. The pattern that I need is "yyyy-MM-dd". I created the DateTextField using the following code.

    DateTextField dtf_ExpiryDate = DateTextField.forDatePattern("ExpDate", "yyyy-MM-dd");
    dtf_ExpiryDate.add(new DatePicker());

It helps to prevent date input in most of other formats. But it accepts input in dd-MM-yyyy format and converts it into some weird format. For example, 12-06-2013 is automatically converted to 0012-06-20.

Is there a way to throw an error when the date is given in dd-MM-yyyy ?

Javadocs of DateTextField says that the conversion is done internally using the Joda time parser. Is there a way to add more constraints ?

I really don't want the data to be captured as String and add a StringValidator to check if it confirms to the pattern using Regex.

Thank you

Was it helpful?

Solution

As far as I know, the answer is NO. DateTextField uses DatePattern or DateStyles internally and it is not possible to enforce stricter rules. If you don't want to use Javascript (custom) or JQuery, you have to use a REGEX to validate the input.

Have a look at here. Use the StrictPatternDateConverter class shown below to enforce a strict validation for the input.

OTHER TIPS

Yep! StringRegExp is a good solution. But another solution could be the use of jqWicket. It provides a MaskedInputBehavior. Take a look at: http://code.google.com/p/jqwicket/wiki/MaskedInputExample

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top