4 Replies Latest reply on Jun 21, 2012 12:00 AM by alexandrahiston

    PDF form field validation - 2 criterias?

    alexandrahiston

      Does anyone know how can I get a numerical pdf form field to validate within a range as well as validate that the value is equal to or less than the value of another numerical field?

       

      Thanks!

        • 1. Re: PDF form field validation - 2 criterias?
          George_Johnson MVP & Adobe Community Professional

          That's possible, but what do you want to happen if the other field is blank, and what are the values for range's min, max, as well as max value of the other field?

          • 2. Re: PDF form field validation - 2 criterias?
            alexandrahiston Level 1

            Hi,

             

            The min is 0 and max is 2,000,000

            The other field will need to have a numerical value (can't be blank if they want to use the 2nd field) - it has no max, so I guess the order of the validation would be the 2,000,000 max after the equal or less than the 1st field? I'm not great at javascript, so don't know how to format this at all!

             

            If you can help at all, that would be great.

            • 3. Re: PDF form field validation - 2 criterias?
              George_Johnson MVP & Adobe Community Professional

              I think the following custom Validate script will do what you want:

               

              function range_validate1() {

               

                  // Do nothing if field is blank

                  if (!event.value) {

                      return;

                  }

                 

                  // Initialize some variables

                  var sError = "";

                  var nMin = 0;

                  var nMax2 = 2e6;

                  var nVal = +event.value;  // Value user entered, converted to a number

               

                  // Get the other field value, converted to a number

                  var nMax1 = +getField("Text1").value;

                 

                 

                  // If the value is less than the minimum

                  if (nVal < nMin) {

                      sError = "Please enter a value greater than or equal to: " + nMin;

                  }

                 

                  // If value exceeds the other field value...

                  if (nVal > nMax1) {

                      sError = "Please enter a value less than or equal to: " + nMax1;

                  }

               

                  // If value exceeds the max. possible value   

                  if (nVal > nMax2) {

                      sError = "Please enter a value less than or equal to: " + nMax2;

                  }

               

                  // Alert the user and reject the value

                  if (sError) {

                      app.alert(sError, 0);

                      event.rc = false;

                  }

               

              }

               

              // Call the function

              range_validate1();

               

               

              The function can be placed in a document-level JavaScript, but the last line should be the custom Validate script for the field. Replace "Text1" in the line containing the getField statement to the actual name of the other field.

              • 4. Re: PDF form field validation - 2 criterias?
                alexandrahiston Level 1

                Genius - thank you so much for your help, that worked brilliantly!