cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Date validation

Former Member
0 Likes
2,430

How can I restrict user to enter date in only dd/mm/yyyy format? I tried regular expression in datepicker but it is too complex for others if they want to make modifications. Please help me resolve this. Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

boghyon
Product and Topic Expert
Product and Topic Expert

This answer suggests to use binding type instead (such as 'sap.ui.model.odata.type.DateTime') which restricts the input value to be stored in the model if it could not be parsed or validated.

Example:

<DatePicker placeholder="DD/MM/YYYY" value="{
  path: 'myODataModel>myDate',
  type: 'sap.ui.model.odata.type.DateTime',
  formatOptions: {
    pattern: 'dd/MM/yyyy'
  },
  constraints: {
    isDateOnly: true,
    displayFormat: 'Date'
  }
}"

The value will be always displayed in the dd/MM/yyyy pattern. But the model stores the value in JS-Date object (Internally, the thirdparty lib datajs will convert it again to OData conform format before it's sent).

Finally, register the control in the message manager to activate automatic message generation as shown in the documentation topic UI Messages.

Sample JSBin: https://jsbin.com/seyutiw/edit?js,output

_____________

If the model is not an ODataModel but just a plain JSONModel:

<DatePicker placeholder="DD/MM/YYYY" value="{
  path: 'myJSONModel>myDate',
  type: 'sap.ui.model.type.Date',
  formatOptions: {
    pattern: 'dd/MM/yyyy'
  }
}"
Former Member
boghyon
Product and Topic Expert
Product and Topic Expert
0 Likes

pavankumaran#overview

The error message you were getting was due to the missing comma which I fixed in the above answer. I also added another snippet in case the "Project" model is a JSONModel instead of OData. You can check the JSBin sample I added to the answer.

Please try again and let us know if this solution was helpful.

Answers (1)

Answers (1)

0 Likes

Hi Pavankumar A N,

Use the given Properties in Date Picker

valueFormat and displayFormat

< DatePicker valueFormat="dd.MM.yyyy" >

BR

Arun Mathew

Former Member
0 Likes

Thank you Arun for the response, we tried all these but we can create a record with 124341/123312/123431 this value also. Can you please help me resolve this?

0 Likes

In date picker, you can select the date from the calendar instead of enter the value.

0 Likes

go through the following link it may help you out!..

Date Picker

BR,

Arun Mathew.