Copy link to clipboard
Copied
I am trying to get an error message to pop up if date entered is less than 3 weeks from the current date. Can anyone provide javascript code for this?
Copy link to clipboard
Copied
You need to use a custom validation script like:
if(event.value != "")
{
var oEnteredDate = util.scand("d-mmm-yyyy", event.value); // convert entered value to JS date object;
if(oEnteredDate == null)
{
app.alert("Entered date is not a valid date.", 1, 0);
event.rc = false;
} else {
var nEnteredDays = Math.floor(oEnteredDate.getTime() / (1000 * 60 * 60 * 24)); // convert entered date to days since Epoch date;
var oSysDate = new Date(); // get current system dateobject;
oSysDate.setFullYear(oSysDate.getFullYear(), oSysDate.getMonth(), oSysDate.getDate(), 0, 0 ,0, 0); // set date to midnight;
console.println(oSysDate);
var nSysDays = Math.floor(oSysDate.getTime() / (1000 * 60 * 60 * 24)); // convert system date to days since Epoch date;
if(nEnteredDays - nSysDays < 27)
{
// current is less than 27 days from current date;
app.alert("Enterd days is less than 3 weeks from the current date.\nPlease reeneter.", 1, 0);
event.rc = false;
} // less than 27 days;
} // valid date inputted;
} // end entry not null string;
You will need to adjust format used in the script for the entered date to match the format for your date field's format.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now