PDF Editing Issues

Restrict an Adobe Acrobat PDF Field to a Single Digit 9

Ayan MasoodAyan Masood Nov 19, 2026 869 views

Question details

Configure an interactive PDF text field to accept only a single digit 9.

Restrict an Adobe Acrobat PDF Field to a Single Digit 9
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form author wants to restrict what users can type or paste into a text field.
Observed behavior
The field should accept 9 or an empty value, allowing users to delete or replace their entry.
Before you start

Open the PDF in an Acrobat version that can edit forms, and identify the text field you want to restrict. Make sure JavaScript is enabled in Acrobat preferences so you can test the script.

Solution 1Recommended

Add a Custom Keystroke Script to the Acrobat Text Field

Use a custom keystroke script to allow one 9 while rejecting other characters and additional digits.

The script checks the proposed field value, including selected text being replaced. It permits an empty field so users can delete their entry.

1
Open the form editor

Open the PDF in Adobe Acrobat, then choose All tools > Prepare a form. The menu name may vary by Acrobat version.

2
Open field properties

Double-click the text field you want to restrict, or right-click it and select Properties.

3
Add the script

On the Format tab, select Custom, then click Edit beside Custom Keystroke Script. Enter: if (!event.willCommit) { var next = event.value.slice(0, event.selStart) + event.change + event.value.slice(event.selEnd); event.rc = /^9?$/.test(next); }

4
Test the field

Close the field properties, save the PDF, and use Preview in Prepare a form to test typing, pasting, selecting, and deleting. Confirm that only 9 or an empty value is accepted.

Add a Custom Keystroke Script to the Acrobat Text Field
Avoid a numeric mask: A 9 in an arbitrary mask commonly represents any numeric digit, not the literal digit 9. The script requires a PDF viewer that supports Acrobat form JavaScript.
Free Microsoft Office alternative

Work With PDFs and Office Documents in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility makes it easy to move between common document workflows, but it does not configure the Acrobat-specific keystroke script described above.

Open and review PDF documents alongside other office filesCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXUse a familiar interface to make moving from Microsoft Office easierAccess free office tools in a lightweight suite
microsoft office alternative - wps office

Frequently Asked Questions

Why can't I use a mask containing 9?

In an Acrobat arbitrary mask, 9 commonly stands for any numeric digit. Use the field's Format > Custom > Custom Keystroke Script setting to restrict the value to a literal 9.

Can users delete the 9 after entering it?

Yes. The script accepts an empty value as well as a single 9, so users can delete the entry or select it and replace it.

Will the script work in every PDF viewer?

No. The viewer must support Acrobat form JavaScript. Test the saved PDF in the viewer your intended users will use.

Can I make the field mandatory?

In Prepare a form, open the field's Properties and select Required on the General tab. This setting is relevant to form submission; it does not necessarily prevent someone from saving the PDF with the field empty.