PDF Editing Issues

How to Validate That One PDF Form Field Is Greater Than Another

Muhammad TalhaMuhammad Talha Oct 28, 2026 869 views

Question details

The user needs to set up a validation rule in a fillable PDF form to ensure that Field B is always equal to or greater than Field A, avoiding a negative calculation result.

How to Validate That One PDF Form Field Is Greater Than Another
Product
PDF
Device & OS
not provided
Scenario
Creating or editing a PDF form where one field calculates the difference between two other fields, and the resulting value must be restricted to positive numbers.
Observed behavior
A PDF form calculates Field B minus Field A, but there is currently no restriction preventing a negative result when Field A exceeds Field B.
Before you start

Ensure you are using a PDF editor that supports JavaScript form properties and verify the exact names of the fields (e.g., Field A, Field B, and Result Field) before writing the script.

Solution 1Recommended

Add a Custom JavaScript Validation to the Calculation Field

Apply a custom JavaScript snippet to the result field's validation properties to alert the user immediately if the calculated value falls below zero.

By targeting the result field, you can capture the calculation the moment it happens. If the script detects a negative number, it triggers a warning popup to prompt the user to correct their input.

For stricter data control, consider adding similar validation checks to Field A and Field B independently, so entries are evaluated as soon as the user types them.

1
Open Field Properties

Open your PDF form in edit mode, right-click the calculated result field, and select Properties from the context menu.

2
Navigate to the Validate Tab

In the Properties dialog box, click on the Validate tab to access data restriction settings.

3
Choose Custom Script

Select the 'Run custom validation script' option, and click the Edit button to open the JavaScript editor.

4
Enter the Validation Code

Input the following script: if (Number(event.value) < 0) app.alert("The value in Field B must be the same as or greater than the value in Field A.");

5
Save and Test

Click OK to save the script, close the Properties window, and test your form by entering a higher value in Field A than in Field B to ensure the alert triggers.

Add a Custom JavaScript Validation to the Calculation Field
Real-time Field Updates: To prevent invalid entries entirely, you can apply this script pattern to validate both fields on the 'blur' event, stopping bad data before the calculation even runs.
Edit and Validate PDF Forms Easily

Use WPS PDF to Create and Manage Fillable Forms

WPS Office offers a comprehensive PDF editor that allows you to effortlessly build fillable forms, set up field calculations, and manage advanced properties.

  1. 1. Open your PDF document: Launch WPS Office and open your fillable PDF file using the WPS PDF tool.
  2. 2. Access the Form tools: Navigate to the Form tab on the top ribbon to view all interactive field editing options.
  3. 3. Edit field properties: Double-click the specific text field you want to modify to open the Interactive Form Field Properties panel.
  4. 4. Set calculations or validations: Switch to the Calculate or Validate sections to apply custom formulas or restrict input ranges.
  5. 5. Save changes: Close the properties panel and save the PDF file to apply the new field rules.
Easily insert text fields, checkboxes, and calculation fields into any PDF document.Fully compatible with standard Adobe Acrobat PDF form properties and JavaScript validations.Intuitive interface for quickly testing and adjusting form field logic.Lightweight architecture ensures smooth performance when editing complex multi-page forms.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF form calculation returning a negative number?

If your formula subtracts Field A from Field B, and the user inputs a larger number in Field A, the mathematical result is naturally negative. A validation script is required to restrict this behavior and alert the user.

Do I need to know JavaScript to add validation rules to PDF forms?

Basic restrictions (like number ranges) can often be set via standard dropdown menus in field properties. However, comparing two fields against each other requires copying and pasting a brief JavaScript snippet into the Custom Validation field.

Are PDF form JavaScript validations compatible with all PDF readers?

Most major desktop PDF readers, including Adobe Acrobat, Foxit, and WPS PDF, fully support JavaScript form calculations and alerts. However, some basic browser-based PDF viewers or mobile apps might not execute advanced custom scripts.

Can I hide the calculation field if the result is negative?

Yes, you can modify the custom calculation script to clear the field entirely or hide it if the result drops below zero, instead of just displaying an alert dialog.