Set a PDF Phone Field’s Character Limit Based on Another Field in Acrobat
Question details
Set a PDF phone field’s character limit according to the value of another form field.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A PDF form has a country field and a phone field that should allow different maximum lengths for domestic and other selections.
- Observed behavior
- The phone field should allow 10 characters for the domestic selection and 20 characters for other selections.
Open the PDF in Acrobat and check the exact form field names and the country option’s export value. Enable Acrobat JavaScript in Acrobat preferences if it is disabled, and ensure you can edit the form fields.
Update the Phone Field Limit When the Country Field Loses Focus
Use a field action to apply the appropriate limit before the user enters a phone number.
The script below assumes the fields are named country and phone, and the domestic option has the value domestic. Field names and the comparison value must match your form exactly.
A character limit counts all characters, including spaces and punctuation. It does not check whether a phone number has a valid format.
In Acrobat, open the PDF and choose All tools > Prepare a form. Open the country and phone field properties to confirm their names and the country option’s export value.
Open the phone field’s Properties > Options and set Limit of characters to match the initial country selection, such as 10 for domestic.
Open the country field’s Properties > Actions. Set Select Trigger to On Blur and Select Action to Run a JavaScript, then click Add.
In the JavaScript editor, enter: var phone = this.getField("phone"); if (this.getField("country").value == "domestic") { phone.charLimit = 10; } else { phone.charLimit = 20; } Click OK and close the field properties.
Use Preview in Prepare a form, select each country option, click away from the country field, and try typing in the phone field. Also test changing the country after entering a number to check how existing text is handled.

Work With PDF and Office Files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for working with documents, spreadsheets, presentations, and PDFs. Its Microsoft Office format compatibility makes moving existing files straightforward. Use Acrobat for the dynamic form JavaScript described above; do not assume it will run in every PDF viewer.

Frequently Asked Questions
Why does the script not recognize the domestic option?
In Prepare a form, open the country field’s Properties and check its field name and option export value. Update the script so country and domestic match those values exactly.
Can I put the script on the phone field instead?
Yes. In the phone field’s Properties > Actions, add an On Blur action that sets event.target.charLimit to 10 or 20 based on the country field. This runs only after the user leaves the phone field, so it does not apply the new limit before typing.
Does a character limit ensure that the phone number is valid?
No. The limit counts characters, including spaces and punctuation. For stricter checks, add a custom keystroke or validation script in the phone field’s properties using patterns for the permitted phone-number formats.
Will the dynamic limit work in every PDF viewer?
Not necessarily. PDF viewers differ in their support for form JavaScript. Save the form and test it in the Acrobat or other PDF application your recipients will use.




