2 Replies Latest reply on Dec 2, 2014 7:47 AM by Nagannudj

    Help with a date field script

    Nagannudj

      Sorry if this is a repeat. I was interrupted and found that my browser had crashed when I came back so I'm not sure if the question got asked.

       

      I need a script for a date field (mm/dd/yyyy) where the user can only fill in a date that is between 12/31/1899 and the current date (whatever the date when the form is opened). I'm getting better at writing these but I haven't been successful with this one. Any help would be greatly appreciated.

       

      Thanks!

        • 1. Re: Help with a date field script
          try67 MVP & Adobe Community Professional

          I have a feeling I already answered this question some time ago... Anyway, you can use this code as the field's custom validation script:

           

          var minDate = util.scand("mm/dd/yyyy", "12/31/1899");
          var maxDate = new Date();
          event.rc = true;
          if (event.value) {
              var d = util.scand("mm/dd/yyyy", event.value);
              if (d<minDate || d>maxDate) {
                  app.alert("Error! The entered date must be between " + util.printd("mm/dd/yyyy", minDate) + " and " + util.printd("mm/dd/yyyy", maxDate));
                  event.rc = false;
              }
          }
          
          • 2. Re: Help with a date field script
            Nagannudj Level 1

            Thank you so much! Exactly what’s needed.