PDF Editing Issues

Set PDF Form Field Formats in Adobe Acrobat with JavaScript

Maira MehtabMaira Mehtab Nov 19, 2026 868 views

Question details

Apply standard formats to multiple PDF form fields using field names and Acrobat JavaScript.

Set PDF Form Field Formats in Adobe Acrobat with JavaScript
Product
Adobe Acrobat Pro
Device & OS
not provided
Scenario
A form creator wants to format date, number, and Social Security number fields in bulk.
Observed behavior
Fields with matching name prefixes should receive the corresponding format action.
Before you start

Open the PDF in Acrobat Pro and check that the fields are text fields with consistent prefixes such as Date_, Number_, and SSN_. Enable Acrobat JavaScript in Preferences if it is disabled, and review any existing field format actions because the script will replace them.

Solution 1Recommended

Apply format actions in bulk with the Acrobat JavaScript console

Use this method to assign formats to existing text fields based on their names.

Acrobat does not provide a global JSON setting for custom form-field formats. This script loops through the document's fields and uses Field.setAction() to assign a Format action to each matching text field.

1
Check field names

Open Tools > Prepare Form and inspect the field names. Use Date_ for dates, Number_ for numbers, and SSN_ for Social Security numbers; adjust the script if your prefixes differ.

2
Open the JavaScript console

Open the JavaScript console in Acrobat using Ctrl+J on Windows or Command+J on a Mac.

3
Run the script

Paste and select the following code in the console, then press Ctrl+Enter on Windows or Command+Enter on a Mac: for (var i = 0; i < this.numFields; i++) { var name = this.getNthFieldName(i); var field = this.getField(name); if (!field || field.type !== "text") continue; if (/^Date_/i.test(name)) { field.setAction("Format", 'AFDate_FormatEx("mm/dd/yyyy");'); } else if (/^Number_/i.test(name)) { field.setAction("Format", 'AFNumber_Format(2, 0, 0, 0, "", true);'); } else if (/^SSN_/i.test(name)) { field.setAction("Format", 'AFSpecial_Format(3);'); } }

4
Test and save the form

Enter sample values in each field type and move focus away to check the displayed formats. Use File > Save to save the updated PDF.

Apply format actions in bulk with the Acrobat JavaScript console
Formatting and validation are separate: The script replaces existing Format actions on matching fields. It does not add Keystroke actions or automatically format fields created later; rerun or update it after adding fields.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface and support for common Office formats, making it easy to move between documents and PDFs. Acrobat-specific JavaScript form actions still need to be managed in Acrobat.

Open and review PDF forms alongside other documentsCompatible with Microsoft Office formats such as DOCX and XLSXFamiliar interface for a smooth transition from OfficeFree, lightweight suite for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

Can I set all Acrobat field formats with a global JSON setting?

No. Acrobat does not offer a global JSON setting for custom form-field formats. You can use Acrobat JavaScript and Field.setAction() to assign actions to matching fields.

How can I change the date or number format in the script?

Edit the Format action in the JavaScript console. For example, change the pattern passed to AFDate_FormatEx or the decimal-place argument passed to AFNumber_Format, then run the script again.

Will the script format fields I add later?

No. The script updates matching fields that exist when it runs. Add the new fields in Tools > Prepare Form, name them with the appropriate prefixes, and rerun the script.

Does a Format action prevent every invalid entry?

No. A Format action controls formatting when the field is processed, but it does not replace a Keystroke action for input restrictions. Test the form and add validation appropriate to your needs.