How to Extract Trailing Numbers from Acrobat PDF Field Names
Question details
The user needs a JavaScript method to extract numeric suffixes of varying lengths from PDF form field names.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing a button script inside a PDF form to identify its own numeric suffix and dynamically locate related fields.
- Observed behavior
- The script needs to accurately read and isolate trailing digits (e.g., '4' from 'topPh4' or '12' from 'newPage12') from the current field name.
Ensure you have access to the JavaScript editor or form design mode in your PDF application, and verify that your form fields consistently use numerical suffixes.
Use a Regular Expression to Match Trailing Digits
The most efficient way to isolate a trailing number of any length from a field name is by using a JavaScript regular expression match function.
Regular expressions allow you to search for specific patterns in strings. By targeting the end of the field name, you can reliably extract any numeric suffix regardless of how many digits it contains.
In your PDF form builder, select the button or field you want to script, access its properties, and navigate to the Actions or Calculate tab to add a custom JavaScript.
Use the built-in variable event.target.name to dynamically retrieve the exact name of the field triggering the script.
Use the JavaScript match() function with the regular expression /\d+$/ to find and extract the trailing digits. For example: var suffix = event.target.name.match(/\d+$/)[0];

Manage PDF Forms Easily with WPS Office
While advanced JavaScript debugging in complex PDF editors can be challenging, WPS Office offers a highly intuitive, lightweight, and cost-effective alternative for creating, filling, and managing PDF forms along with full Word, Excel, and PowerPoint compatibility.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your device.
- 2. Open your PDF Document: Launch WPS Office and open your interactive PDF form directly within the app.
- 3. Fill and Manage Forms: Use the dedicated PDF tools to fill form fields, add signatures, and manage document properties easily.

Frequently Asked Questions
Why does my JavaScript return null when extracting the number?
This usually happens if the field name does not actually end with a digit or contains hidden trailing spaces. Ensure your regular expression is applied to correctly named fields without trailing spaces.
Can I extract numbers from the beginning of the field name instead?
Yes. You can modify the regular expression to /^\d+/ to match one or more digits strictly at the start of the field name instead of the end.
How do I use the extracted number to reference another field?
Once you extract the suffix, you can concatenate it with the base name of the related field and use this.getField('baseName' + suffix) to access the related field's properties and values.




