How to Show an Alert When Non-Numeric Text Is Entered in a PDF Form
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.

- 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.
Ensure your PDF editing software supports JavaScript for form fields and that you have already inserted the target text field into your document.
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.
Open your PDF in edit mode. Right-click the text field you want to restrict and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Validate' tab at the top.
Choose the option 'Run custom validation script' and click the 'Edit' button to open the JavaScript editor.
Type the following script into the editor: var pattern = /^[0-9]+$/; if (event.value && !pattern.test(event.value)) app.alert("Please enter a number.");
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.

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. Open Your PDF in WPS Office: Launch WPS Office and open your PDF document.
- 2. Enter Form Editing Mode: Navigate to the 'Form' tab on the top ribbon and click on 'Edit Form'.
- 3. Open Field Properties: Double-click the text field you want to modify to open its Properties panel.
- 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.

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.




