Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

Not applicable
Hi,



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?



Thanks,

Annie
2 Replies
_SekharN_
Level 5
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,"");

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

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);

//xfa.host.messageBox(""+date1);

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);

//app.alert(""+(datDate2-datDate1)/(24*60*60*1000));



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

}
madhu_livecycle
Level 2
Level 2

hi Annie,

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

if

($.rawValue <> null )

then

var

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

if

( num > 0 )

then

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

$.rawValue

= ""

$host.setFocus("your field path")

endif

endif

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.

Thanks,

Madhu.