How to Restrict a PDF Text Field to Only 'X' or 'I' in Acrobat
Question details
The user wants to restrict a PDF text field to accept only the letters 'X' or 'I' and reject any other keystrokes while typing.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Creating or editing a fillable PDF form that requires highly specific character inputs from the end user.
- Observed behavior
- By default, text fields accept any alphanumeric input. A custom script or an alternate field type is required to restrict inputs to only 'X' or 'I'.
Ensure you have access to the form editing tools in your PDF editor. If you plan to use JavaScript for keystroke restrictions, verify that JavaScript execution is enabled in your PDF viewer's preferences.
Apply a Custom Keystroke Script
Use a JavaScript keystroke event to evaluate and reject invalid inputs dynamically as the user types.
This method uses the AFMergeChange(event) function to check the character being entered. If the character is not an 'X' or 'I', the script blocks the input instantly before it appears in the field.
Open your PDF form in edit mode, right-click the target text field, and select Properties from the context menu.
Go to the Format tab in the Properties dialog and select Custom from the Select format category drop-down list.
Click Edit next to the Custom Keystroke Script box and enter your JavaScript snippet utilizing AFMergeChange(event).
Write the script logic to check if the input is 'X' or 'I'. If it is not, set event.rc = false to reject the keystroke and optionally trigger an alert message explaining the restriction.

Change the Text Field to a Drop-Down List
Replace the text field with a drop-down menu containing only the allowed options for a simpler, script-free solution.
Create Restricted PDF Forms Easily with WPS PDF
Instead of writing complex JavaScript codes, you can easily insert drop-down menus or combo boxes using WPS Office's PDF editor to restrict user inputs to specific choices like 'X' or 'I'.
- 1. Open the PDF in WPS Office: Launch WPS Office, open your PDF document, and navigate to the Form tab on the top ribbon.
- 2. Select the Combo Box tool: Click on Combo Box or Drop-down from the form controls toolbar.
- 3. Draw the field: Click and drag on your PDF page to draw the field where you want the user to input their choice.
- 4. Add restricted options: Double-click the newly created field to open its Properties. Under the Options tab, add 'X' and 'I' as the only allowed item choices.
- 5. Save and share: Save the PDF document. When users open the file, they will only be able to select from the specific letters you provided.

Frequently Asked Questions
Why doesn't a custom validation script stop invalid typing immediately?
A validation script only triggers after the user finishes typing and clicks away from the field. To block characters as they are actively typed, you must use a Keystroke script instead.
Can I restrict a PDF text field to numbers only without coding?
Yes. In the text field properties under the Format tab, you can set the format category to 'Number'. This automatically rejects non-numeric keystrokes without needing custom JavaScript.
What happens if JavaScript is disabled in the user's PDF viewer?
If the user has disabled JavaScript for security reasons, the keystroke script will not run, and they will be able to type any character into the text field. Using a drop-down field is a safer alternative that does not rely on JavaScript execution.




