How to Format an Acrobat Form Field with a Variable-Length Number
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.

- 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.
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.
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.
Open your document in Adobe Acrobat, go to 'Tools', and select 'Prepare Form' to enable form editing.
Right-click the specific text field you want to modify and select 'Properties' from the context menu.
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.
In the same 'Format' tab, add a Custom Keystroke Script to restrict the user's input strictly to numbers and dashes, preventing invalid characters.
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.

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. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in PDF editor.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form creation suite.
- 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. Customize Field Properties: Double-click the inserted field to easily adjust its name, appearance, and standard formatting rules from the properties panel.

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.




