PDF Editing Issues

How to Show an Alert When Non-Numeric Text Is Entered in a PDF Form

Adam DavisAdam Davis Nov 5, 2026 871 views

Question details

The user needs to configure a PDF form field to display a pop-up alert if someone tries to enter letters or other non-numeric characters.

How to Show an Alert When Non-Numeric Text Is Entered in a PDF Form
Product
Adobe Acrobat / PDF Forms
Device & OS
not provided
Scenario
Creating or editing an interactive fillable PDF form that requires strict numeric data entry from the end-user.
Observed behavior
The form needs to reject invalid characters and trigger an active warning message guiding the user to input numbers only.
Before you start

Ensure your PDF editing software supports JavaScript for form fields and that you have already inserted the target text field into your document.

Solution 1Recommended

Use a Custom JavaScript Validation Script

You can apply a regular expression (RegEx) script within the form field's properties to check the input and trigger an alert box if non-numeric characters are detected.

By using a custom validation script, you have complete control over the input rules. The script runs instantly as soon as the user finishes typing and clicks outside the field.

1
Access Form Field Properties

Open your PDF in edit mode. Right-click the text field you want to restrict and select 'Properties' from the context menu.

2
Navigate to the Validate Tab

In the Properties dialog box, click on the 'Validate' tab at the top.

3
Select Custom Validation Script

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

4
Enter the Validation Code

Type the following script into the editor: var pattern = /^[0-9]+$/; if (event.value && !pattern.test(event.value)) app.alert("Please enter a number.");

5
Save and Test

Click 'OK' to close the editor, then close the Properties dialog. Exit form editing mode and test your field by typing a letter to see if the alert appears.

Use a Custom JavaScript Validation Script
Customizing for Decimals: If you need to allow decimal points, update the pattern to allow the period character, for example: var pattern = /^[0-9.]+$/;

Easily Format PDF Form Inputs with WPS Office

While custom JavaScript is powerful, WPS Office offers an intuitive PDF form builder where you can easily restrict text fields to numeric inputs without writing any code.

  1. 1. Open Your PDF in WPS Office: Launch WPS Office and open your PDF document.
  2. 2. Enter Form Editing Mode: Navigate to the 'Form' tab on the top ribbon and click on 'Edit Form'.
  3. 3. Open Field Properties: Double-click the text field you want to modify to open its Properties panel.
  4. 4. Set the Format to Number: Go to the 'Format' tab, select 'Number' from the category drop-down list, and customize your decimal rules. WPS Office will automatically handle the validation.
No coding required to restrict field input formatsHighly compatible with Adobe Acrobat PDF form standardsLightweight and fast PDF editing and reading experienceFree built-in tools for filling and managing PDF forms
microsoft office alternative - wps office

Frequently Asked Questions

How do I allow spaces or dashes in my numeric form field?

You can modify the regular expression in your JavaScript to include spaces and dashes. For example, changing the pattern to /^[0-9 -]+$/ will allow numbers, spaces, and hyphens, which is useful for phone numbers.

Why isn't my JavaScript alert showing up when I test the form?

This usually happens if JavaScript is disabled in your PDF viewer's settings. Go to your PDF reader's Preferences, locate the JavaScript section, and ensure 'Enable Acrobat JavaScript' is checked.

Can I apply this validation rule to multiple fields at once?

Yes. You can either select multiple fields, right-click to open their combined properties, and apply the script to all of them, or define a document-level JavaScript function and call that function from each field.