Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

How can I prevent the entry of a future date in my date field?


Former Community Member

I have a date field in my form (created w/ Adobe Lifecycle Designer v8.0) and I need to prevent users from entering a future date (current or past date is okay). Ideally, if a future date is entered, an error message pops up and tells the person that a future date is not acceptable. Does anyone know how to do this or have any suggestions to try?


2 Replies


Level 5
Hope the following JS code helps you..........

var checkDate = isCurrOrPastDate(this.rawValue)

if (checkDate == true) {

//xfa.host.messageBox("This date is valid current or past date.");

}else {

xfa.host.messageBox("Date can not be a future date");

xfa.host.setFocus(this.somExpression); //set focus back to the data field.


function isCurrOrPastDate(dateStr) {

var dto = dateStr;

var iLen1 = String(dto).length;

var DD = dto.substring(iLen1, iLen1 - 2);

DD = DD.replace(/^\s*|\s*$/g,"");


var MM = dto.substring(5,7)

var YYYY = dto.substring(0,4);

//xfa.host.messageBox(""+DD+" "+MM+" "+YYYY);

//return false;

var date1 = new Date(MM+"/"+DD+"/"+YYYY);//new Date(month+"/"+day+"/"+year);


var today = new Date();

var ddf = dateDifference(today,date1);

//xfa.host.messageBox("ddf: "+ddf);

if (ddf <= 0) {

//xfa.host.messageBox("This date is valid current or past date.");

return true; // date is valid


//xfa.host.messageBox("Date can not be a future date");

return false; // date is not valid


function dateDifference(strDate1,strDate2){

datDate1= Date.parse(strDate1);

datDate2= Date.parse(strDate2);


return (datDate2-datDate1)/(24*60*60*1000);



Level 2

hi Annie,

place the below code in the exit event of the date field and script language should be FormCalc


($.rawValue <> null )



num = IsoDate2Num($.rawValue)-Date()


( num > 0 )


$host.messageBox("Invalid Date and cannot be Future Date")


= ""

$host.setFocus("your field path")



Note : your field path for example your date field name is futuredate under subform name body then place body.futuredate.

if you want to resrict not to enter past date then compare num with < 0 or to current date then compare num with = 0.