Skip navigation
alexandrahiston
Currently Being Moderated

PDF form field validation - 2 criterias?

Jun 20, 2012 6:50 PM

Tags: #javascript #acrobat_forms

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!

 
Replies
  • George Johnson
    9,208 posts
    Aug 11, 2002
    Currently Being Moderated
    Jun 20, 2012 8:19 PM   in reply to alexandrahiston

    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?

     
    |
    Mark as:
  • George Johnson
    9,208 posts
    Aug 11, 2002
    Currently Being Moderated
    Jun 20, 2012 11:56 PM   in reply to alexandrahiston

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points