How to Restrict an Acrobat Text Field to Specific Letters
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.

- 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.
Ensure you have access to the 'Prepare Form' tool in Adobe Acrobat and possess basic familiarity with adding custom JavaScript to form field properties.
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.
Open your PDF in Adobe Acrobat and select the 'Prepare Form' tool from the right-hand pane.
Right-click the specific text field you want to restrict and select 'Properties' from the context menu.
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).
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));
Click 'Close' to save the properties. Exit the 'Prepare Form' mode by clicking 'Preview' at the top right to test your restricted field.

Use a Drop-Down List as an Alternative
If you are not comfortable with JavaScript and have enough space on your form, a drop-down list is the simplest way to restrict input to specific options.
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. Download and Install: Get WPS Office for free from the official website and follow the easy installation prompts.
- 2. Open Your Documents: Launch WPS Office, click on 'Open', and select any PDF, DOCX, XLSX, or PPTX file.
- 3. Edit and Manage: Use the integrated PDF tools to fill forms, highlight text, or convert PDFs directly into editable Word documents.

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.




