PDF Editing Issues

Remove Leading and Trailing Spaces from Acrobat Form Fields

Natalie TaylorNatalie Taylor Nov 19, 2026 869 views

Question details

Remove whitespace from the beginning and end of text entered in a PDF form field without removing spaces within the text.

Remove Leading and Trailing Spaces from Acrobat Form Fields
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form needs to clean up names or other text when users finish entering a field value.
Observed behavior
Leading and trailing whitespace is removed while spaces between words remain intact.
Before you start

Open the PDF in an Acrobat edition that lets you edit form fields, and make sure you can access the field's Properties dialog. The validation script runs when a field value is committed, so test it by changing the field and moving focus away.

Solution 1Recommended

Add a custom validation script to the Acrobat form field

Use the field's validation settings to trim whitespace from both ends of an entered value while preserving internal spaces.

1
Open form editing

Open the PDF in Adobe Acrobat and select Prepare a form from the tools menu.

2
Open field properties

Right-click the text field you want to clean up, then select Properties.

3
Add the validation script

On the Validate tab, select Run custom validation script, click Edit, and enter: event.value = event.value.trim();

4
Save and test the field

Confirm the script, close Properties, and save the PDF. Enter a value such as " Jane Doe " in the field, then click another field; the result should be "Jane Doe".

Add a custom validation script to the Acrobat form field
Use validation, not formatting: Add the code as a custom validation script rather than a format script. Existing values are not necessarily cleaned until the field value is changed and committed.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free, lightweight alternative for everyday document work, with a familiar interface and compatibility with common Microsoft Office formats for easier migration. Its PDF tools can help with general PDF tasks, but they do not replace Acrobat's custom form validation script.

Open and work with PDFs alongside other documentsCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFamiliar interface for users moving from Microsoft OfficeFree, lightweight suite for everyday office work
microsoft office alternative - wps office

Frequently Asked Questions

Will trim() remove the space between a first and last name?

No. The script event.value = event.value.trim(); removes whitespace only from the beginning and end of the field value, leaving internal spaces intact.

Where should I put the script in Acrobat?

In Prepare a form, right-click the text field and choose Properties. On the Validate tab, select Run custom validation script and click Edit.

When does the validation script run?

It runs when the field value is committed, such as after a user changes the text and moves focus to another field.

Will this script automatically clean every existing field value?

No. The script applies to the field where it is added and runs when that field's value is validated. Existing values may need to be changed and committed before they are trimmed.