How to Set Acrobat JavaScript Validation for Values Between 100 and 400,000
Question details
The user needs a mathematical validation method for a PDF form field so that it only accepts values between 100 and 400,000 that are exact multiples of 100.

- Product
- PDF Form
- Device & OS
- not provided
- Scenario
- Creating custom validation rules for fillable PDF form fields to restrict user numeric input dynamically without listing every single valid number.
- Observed behavior
- A mathematical validation method using JavaScript is required to validate specific value ranges and multiples.
Ensure you are using a PDF editor that supports form field creation and JavaScript execution, and verify that your target text field is designated for numeric input.
Use the Modulo Operator in a Custom Validation Script
Apply a custom JavaScript validation script to the form field to dynamically check if the entered number falls within the required range and is a multiple of 100.
Instead of manually defining thousands of valid entries, you can utilize JavaScript's modulo operator (%). The modulo operator calculates the remainder of a division operation, allowing you to easily verify if an entered number is an exact multiple of 100.
Open your PDF form in edit mode, right-click the target text field, and select 'Properties' from the context menu.
In the Text Field Properties dialog box, click on the 'Validate' tab to set up input restrictions.
Select the 'Run custom validation script' option and click the 'Edit' button to open the JavaScript editor.
Type the following script: `if (event.value) { var v = Number(event.value); if (v < 100 || v > 400000 || v % 100 != 0) { app.alert("The entered value must be at least 100 and a multiple of 100."); event.target.textColor = color.red; } else { event.target.textColor = color.black; } }`
Click 'OK' to save the script, close the properties window, and exit edit mode to test the form field with various numbers.

Manage and Fill PDF Forms with WPS Office
WPS Office provides comprehensive PDF tools to read, edit, and fill interactive PDF forms smoothly. It handles complex form validations seamlessly and serves as a powerful, lightweight alternative for your daily document tasks.
- 1. Open Your PDF: Launch WPS Office and open the PDF document containing the interactive forms.
- 2. Access Form Tools: Navigate to the 'Form' or 'Fill & Sign' tab to access tools specifically designed for interactive documents.
- 3. Fill the Data: Click on the designated fields and enter your data; any embedded JavaScript validations will execute automatically.
- 4. Save the Document: Once completed, click 'Save' to preserve your inputs or export the filled form to share with others.

Frequently Asked Questions
What does the modulo operator (%) do in JavaScript validation?
The modulo operator returns the remainder of a division operation. In form validation, checking if a value modulo 100 equals zero ensures the entered number is an exact mathematical multiple of 100.
Why does my custom validation script not trigger when I type?
Ensure that the script is placed under the 'Validate' tab of the field properties, rather than the 'Calculate' or 'Format' tabs. Validation scripts only trigger when the user commits the data by clicking outside the field or pressing Enter.
How do I revert the text color to normal after an invalid entry?
The provided script handles this automatically using the `else` block: `event.target.textColor = color.black;`. This line resets the text color to black as soon as a valid number is entered into the field.
Can I use this script for different number ranges?
Yes, you can easily customize the script by modifying the variables in the `if` statement. Simply change the `< 100` and `> 400000` values to match your specific minimum and maximum limits.




