PDF Editing Issues

How to Validate a PDF Form Field Against Values in Other Fields

Maira MehtabMaira Mehtab Nov 3, 2026 869 views

Question details

The user needs to validate a PDF form field by comparing its input against values calculated from other fields using a JavaScript validation script.

How to Validate a PDF Form Field Against Values in Other Fields
Product
PDF Editor
Device & OS
not provided
Scenario
Setting up custom form field validation rules using JavaScript in an interactive PDF document.
Observed behavior
To ensure accurate validation, the script must properly quote field names, parse values as numbers, and reject input that falls outside calculated boundaries.
Before you start

Ensure you have access to PDF form editing tools and basic knowledge of JavaScript. Double-check the exact names of the form fields you intend to reference, as field names are case-sensitive.

Solution 1Recommended

Implement JavaScript Validation with Correct Type Conversion

Use JavaScript to fetch other field values, convert them to numbers, and compare them against the current input to validate the entry.

When writing custom validation scripts in PDFs, text values must be explicitly converted to numbers to ensure mathematical comparisons work correctly. Omitting quotation marks around field names or failing to convert strings to numbers are the most common causes of script failure.

1
Retrieve Field Values

Use quotation marks around every field name when fetching them. For example, use this.getField('FieldName').value to read the contents of the target field.

2
Convert to Numbers

Convert the retrieved field values to numbers using the Number() function before using them in any calculations to avoid string concatenation issues.

3
Calculate Bounds

Perform your mathematical calculation to establish the upperbound and lowerbound limits based on the numeric values.

4
Apply Validation Condition

Write an if-statement to check whether event.value is greater than the upperbound or less than the lowerbound.

5
Reject Invalid Entries

If the condition is met and the value is outside the permitted range, set event.rc = false within your script. This tells the PDF viewer to reject the user's input.

Implement JavaScript Validation with Correct Type Conversion
Testing the Script: After saving your script, switch to the form preview or hand tool and test the validation by intentionally entering numbers outside the permitted range.
Easily Manage PDF Forms

Create and Edit PDF Forms with WPS Office

WPS Office provides a comprehensive PDF Editor that allows you to effortlessly create, edit, fill, and manage interactive PDF forms without needing complex coding.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in PDF Editor.
  2. 2. Access Form Tools: Navigate to the Form tab on the top ribbon to view all available form creation and editing tools.
  3. 3. Edit or Fill Forms: Click on existing fields to modify their properties, or add new text fields to design your interactive document.
  4. 4. Save and Export: Once your form is set up, save the document to ensure all interactive fields and properties are securely preserved.
Easily insert text fields, checkboxes, and drop-down menus into your PDFs.Highly compatible with standard PDF forms and Adobe Acrobat files.Lightweight software with an intuitive, user-friendly interface.Available across Windows, Mac, and mobile platforms.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF form validation script ignoring the upper and lower limits?

This typically happens if the field values are treated as text strings instead of numbers. Ensure you use JavaScript functions like Number() to convert the field values before performing greater-than or less-than mathematical comparisons.

How do I reject an invalid entry in a PDF form using JavaScript?

You can reject an invalid entry by evaluating the input against your conditions and setting event.rc = false; in your custom validation script. This natively instructs the PDF viewer to discard the user's input.

Does WPS PDF support JavaScript validation in forms?

WPS PDF supports viewing, filling, and creating interactive forms. While basic field formatting and calculations are broadly supported, the execution of highly advanced custom Adobe Acrobat JavaScript validations may vary depending on the specific functions used in the document.