Set PDF Form Field Formats in Adobe Acrobat with JavaScript
Question details
Apply standard formats to multiple PDF form fields using field names and Acrobat 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.
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.
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.
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.
Open the JavaScript console in Acrobat using Ctrl+J on Windows or Command+J on a Mac.
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);'); } }
Enter sample values in each field type and move focus away to check the displayed formats. Use File > Save to save the updated PDF.

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.

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.




