How to apply client side validation for date format to input text field?
Application Type
Traditional Web

I have input text field to enter the date. I have set local variable to it which data type is text. But I want to force user that enter date in this format (dd/MM/yyyy). 

Hi Ajith,

In this case also, OutSystems will understand and apply the "date" value as "text". You can set the local variable data type as "date or date time" and pass it over API.. API will understand the "date" value as "text". 

Add the prompt value ("Date format should be dd/MM/yyyy") to the input field. Then alert the user by validation message, "The date has been considered as 10-OCT-2021". Before API action also you can validate the date text using if condition.

You can convert the text to date if required in your process. 

TextToDate()

Hope this helps you..

Thanks, Aadhavan S

Hi Ajith,

For this you can write check condition on onchange client action. But how system will understand if the date is 10/10/2021 (MM/dd/yyyy) during validation?

Better you have to set variable data type as "date". else system will assume your date as a month or month as a date. OutSystems itself understand the "date" variable to "text". you don't need to define data type.

Try to follow OutSystems best practices to avoid these kind of situations.

Thanks, Aadhavan S

Hello Aadhavan,

Thanks for the reply and always you giving me the better solutions.

But here I don't want to change the data type. I have consume rest API where date datatype is text. Here I want to force user to enter the text in the format I have mentioned in question.

Could you please find out any solution for this one.

Regards,

Ajit Kurane.

Hi Ajith,

In this case also, OutSystems will understand and apply the "date" value as "text". You can set the local variable data type as "date or date time" and pass it over API.. API will understand the "date" value as "text". 

Add the prompt value ("Date format should be dd/MM/yyyy") to the input field. Then alert the user by validation message, "The date has been considered as 10-OCT-2021". Before API action also you can validate the date text using if condition.

You can convert the text to date if required in your process. 

TextToDate()

Hope this helps you..

Thanks, Aadhavan S

Hi @Ajit Kurane ,

If I understood correctly, is this that you want?

Hello Luis,

Many thanks for replying.

I haven't used date picker. User is typeing date manually. And input textbox by default prompting there that date should be in "dd/MM/YYYY" format. In case user type date in different format then it should prompt error that "invalid date format" 

I hope you are getting my query.

Kind Regards,

Ajit Kurane 

Hi @Ajit Kurane ,

I didn't understand that. So based on that you can use the regex for example or made a cache action to convert the date and validate it. Here is a sample with the 2 approachs.

Regards,

Luis Oliveira


CheckDate.oml

Hello Ajit,

You can put up a regular expression to match the format of the date that you are getting into that text box.
This action is available in the in-built Text (extension) of OutSystems. Just add it as a dependency and use it.


I suggest you to use action Regex_Search, and based on the boolean result of the action, you can design the validation logic. 

I hope that will resolve the issue.

Regards,
Nikhil

Champion

Hi Ajit,
Despite all the good answers above :)

Here's one more approach to restricting the user to input only date in the format as you required & validating the same as well.

Sample:
https://assif.outsystemscloud.com/DateManual/Sample?_ts=637661207829409226


PFA OML; There's a JS Snippet.
Note: Validation/ Preparation Assignment can be refined when we convert same to WB.

Hope it helps,
Assif


DateManual.oml

Hi Ajit,

Based on your use case I would suggest you to use Custom Input Masks Forge component you can find link below.

Also, I have attached demo application how you can implement it.

https://www.outsystems.com/forge/component-overview/647/custom-input-masks

Hope it helps solve your problem.

Regards,

Allan Kedari

TestInputMask.oap

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.