Customize Acrobat Form Field Formats with JavaScript
Question details
The user wants to add regional formats, such as Swiss AHV numbers and IBANs, to Acrobat form fields.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form needs field formats that are not available in Acrobat's built-in Special Format options.
- Observed behavior
- Custom JavaScript should display each field value in the appropriate regional format.
Open the PDF in an Acrobat version that supports creating or editing form fields, and identify the fields that need custom formats. Enable Acrobat JavaScript in Preferences if it is disabled.
Add a custom format script to each Acrobat form field
Use a field-level script when you need a regional display format without installing reusable functions.
Open the PDF in Acrobat and choose All tools > Prepare a form. Select the text field you want to format, or add a text field if needed.
Open the field's Properties, select the Format tab, and choose Custom from the format category list. Click Edit next to Custom Format Script.
For an AHV field, enter this script: var digits = String(event.value).replace(/\D/g, ''); if (digits.length === 13) event.value = digits.substring(0, 3) + '.' + digits.substring(3, 7) + '.' + digits.substring(7, 11) + '.' + digits.substring(11, 13);
For a separate Swiss IBAN field, open its Custom Format Script editor and enter: var iban = String(event.value).replace(/\s/g, '').toUpperCase(); if (/^CH\d{2}[A-Z0-9]{17}$/.test(iban)) event.value = iban.replace(/(.{4})(?=.)/g, '$1 ');
Close the properties dialog, use Preview in Prepare a form, and enter sample values. Move out of each field to check its displayed format, then save the PDF.

Reuse formatting functions through Acrobat application-level JavaScript
Use shared functions when multiple forms on the same configured installation need the same formatting logic.
Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Microsoft Office files. Open existing files to make the move easier; Acrobat-specific JavaScript formatting still requires a compatible Acrobat setup.

Frequently Asked Questions
Where do I add a custom format script in Acrobat?
Open All tools > Prepare a form, open the field's Properties, and select Format. Choose Custom, then click Edit next to Custom Format Script.
Will the AHV script check whether a number is valid?
No. The example formats 13 digits with periods but does not check the AHV prefix or checksum. Add separate validation if you need to reject invalid numbers.
Can I use one formatting function in several PDF forms?
Yes. Define a named function in an Acrobat application-level JavaScript file, restart Acrobat, and call it from each field's Custom Format Script. Each user's installation must have the function available.
Why does a custom format work on my computer but not for another user?
Check whether the script calls an application-level function that is missing from the other user's installation. Also check whether JavaScript is enabled and whether their PDF viewer supports Acrobat form JavaScript.




