4

Following is (a part of) my JSP:

<fieldset data-role="fieldcontain">
  <label id="labelForDob" for="dob">Date of birth (dd/mm/yyyy)</label>
  <form:input path="dob" cssErrorClass="errorField" />
  <form:errors path="dob" cssClass="errorMessage" />
</fieldset>

Following is (a part of) my form bean:

    @DateTimeFormat(pattern = "dd/MM/yyyy")
    @NotNull
    @Past(message = "enter a past date in the format of dd/mm/yyyy")
    private Date dob;

When I enter a string in the wrong format (that cannot be converted to Date), conversion error message is displayed (see figure bellow):

enter image description here

How can I customise this message? (Something like "Your input cannot be converted to a date")

Community
  • 1
  • 1
siva636
  • 16,109
  • 23
  • 97
  • 135

1 Answers1

-2

Their are four options you can adopt:

  1. Instead of using the input text for the date. Always use the date type field for the date.You can use
    < input type="date" text="dateOfBirth" pattern="dd/MM/yyyy">< /input> So that use will have an option to select a date from calendar only.

  2. You can write a javascript on the blur event for the input box so that when user will leave that field you can prompt him to enter current date.

  3. You can have regular expression in javascript to check the pattern.

  4. You can put regular expression in input type itself like: pattern="\d{1,2}/\d{1,2}/\d{4}"

Kapil Dave
  • 126
  • 1
  • 6