PDF Editing Issues

How to Restrict a PDF Form Field to Numbers and Commas

Chanuka GeekiyanageChanuka Geekiyanage Oct 28, 2026 869 views

Question details

The user needs to configure a PDF form field so it only accepts numbers and commas, specifically rejecting letters, spaces, descriptions, and other characters.

How to Restrict a PDF Form Field to Numbers and Commas
Product
PDF Editor
Device & OS
not provided
Scenario
Creating or editing a PDF form that requires strict input validation, such as entering multiple department numbers separated by commas.
Observed behavior
By default, the PDF text field accepts any alphanumeric character. The goal is to restrict the input strictly to digits and commas to prevent invalid data entry.
Before you start

Ensure you are using a comprehensive PDF editor like WPS Office or Adobe Acrobat that supports interactive form field properties and custom JavaScript formatting.

Solution 1Recommended

Apply a Custom Keystroke Script for Validation

Add a simple regular expression script in the field's formatting properties to instantly block invalid characters like letters and spaces during user input.

This method uses a Custom Keystroke Script triggered every time a user types into the field. By leveraging a standard regular expression, you can cleanly restrict the allowed input to digits and commas only.

1
Open Field Properties

Right-click the target text field in your PDF form and select 'Properties' from the context menu.

2
Navigate to the Format Tab

In the Properties dialog box, click on the 'Format' tab located at the top of the window.

3
Choose Custom Format Category

Click the 'Select format category' dropdown menu and choose 'Custom'.

4
Add the Keystroke Script

In the 'Custom Keystroke Script' text box, enter the following code: event.rc = /^[\d,]*$/.test(event.change);

5
Test the Form Field

Close the properties window, exit form editing mode, and test the field by typing letters or spaces. The field should now exclusively accept numbers and commas.

Apply a Custom Keystroke Script for Validation
Adjusting for Decimals or Spaces: If you need to support French formatting where a comma acts as a decimal point, or if you wish to allow standard decimal periods or spaces, you will need to adjust the regular expression accordingly (e.g., adding a period or space inside the brackets).
Advanced PDF Form Editing

Edit and Manage PDF Forms Easily with WPS Office

WPS Office provides a comprehensive suite of PDF tools, allowing you to create interactive forms, edit text, manage field properties, and apply advanced data validation scripts seamlessly.

  1. 1. Open your PDF in WPS Office: Launch WPS Office and open the PDF document containing your form.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access interactive form field tools.
  3. 3. Modify Field Properties: Right-click the target text field, select 'Properties', and navigate to the Format tab to set up custom validation rules.
Easily create, edit, and validate interactive PDF form fields.Fully compatible with standard Adobe PDF formats and Microsoft Office files.Intuitive interface for managing advanced form field properties.Lightweight, fast, and feature-rich alternative to heavy PDF software.
QA img-9

Frequently Asked Questions

Can I restrict a PDF form field to only numbers without commas?

Yes, you can use the built-in 'Number' format category in the field properties under the Format tab. Alternatively, if you want to use a script to strictly allow only digits without separators, use the script: event.rc = /^\d*$/.test(event.change);

Why is my custom keystroke script not working in the PDF?

Ensure your PDF editor supports JavaScript execution and that JavaScript is not disabled in your application's security preferences. Also, double-check the script code for any missing brackets or syntax errors.

How do I allow spaces along with numbers and commas?

You can modify the regular expression in the custom keystroke script to include a space character inside the brackets. Update the code to: event.rc = /^[\d, ]*$/.test(event.change);