PDF Editing Issues

How to Format an Acrobat Form Field with a Variable-Length Number

Ayan MasoodAyan Masood Oct 28, 2026 869 views

Question details

The user needs to configure a PDF form field to include a dash, followed by a dynamically sized number ranging from three to seven characters in length.

How to Format an Acrobat Form Field with a Variable-Length Number
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF form that requires flexible, non-fixed formatting rules for user input.
Observed behavior
Standard formatting options in PDF forms require a fixed number of characters (e.g., 99-99999), meaning variable-length inputs are not natively supported without custom scripting.
Before you start

Ensure you are using Adobe Acrobat Pro or an advanced PDF editor with form preparation capabilities, as standard PDF readers do not allow editing form field properties or adding JavaScript.

Solution 1Recommended

Use Custom JavaScript for Form Formatting and Validation

Because standard formatting requires exact character counts, you must use custom keystroke, format, and validation JavaScript to support a variable-length suffix.

To achieve a format where the user types a prefix, a dash, and then anywhere from three to seven digits, you need to override the built-in arbitrary mask. A combination of three scripts ensures that the input is formatted properly as the user types, and validated upon completion.

1
Enter Prepare Form Mode

Open your document in Adobe Acrobat, go to 'Tools', and select 'Prepare Form' to enable form editing.

2
Open Field Properties

Right-click the specific text field you want to modify and select 'Properties' from the context menu.

3
Apply Custom Format Script

Navigate to the 'Format' tab, change the format category to 'Custom', and enter a custom Format Script to insert the dash automatically if it is missing.

4
Apply Custom Keystroke Script

In the same 'Format' tab, add a Custom Keystroke Script to restrict the user's input strictly to numbers and dashes, preventing invalid characters.

5
Apply Validation Script

Navigate to the 'Validate' tab, select 'Run custom validation script', and input JavaScript to check that the string segment after the dash contains between three and seven characters.

Use Custom JavaScript for Form Formatting and Validation
JavaScript Proficiency Required: Writing custom scripts requires a basic understanding of Acrobat JavaScript (based on Core JavaScript 1.5). For users new to this, consulting the Acrobat JavaScript API Reference is highly recommended.

Create and Manage PDF Forms Easily with WPS Office

If you are looking for an intuitive way to handle interactive PDF forms without struggling through complex JavaScript setups, WPS Office provides a streamlined PDF editor tailored for daily productivity.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in PDF editor.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form creation suite.
  3. 3. Insert Form Fields: Select the desired field type, such as 'Text Field' or 'Combo Box', and click on the document to place it.
  4. 4. Customize Field Properties: Double-click the inserted field to easily adjust its name, appearance, and standard formatting rules from the properties panel.
Easily insert text fields, checkboxes, and drop-down menus into your PDF formsFully compatible with standard PDF formats and Adobe Acrobat formsLightweight desktop application with a user-friendly, tabbed interfaceBuilt-in PDF conversion tools to switch between Word, Excel, and PDF formats seamlessly
microsoft office alternative - wps office

Frequently Asked Questions

Why can't I use the standard arbitrary mask for a variable-length number?

The built-in arbitrary mask in Acrobat (like 99-99999) dictates an exact, fixed number of characters. It does not natively support optional characters or variable lengths, which is why custom JavaScript is necessary.

Where do I add JavaScript to an existing Acrobat form field?

You can add JavaScript by right-clicking the form field in 'Prepare Form' mode, selecting 'Properties', and then navigating to either the 'Format', 'Validate', or 'Calculate' tabs, depending on when you want the script to trigger.

Can I format PDF forms with JavaScript using a free PDF reader?

No, free PDF readers only allow you to fill out existing forms. Modifying form field properties, including adding formatting rules and JavaScript, requires professional PDF editing software like Adobe Acrobat Pro.