PDF Editing Issues

How to Allow Only Positive Numbers in a PDF Form Field

Kushani NimanthikaKushani Nimanthika Oct 28, 2026 869 views

Question details

The user needs to restrict a numeric PDF form field so that it rejects negative values and only accepts zero or positive numbers.

How to Allow Only Positive Numbers in a PDF Form Field
Product
PDF Editor
Device & OS
not provided
Scenario
Creating or editing an interactive PDF form that requires positive numeric input for accurate data collection.
Observed behavior
By default, a numeric field may accept negative values. The goal is to enforce a validation rule that prevents negative inputs from being accepted.
Before you start

Ensure you have access to a PDF editor with advanced form editing capabilities, such as Adobe Acrobat Pro or a tool that supports custom JavaScript field validation.

Solution 1Recommended

Use a Custom JavaScript Validation Script

Add a simple JavaScript validation code to the form field's properties to instantly reject any negative number input.

By utilizing custom JavaScript in the field's properties, you can trigger a warning message and clear the input whenever a user attempts to enter a negative value. This ensures your collected data meets specific numerical requirements.

1
Enter Form Editing Mode

Open your PDF form in your PDF editor and navigate to the 'Prepare Form' or 'Form Editing' tool.

2
Access Field Properties

Right-click the specific numeric field you want to restrict and select 'Properties' from the context menu.

3
Navigate to the Validate Tab

In the Properties dialog box, click on the 'Validate' tab to configure input rules.

4
Add the Custom Script

Select 'Run custom validation script' and click the 'Edit' button. Enter the following code: if (Number(event.value) < 0) { app.alert("You must enter only positive numbers."); event.rc = false; }

5
Save and Test

Click 'OK' to save the script, close the Properties dialog, and test the form field by entering a negative number to ensure the alert appears.

Use a Custom JavaScript Validation Script
Efficient PDF Form Management

Handle PDF Forms Seamlessly in WPS Office

WPS Office provides powerful PDF tools that allow you to fill, edit, and manage interactive PDF forms with ease. It's a comprehensive suite designed to handle all your document workflows efficiently.

  1. 1. Open the PDF Form: Launch WPS Office and open your interactive PDF form document.
  2. 2. Fill the Fields: Navigate through the document and simply click on the highlighted interactive fields to type your data.
  3. 3. Save and Share: Once completed, click the 'Save' icon to preserve your filled data, or export it to share with others.
Fully compatible with standard PDF forms and fieldsEasily fill interactive fields including text and numeric inputsLightweight and fast PDF reading and editing experienceHigh compatibility with Adobe Acrobat PDF formats
microsoft office alternative - wps office

Frequently Asked Questions

Why does my validation script not trigger when I enter a negative number?

Ensure that the form field format is explicitly set to 'Number' in the Format tab of the Properties dialog, and check that JavaScript execution is enabled in your PDF reader's security preferences.

What happens if a user tries to type text instead of numbers?

If the field format is set to 'Number' in the Format tab, the PDF viewer will automatically reject non-numeric characters before the validation script even runs.

Will this JavaScript validation work on mobile PDF readers?

JavaScript support varies heavily across mobile PDF viewers. While it works perfectly on desktop software like Adobe Acrobat and WPS Office, some basic mobile PDF apps might ignore custom validation scripts.

Can I customize the error message shown to the user?

Yes. In the JavaScript code, you can change the text inside the quotes of the app.alert("...") function to display any custom message you prefer.