How to Allow Letters and Numbers in PDF Form Fields with Acrobat JavaScript
Question details
The user wants to modify a PDF form's JavaScript to accept both letters and numbers while maintaining the AutoTab functionality.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Editing JavaScript in a PDF form field to change input restrictions from numbers-only to alphanumeric.
- Observed behavior
- The current script uses AFNumber_Keystroke, which restricts the input strictly to numeric characters, preventing the entry of letters.
Ensure you have access to a PDF editor that supports JavaScript editing, such as Adobe Acrobat Pro, and make a backup copy of your PDF form before modifying the scripts.
Remove the Numeric Restriction Script
By removing the AFNumber_Keystroke function, you can allow alphanumeric input while keeping the AutoTab feature intact.
The AFNumber_Keystroke function is specifically designed to restrict field input to numbers, signs, and decimal points. To allow letters as well, this function must be removed from your custom keystroke script.
The AutoTab behavior relies on checking the length of the entered keystrokes using AFMergeChange. As long as you keep this part of the script, the automatic focus movement will continue to work for alphanumeric characters.
Open your PDF form in your PDF editor and activate the Form Editing mode to access field properties.
Right-click the specific form field you want to modify and select 'Properties' from the context menu.
Navigate to the 'Format' or 'Calculate' tab where your custom Keystroke script is located, and click the 'Edit' button.
Locate and delete the line containing `AFNumber_Keystroke(0, 0, 0, 0, "", true);`. Ensure the script still contains the AFMergeChange length test to maintain the AutoTab functionality.
Click 'OK' to save the script, close the properties dialog, and test the form field to ensure it now accepts both letters and numbers while auto-tabbing.

Easily Manage and Edit PDF Forms with WPS PDF
WPS Office provides a comprehensive PDF editor that allows you to fill, create, and manage interactive PDF forms without a steep learning curve.
- 1. Install WPS Office: Download and install WPS Office on your computer or mobile device.
- 2. Open Your PDF: Launch WPS PDF and open the PDF document containing the forms.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the form editing tools.
- 4. Edit or Fill Forms: Add, modify, or fill out text fields, checkboxes, and dropdowns as needed, then save your document.

Frequently Asked Questions
What does the AFNumber_Keystroke function do in a PDF form?
The AFNumber_Keystroke function is a built-in Acrobat JavaScript function that restricts user input in a form field to numeric characters, decimal points, and signs. It prevents the entry of letters or special characters.
How does the AutoTab feature work in PDF JavaScript?
AutoTab works by using the AFMergeChange function to check the length of the current input. Once the input reaches the maximum character limit set for the field, the script automatically moves the focus to the next form field.
Can I restrict a PDF form field to only letters?
Yes, but you cannot use the built-in numeric functions. You will need to write a custom Keystroke script using Regular Expressions (RegEx) to test the input and reject any keystrokes that are not alphabetical characters.
Why did my AutoTab stop working after changing the script?
If AutoTab stops working, you may have accidentally deleted the event return check or the AFMergeChange length test when modifying the script. Ensure that the logic checking the character limit remains intact.




