Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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?

Guest
Jan 10, 2017 Jan 10, 2017

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?

TOPICS
Acrobat SDK and JavaScript
253
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2017 Jan 10, 2017
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines