How to Allow Spaces and Special Characters in Acrobat PDF Text Fields
Question details
The user needs to configure a custom validation script in a PDF text field to allow English letters and numbers, as well as spaces, periods, and specific special characters without rejecting them.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating a custom JavaScript validation script for a PDF form text field to restrict user input to a specific character set.
- Observed behavior
- The current validation script rejects valid characters such as spaces, periods, and ampersands, even though they were intended to be permitted alongside standard English letters and numbers.
Ensure you have access to the form editing tools in your PDF editor and a basic understanding of JavaScript regular expressions (Regex).
Update the Regular Expression Character Class in Your Script
Modify the custom validation script to explicitly include the space character, period, and any other required special characters within the regex square brackets.
Regular expressions (regex) use character classes enclosed in square brackets to define exactly which characters are permitted. If a space or period is missing from this class, the script will reject the input.
By placing every permitted character (like spaces, periods, and ampersands) directly inside the regular expression character class, the validation will accurately pass supported inputs while triggering an alert only for unsupported characters.
In your PDF editing software, enter the Form Preparation mode. Right-click the specific text field you want to validate and select 'Properties'.
Click on the 'Validate' tab in the Properties dialog box and select 'Run custom validation script' from the available options.
Click the 'Edit' button and input the updated regex script. For example: var pattern = /^[0-9a-zA-Z .&-]*$/; event.rc = pattern.test(event.value); if (!event.rc) app.alert("English Characters and Approved Punctuation Only");
Click 'OK' to save the script, close the Properties window, and switch back to the standard preview mode to test the text field with spaces and special characters.

Easily Create and Fill PDF Forms with WPS Office
If you frequently work with PDF forms and need a reliable, lightweight application, WPS PDF provides excellent tools for editing, form filling, and document formatting without complex configurations.
- 1. Open WPS Office: Launch WPS Office and click on the 'PDF' tab from the home screen.
- 2. Open Your PDF Form: Click 'Open' and select the PDF form document you want to edit or fill.
- 3. Use Form and Edit Tools: Navigate to the 'Edit' or 'Form' tab on the top ribbon to easily input text, modify existing content, or fill out interactive fields without needing complex scripts.

Frequently Asked Questions
Why does my PDF form field reject spaces even when I allow text?
Standard alphabetic validation patterns often only include A-Z and a-z. To allow spaces, you must explicitly type a space character within the square brackets of your validation script's regular expression.
Can a JavaScript validation script detect if the text entered is valid English?
No, a standard regular expression script only checks if the entered characters belong to a permitted set (like the Latin alphabet). It cannot verify grammar, vocabulary, or the language context of the sentence.
How do I add an ampersand or hyphen to my regex character class?
You can add special characters like ampersands directly inside the square brackets. For hyphens, place them at the very end of the character class (e.g., [a-zA-Z .&-]) so the system interprets it as a literal hyphen rather than a character range.




