PDF Editing Issues

How to Restrict a PDF Text Field to Only 'X' or 'I' in Acrobat

Huma Ashraf ChHuma Ashraf Ch Nov 3, 2026 869 views

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.

How to Restrict a PDF Text Field to Only 'X' or 'I'
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'.
Before you start

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.

Solution 1Recommended

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.

1
Access field properties

Open your PDF form in edit mode, right-click the target text field, and select Properties from the context menu.

2
Navigate to custom format

Go to the Format tab in the Properties dialog and select Custom from the Select format category drop-down list.

3
Add keystroke script

Click Edit next to the Custom Keystroke Script box and enter your JavaScript snippet utilizing AFMergeChange(event).

4
Set rejection condition

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.

Apply a Custom Keystroke Script
Case Sensitivity: Ensure your script accounts for both uppercase and lowercase inputs if you want to allow 'x' and 'i' as well as their uppercase equivalents.
Easy PDF Form Editing

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. 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. 2. Select the Combo Box tool: Click on Combo Box or Drop-down from the form controls toolbar.
  3. 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. 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. 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.
Visual PDF form builder without needing complex JavaScriptFully compatible with Adobe Acrobat PDF and Microsoft Word formatsSupports text fields, checkboxes, and drop-downs for easy data entryLightweight, fast, and completely free to download
microsoft office alternative - wps office

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.