How to Add an NPI Prefix and Validate a 10-Digit Number in PDF Forms
Question details
Configure a PDF form text field to automatically add an "NPI: " prefix to user input and validate that the entered value is exactly 10 digits long.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating or modifying an interactive PDF form where users must input a valid 10-digit National Provider Identifier (NPI).
- Observed behavior
- The target form field must automatically prepend the prefix "NPI: " to the entered data and strictly reject any input that does not consist of exactly 10 numeric digits.
Ensure you are using a PDF editor that supports advanced form editing and JavaScript execution, as setting up this specific formatting and validation requires custom scripting.
Apply Custom Format and Validation Scripts
Use the PDF field properties to embed custom JavaScript for both formatting the display value and validating the user input length.
By utilizing custom JavaScript in PDF form fields, you can control exactly how data is displayed and verify its structure. A Format script handles the visual addition of the 'NPI: ' prefix, while a Validation script uses a regular expression to enforce the 10-digit requirement.
Open your PDF form in edit mode, right-click on the specific text field where the NPI will be entered, and select 'Properties'.
Navigate to the 'Format' tab. From the 'Select format category' dropdown, choose 'Custom'. In the Custom Format Script box, enter the following code: if (event.value) event.value = "NPI: " + event.value;
Next, switch to the 'Validate' tab. Select the 'Run custom validation script' option. In the scripting box, input the exact requirement code: if (event.value) event.rc = /^\d{10}$/.test(event.value);
Close the properties window and exit form editing mode. Type a 10-digit number into the field and press Enter or click away to confirm that the NPI prefix is applied and that invalid entries are appropriately rejected.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office offers a comprehensive PDF editor that allows you to easily design interactive forms, manage text fields, and customize document properties.
- 1. Download and Install WPS Office: Get the latest version of WPS Office and install it on your device to access the full suite of PDF editing tools.
- 2. Open Your PDF: Launch WPS PDF and open the document you wish to transform into an interactive form.
- 3. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access various form controls and properties.
- 4. Edit Field Properties: Double-click any inserted form field to adjust its properties, appearance, and specific interactive options.

Frequently Asked Questions
Why is my PDF validation script not working?
If your script isn't working, double-check the syntax. JavaScript is highly sensitive to errors. Ensure there are no typos, missing semicolons, or incorrect casing in the regular expression `/^\d{10}$/`.
Can I format other document numbers using a similar PDF script?
Yes. You can adapt the Format script by simply changing the "NPI: " text string to any other prefix or suffix you need (for instance, "ID: " or "PO: ") to suit different business forms.
What happens if a user enters letters instead of digits?
The regular expression `^\d{10}$` in the Validation script checks exclusively for numeric characters (`\d`). If a user inputs letters or special characters, the script will evaluate to false and the PDF form field will reject the entry.




