PDF Editing Issues

Customize Acrobat Form Field Formats with JavaScript

Huda QurayshiHuda Qurayshi Nov 19, 2026 868 views

Question details

The user wants to add regional formats, such as Swiss AHV numbers and IBANs, to Acrobat form fields.

Customize Acrobat Form Field Formats with JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

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.

2
Open the custom format editor

Open the field's Properties, select the Format tab, and choose Custom from the format category list. Click Edit next to Custom Format Script.

3
Add an AHV format

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);

4
Add an IBAN format

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 ');

5
Test the fields

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.

Add a custom format script to each Acrobat form field
Formatting is not validation: These examples format values with the expected length and structure; they do not verify AHV or IBAN checksums. Values that do not match the expected structure are left unchanged.
Free Microsoft Office alternative

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.

Open and review PDF forms alongside other documentsCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for working with existing Office filesFree, lightweight option for everyday document tasks
microsoft office alternative - wps office

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.