Announcement Announcement Module
No announcement yet.
Date Field Validation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date Field Validation

    I'm trying to use commons-validators to validate the date filed in my form.

    I'm using a custom editor for the date which is:
    binder.registerCustomEditor(Date.class,null, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
    In the validation.xml file I wrote:
                    <form name="invoice">
    			<field property="date" depends="date">
    				<arg0 key="Date"/>
    Now, 1- if i leave the date field empty no error occurs and the form is submitted successfully.

    2- If I entered any value for example 2 , I get the following:
    Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'date'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "2"

    3- The error message appears only if I enter the value in the following format: 2-3-4
    After submitting the value in the date field is converted to : 0002-03-04
    and the following error message appears:
    Date is not a date.

    What I want to do is that whatever the format of the value entered in the date field is, since it is not the correct format or if it is left empty the error message should appear.

    How could this be done?

    Thanks in Advance.