Known Participant
April 23, 2021
Answered
Date validation based on dd/mm/yyy
- April 23, 2021
- 2 replies
- 1648 views
Hi all,
I have a date field where I need users to insert the exact date in format dd/mm/yyyy. I configured a custom Date field with the above format, but it seems if the users insert other formats like dd/mm, these formats are accepted and the current year is automatically displayed, while it's not assigned in the underlying field (please refer to the attachment).
I thought to configure a validation to ensure date is inserted with all its parts, and I used the following validation script which seems not working:
var myDate = event.target.valueAsString;
var DD = myDate.substr(0,2);
var MM = myDate.substr(3,2);
var YYYY = myDate.substr(6,2);
if ( (DD > 31 || DD < 1) || (MM > 12 || MM < 1) || (myDate.length != 10) || (myDate.substr(2,1) != "/") || (myDate.substr(5,1) != "/") )
{app.alert({ cMsg: "Please insert the full date in format dd/mm/yyyy", cTitle: "" });
event.rc = false;}. Any help is really appreciated.
Thanks
Simone
