PDF Editing Issues

How to Restrict an Acrobat Text Field to Specific Letters

Kushani NimanthikaKushani Nimanthika Nov 3, 2026 869 views

Question details

The user wants to restrict a PDF text field to accept only specific uppercase letters (e.g., A, C, or D) and reject any invalid input without using a drop-down list.

How to Restrict an Acrobat Text Field to Specific Letters
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Designing a PDF form where a specific text field has limited space (only wide enough for one letter), making drop-down arrows problematic, and requiring strict control over what characters can be typed.
Observed behavior
A method is needed to prevent invalid characters from being typed in real-time and to validate the input immediately when the user leaves the text field.
Before you start

Ensure you have access to the 'Prepare Form' tool in Adobe Acrobat and possess basic familiarity with adding custom JavaScript to form field properties.

Solution 1Recommended

Implement JavaScript Validation and Keystroke Scripts

Add regular expressions to the text field properties to control exactly what users can type and validate it when they exit the field.

Using a combination of a keystroke script and a validation script ensures the best user experience. The keystroke script prevents invalid characters from being typed in real-time, while the validation script acts as a final check when the user attempts to click away or tab out of the field.

1
Open Form Preparation

Open your PDF in Adobe Acrobat and select the 'Prepare Form' tool from the right-hand pane.

2
Access Field Properties

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

3
Add Validation Script

Navigate to the 'Validate' tab, select 'Run custom validation script', and enter the following code: if (event.value) event.rc = /^[ACD]$/.test(event.value); (Modify A, C, and D to the specific uppercase letters you wish to allow).

4
Add Keystroke Script

Navigate to the 'Format' tab, choose 'Custom' from the Select format category dropdown, and enter this custom keystroke script: event.rc = /^[ACD]?$/.test(AFMergeChange(event));

5
Save and Test

Click 'Close' to save the properties. Exit the 'Prepare Form' mode by clicking 'Preview' at the top right to test your restricted field.

Implement JavaScript Validation and Keystroke Scripts
Understanding the Regular Expressions: The expression ^[ACD]$ ensures that the field contains exactly one character and it must be A, C, or D. The keystroke script includes a ? to allow the field to temporarily be empty while the user is typing.
Free Microsoft Office alternative

A Lightweight Alternative for PDF and Office Tasks

While complex JavaScript form validation requires advanced Adobe Acrobat features, WPS Office provides a free, lightweight, and highly compatible alternative for everyday PDF editing, form filling, and document management. Experience a seamless transition with a familiar UI and broad format support.

  1. 1. Download and Install: Get WPS Office for free from the official website and follow the easy installation prompts.
  2. 2. Open Your Documents: Launch WPS Office, click on 'Open', and select any PDF, DOCX, XLSX, or PPTX file.
  3. 3. Edit and Manage: Use the integrated PDF tools to fill forms, highlight text, or convert PDFs directly into editable Word documents.
Fully compatible with standard PDF formats and Microsoft Office files (Word, Excel, PowerPoint).Lightweight design ensures fast performance without slowing down your system.Familiar, intuitive interface requires zero learning curve.Free to download with an all-in-one suite for everyday productivity tasks.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't the Acrobat keystroke script work when users paste text into the field?

Keystroke scripts typically trigger only on keyboard input. To ensure pasted text is also validated and rejected if invalid, you must include the validation script (which runs when the field loses focus). This acts as a safety net to catch pasted invalid characters.

Can I restrict an Acrobat text field to accept numbers only?

Yes. You can change the Regular Expression in your JavaScript. For example, using /^[0-9]+$/ in your validation script will restrict the field to accept only numeric values.

How do I allow both uppercase and lowercase letters in the text field?

You can modify the Regular Expression to include lowercase letters. For instance, changing /^[ACD]$/ to /^[a-cA-C]$/ will permit both cases. Alternatively, you can use a custom format script to automatically convert any typed lowercase letters to uppercase.

Is it possible to limit the text field to exactly one character without using JavaScript?

Yes, you can limit the character count natively. Open the text field Properties, go to the 'Options' tab, check the 'Limit of' box, and set the value to 1 character. However, this built-in feature only restricts the length, not which specific characters are allowed.