PDF Editing Issues

How to Format Time Input as 11h00 in PDF Forms using Scripts

Camila MilosovichCamila Milosovich Oct 28, 2026 869 views

Question details

The user needs to automatically format a four-digit numerical time input into a specific time format within a PDF form field.

Product
PDF Forms
Device & OS
not provided
Scenario
Designing an interactive PDF form where users enter times (e.g., 1100) and need the field to auto-format it consistently (e.g., 11h00).
Observed behavior
The user wants to replicate a specific formatting behavior from LiveCycle using standard PDF custom format scripts to insert an 'h' before the last two digits.
Before you start

Ensure you are using a PDF editor that supports form creation and custom JavaScript execution, such as Adobe Acrobat Pro or WPS Office, and verify that the target field is configured as a standard Text Field.

Solution 1Recommended

Apply a Custom Format Script with Regular Expressions

Use a brief JavaScript regex format script to automatically insert an 'h' before the final two digits of the user's input.

PDF forms support custom JavaScript for calculating and formatting user inputs. By utilizing a simple Regular Expression (Regex), you can target the last two digits of a four-digit number and insert any character you need, such as an 'h' for hours.

1
Open Field Properties

Open your PDF document in Form Editing mode. Right-click the specific text field you want to modify and select 'Properties' from the context menu.

2
Navigate to the Format Tab

In the Text Field Properties dialog, click on the 'Format' tab at the top. From the 'Select format category' dropdown menu, choose 'Custom'.

3
Enter the JavaScript

In the 'Custom Format Script' window, enter the following code: event.value = event.value.replace(/(\d{2}$)/, "h$1");

4
Test the Input

Click 'Close' to save the properties. Exit form editing mode and type a four-digit number like '1100' into the field, then click away to verify it automatically changes to '11h00'.

Apply a Custom Format Script with Regular Expressions
Add Data Validation: It is highly recommended to add a custom Validation script as well to ensure users only enter exactly four digits. If a user types text or an incorrect number of digits, the formatting script might produce unintended results.
Efficient PDF Form Creation

Edit and Manage Interactive PDF Forms with WPS Office

WPS Office provides robust PDF editing capabilities, enabling you to effortlessly handle interactive forms, customize text fields, and process document data efficiently.

  1. 1. Open the PDF: Launch WPS Office and open your interactive PDF document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access field creation and editing tools.
  3. 3. Edit Field Properties: Double-click any text field to adjust its appearance, format, and behavior options.
  4. 4. Save and Distribute: Save your optimized PDF form and easily share it with others for seamless filling.
Fully compatible with standard PDF form fields and formatting scripts created in Microsoft Windows and Adobe ecosystems.Lightweight and fast, opening complex interactive PDFs instantly.Free to use for essential PDF viewing, filling, and annotating tasks.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my custom format script not executing in the PDF viewer?

JavaScript might be disabled in your PDF reader's security preferences. Go to the settings or preferences menu of your PDF software and ensure that 'Enable JavaScript' is checked.

Can I format the time to include a colon, like 11:00 instead of 11h00?

Yes, you can easily adapt the script. Change the replacement string in the script to insert a colon. Use: event.value = event.value.replace(/(\d{2}$)/, ":$1");.

How do I restrict the text field so users can only type numbers?

In the Text Field Properties dialog, go to the 'Format' tab, select 'Number', and adjust decimal places to 0. Alternatively, use a custom Keystroke script to restrict input strictly to numerical characters.

Does WPS Office support filling out PDFs with these custom scripts?

Yes, WPS Office fully supports standard PDF form filling and processes basic JavaScript actions, ensuring users see the correct formatting when they enter data into the document.