11 Replies Latest reply on May 9, 2017 1:59 PM by Joel_Geraci

    Date validation to allow only current dates in date field.

    Heliosoz

      Hey Everyone,

       

      I'm trying to validate a date field(mm/dd/yyyy) against user input in my Adobe Acorbate form. The date field should only allow the current date, no future/past dates. Here's my code that prevents future / past dates depending on the greater than or less than condition.

      if (event.value != "") {
      var d = util.scand("mm/dd/yyyy", event.value).getTime();
      d = d - (d % 1000); 
      var nNow = new Date().getTime();
      nNow = nNow - (nNow % 1000); 
      if (d < nNow) {
      app.alert("You may not enter a date in the past.");
      event.rc = false;}
      }
      

       

      The issue I'm facing is that in each scenario the current date is excluded, it will either have to be a day before today or a day after today. So with the code above for example I cannot enter 05/09/2017 even though it isn't a past date, the code recognizes it as it is. I've tried where d != nNow and that didn't work either.

       

      I'm trying to enforce validation where the user can only enter the current date, hope someone can help.

       

      Thanks!