Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Need help in date Validation Urgent

Avatar

Level 3

Hi ,

We need help in Date Validation.

we have 2 Date fields on the form Start Date, End Date

The requirement is: End Date (May not be greater than 30 years from the start date).

I have written following script on End Date Exit event. But the problem is its calculating 30 years from the Current Date not from the Start Date

var

tDate = util.scand("mm/dd/yyyy", new Date());

var

M = tDate.getMonth();

var

D = tDate.getDate();

var

Y = tDate.getFullYear();

var

SRes = util.printd("yyyy-mm-dd", new Date((Y+30), M,D) );

//app.alert(SRes)

if

(SRes <= this.rawValue)

{

app.alert("May not be greater than 30 years from the start date")

xfa.host.setFocus(

this);

}

can someone please help me

Regards,

Jay

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi,

You'll need to get javascript date from LCD field, and calculate & compare with the future date in javascript date.

try following script;

var sDate = StartDate.rawValue;
var wkStartDate = util.scand("yyyy-mm-dd", sDate);

var nYear = wkStartDate.getFullYear();
var nMonth = wkStartDate.getMonth();
var nDay = wkStartDate.getDate();

var wkFutureDate = new Date(nYear  + 30 , nMonth, nDay);

sDate = EndDate.rawValue;
var wkEndDate = util.scand("yyyy-mm-dd", sDate);

if (wkEndDate.getTime() > wkFutureDate.getTime()){
  xfa.host.messageBox("May not be greater than 30 years from the start date");
  xfa.host.setFocus(this);
}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 2

Hi,

You'll need to get javascript date from LCD field, and calculate & compare with the future date in javascript date.

try following script;

var sDate = StartDate.rawValue;
var wkStartDate = util.scand("yyyy-mm-dd", sDate);

var nYear = wkStartDate.getFullYear();
var nMonth = wkStartDate.getMonth();
var nDay = wkStartDate.getDate();

var wkFutureDate = new Date(nYear  + 30 , nMonth, nDay);

sDate = EndDate.rawValue;
var wkEndDate = util.scand("yyyy-mm-dd", sDate);

if (wkEndDate.getTime() > wkFutureDate.getTime()){
  xfa.host.messageBox("May not be greater than 30 years from the start date");
  xfa.host.setFocus(this);
}

Avatar

Level 3

Thank you,

It's working perfect...

Regards,

Jay