3 Replies Latest reply on May 9, 2012 6:10 AM by Formzet - Zoetermeer

    Date validation

    Formzet - Zoetermeer Level 1

      I had to cut a date field into 3 pieses ( [day] [month] [year] )

      Now i have to validate the date, but i don't know how.

      I create a script to combine the field values into a new hidden field to perform te validation.

       

      event.value = vDay.value + "-" + vMonth.value + "-20" + vYear.value;
      

       

      It works, but i get a standard error message.

       

      I want to perfom a custom validation with an custom error message and to reset the fields when input is wrong.

       

      Can anyone help me with this script?

      I don't know how to perform date validations in Acrobat/Javascript

        • 1. Re: Date validation
          try67 MVP & Adobe Community Professional

          Do you just mean that you want to check if the input is a valid date or

          not? The best way to do that is to try to convert it to a Date object,

          using util.scand(). If the result is null, then it was not a valid date

          string. For example (I'm assuming here that vDay, vMonth and vYear are

          variables pointing to field objects):

           

          var dateString = vDay.value + "-" + vMonth.value + "-20" + vYear.value;

          var dateObject = util.scand("dd-mm-yyyy", dateString);

          if (dateObject==null) {

          app.alert("Error! This is not a valid date.");

           

          • 2. Re: Date validation
            gkaiseril MVP & Adobe Community Professional

            What is the "standard" error you are getting?

             

            Have you tried to use the JavaScript console in Acrobat to see the values you are trying to process?

             

            Is the month value the 3 character string or a number?

             

            Are you subtract the number 20 or concatenate the text character string "-20"?

             

            You could add the following script to a button and then press the button to see what happens as you  enter data into your fields:

             

            console.show();

            console.clear();

            var vDay = this.getField("vDay");

            var vMonth = this.getField("vMonth");

            var vYear = this.getField("vYear");

            console.println("vDay: " + vDay.value);

            console.println("vMonth: " + vMonth.value);

            console.println("vYear: " + vYear.value);

            var dateString = vDay.value + "-" + vMonth.value + vYear.value;

            console.println("dateString: " + dateString)

            var dateObject = util.scand("dd-mm-yyyy", dateString);

            console.println("dateObject: " + dateObject);

             

            Once you see what is happening with just the fields you can work on building up a more complex script.

            1 person found this helpful
            • 3. Re: Date validation
              Formzet - Zoetermeer Level 1

              @try67

               

              Works perfect.

              Just what i'm looking for

              Thank you