PDF Editing Issues

How to Validate Multiple Cost Code Formats in Mobile PDF Forms

John WilsonJohn Wilson Nov 3, 2026 869 views

Question details

The user needs a dynamic PDF timesheet to accept two specific cost code formats (9-99-999 or 99-99-999) without leading zeros, functioning seamlessly across various mobile devices.

How to Allow Two Cost Code Formats in a Mobile PDF Form
Product
PDF
Device & OS
iPhone, iPad, Android
Scenario
Creating a dynamic PDF timesheet for field staff that requires specific formatting rules for cost code entry fields.
Observed behavior
Standard Acrobat format masks only support one fixed format, failing to accommodate both required structural variations and unable to block leading zeros.
Before you start

Before applying custom scripts, ensure your preferred PDF editor supports JavaScript for form validation, and note that script execution can vary significantly depending on the mobile PDF reader app being used.

Solution 1Recommended

Use Custom JavaScript Regular Expressions for Validation

Since a single format mask cannot support multiple structures, you must use a custom JavaScript validation script with regular expressions to enforce the two cost code formats and reject leading zeros.

A custom validation script evaluates the user's input against predefined regular expressions. It checks if the entry matches either the 9-99-999 or 99-99-999 format. Additionally, it applies a specific check to ensure the first digit is not a zero when the two-digit prefix is used.

1
Open Form Field Properties

Right-click the designated cost code text field in your PDF form editor and select 'Properties' from the context menu.

2
Navigate to the Validate Tab

In the Properties dialog box, click on the 'Validate' tab to configure the input rules for the field.

3
Enable Custom Validation

Select the option to 'Run custom validation script' and click the 'Edit' button to open the JavaScript editor.

4
Insert the RegExp Script

Paste a JavaScript snippet that tests the event.value against the required regular expressions (e.g., /^\d{2}-\d{2}-\d{3}$/ and /^\d{1}-\d{2}-\d{3}$/) while explicitly setting event.rc to false if the value begins with a zero. Save your changes.

5
Test on Target Mobile Apps

Because JavaScript support varies across mobile applications, transfer the updated PDF to an iPhone, iPad, and Android device. Test the form fields using the exact PDF reader applications your field staff will utilize.

Use Custom JavaScript Regular Expressions for Validation
Mobile App Compatibility: Not all third-party mobile PDF viewers support JavaScript validation. If the script fails on mobile, you may need to mandate the use of a fully compliant PDF reader app for your field staff.
WPS PDF Form Tools

Manage Interactive PDF Forms with WPS Office

WPS Office offers a comprehensive suite of PDF tools that allow you to seamlessly view, fill, and manage interactive forms on both desktop and mobile platforms.

  1. 1. Open the PDF File: Launch WPS Office on your desktop or mobile device and open your interactive PDF timesheet.
  2. 2. Fill the Form Fields: Tap or click on the cost code fields to input your data; WPS PDF accurately renders interactive text fields.
  3. 3. Save and Share: Once the timesheet is completed, save the document and use the built-in share feature to send it to your team directly.
Cross-platform support ensures PDF forms can be accessed on Windows, Mac, iOS, and Android.Fully compatible with standard Adobe PDF form fields and Microsoft Office file formats.Lightweight application providing a fast and familiar user interface.Easily share filled timesheets and forms directly from your mobile device.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my PDF form validation script working on mobile devices?

Many default or third-party mobile PDF readers offer limited or no support for JavaScript execution. To ensure your custom validation scripts work, your users must open the form in a fully compliant PDF application designed to handle advanced interactive elements.

Can I use standard Acrobat format masks for two different formats?

No, standard format masks in PDF editors only allow you to define a single, fixed input structure. When a field requires multiple valid formats, such as varying prefix lengths, custom JavaScript is the only way to enforce the rules.

How do I prevent users from entering a leading zero in a PDF text field?

You can block leading zeros by adding a condition in your custom JavaScript validation script. For example, using a regular expression like /^0/.test(event.value) allows the script to detect a leading zero and reject the input by triggering an error alert.