PDF Editing Issues

How to Restrict PDF Text Fields to Allow Only Numbers or Letters

Natalie TaylorNatalie Taylor Oct 28, 2026 869 views

Question details

The user wants to format PDF form text fields to strictly accept either numerical inputs only or alphabetical letters only.

How to Restrict PDF Text Fields to Allow Only Numbers or Letters
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating or editing an interactive PDF form where strict data validation is required for certain text fields.
Observed behavior
By default, PDF text fields allow users to type any characters. The user needs to enforce specific character types (letters or numbers) to prevent invalid data entry.
Before you start

Ensure you have a PDF editor with advanced form creation and JavaScript capabilities, such as Adobe Acrobat Pro, installed on your computer.

Solution 1Recommended

Apply Custom Keystroke Scripts to PDF Text Fields

Use the form field's Properties dialog to add a short JavaScript validation snippet that restricts input to numbers or letters as the user types.

Acrobat allows you to use regular expressions (Regex) within a custom keystroke script to validate what characters the user is allowed to enter into a form field in real-time.

1
Enter Prepare Form Mode

Open your PDF document in Acrobat. Go to the 'Tools' menu and select 'Prepare Form' to activate form editing mode.

2
Open Field Properties

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

3
Navigate to the Format Tab

In the Properties dialog box, click on the 'Format' tab. From the 'Select format category' dropdown menu, choose 'Custom'.

4
Add the Custom Keystroke Script

Click the 'Edit' button next to the 'Custom Keystroke Script' box. To allow numbers only, paste the following code: event.rc = /^\d*$/.test(AFMergeChange(event)); To allow letters only, use: event.rc = /^[a-z]*$/i.test(AFMergeChange(event)); Click 'OK' and then 'Close' to save your changes.

Apply Custom Keystroke Scripts to PDF Text Fields
Test Your Form: After applying the script, click the 'Preview' button in the top right corner to test the text field. Ensure that invalid keystrokes are properly blocked.
Powerful PDF Form Editor

Create and Manage PDF Forms Easily with WPS Office

WPS Office provides a comprehensive PDF toolkit that allows you to easily edit text, insert form fields, and manage interactive PDFs. It is fully compatible with standard PDF formats and makes building professional forms a breeze.

  1. 1. Open Your PDF: Download and install WPS Office, then open your PDF document within the application.
  2. 2. Navigate to the Form Tab: Click on the 'Form' tab in the top menu bar to access the interactive form tools.
  3. 3. Insert Form Fields: Select 'Text Field' and click anywhere on the document page to insert a new interactive input field.
  4. 4. Customize Field Settings: Double-click the newly created field to access its properties, where you can customize its appearance, name, and default values.
Easily insert and modify text fields, checkboxes, and drop-down menusHighly compatible with Adobe Acrobat PDF formsLightweight, fast, and easy to useSupports cross-device document editing and seamless sharing
microsoft office alternative - wps office

Frequently Asked Questions

Why is my custom keystroke script not working in my PDF form?

Ensure you have enabled JavaScript execution in your PDF viewer's security preferences. Additionally, double-check that there are no syntax errors in your script and that you placed it specifically in the 'Custom Keystroke Script' section under the Format tab, rather than the validation or calculation sections.

Can I restrict the text field to a specific number of characters?

Yes. In the text field Properties dialog, navigate to the 'Options' tab. You can check the 'Limit of [ ] characters' box and enter the maximum number of characters allowed for that specific field.

How do I format a text field as a date or currency instead of using a script?

In the text field Properties dialog, go to the 'Format' tab. Click the 'Select format category' dropdown menu and choose 'Number' for currency and decimal formats, or 'Date' for specific date layouts. Built-in formats do not require any manual custom scripting.