PDF Editing Issues

Validate a PDF Time Field in Adobe Acrobat

Rana GarciaRana Garcia Nov 19, 2026 868 views

Question details

The user needs a PDF form time field that inserts a colon, rejects letters, and validates the completed time.

Validate a PDF Time Field in Adobe Acrobat
Product
Adobe Acrobat PDF forms
Device & OS
not provided
Scenario
A user enters a time such as 00:00 or 12:59 in a PDF form field.
Observed behavior
The field automatically inserts a colon after two digits, but also needs to reject letters and enforce valid hour and minute ranges.
Before you start

Open the PDF in an Acrobat edition that supports editing form fields and JavaScript. Decide whether the field uses 24-hour time or a separate AM/PM control, and check for existing field scripts that may conflict.

Solution 1Recommended

Add a custom keystroke script to validate the time field

Use this script to reject letters while typing and validate a complete 24-hour time when the field is committed.

The script inserts a colon after the second digit when users type into an empty field. It accepts times from 00:00 through 23:59 and permits an empty value unless the field is marked required.

1
Open the form editor

In Adobe Acrobat, open the PDF and select All tools > Prepare a form. Select the time field and open its Properties.

2
Open the script editor

On the Format tab, choose Custom from the format category menu, then select Edit next to Custom Keystroke Script. If a script already inserts the colon, replace or merge it so that two scripts do not insert it twice.

3
Enter the validation script

Paste this script into the custom keystroke editor: if (!event.willCommit) { if (!/^[0-9:]*$/.test(event.change)) { event.rc = false; } else if (/^[0-9]$/.test(event.change) && /^[0-9]$/.test(event.value) && event.selStart === 1 && event.selEnd === 1) { event.change += ":"; } } else { event.rc = event.value === "" || /^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/.test(event.value); }

4
Save and test the field

Close the properties, save the PDF, and use Preview in Prepare a form. Type 0059 and 1259 to check colon insertion; try letters, 24:00, and 12:60 to confirm invalid input is rejected when you leave the field.

Add a custom keystroke script to validate the time field
Using an AM/PM control: For a separate AM/PM control, replace the 24-hour expression with /^(?:0[1-9]|1[0-2]):[0-5][0-9]$/ to allow 01:00 through 12:59. The script does not add a colon to pasted four-digit values; users should paste a formatted value such as 12:59.
Free Microsoft Office alternative

Work with PDF and Office files in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Office formats, making it easy to move existing files. Use Acrobat to author and test the custom PDF form JavaScript described above; script support can vary by PDF application.

Open and review PDF forms alongside other documentsCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFamiliar interface for a straightforward transition from Microsoft OfficeFree, lightweight suite for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

How do I restrict the field to 12-hour time?

In the custom keystroke script, use /^(?:0[1-9]|1[0-2]):[0-5][0-9]$/ for the committed value. This accepts 01:00 through 12:59 and assumes AM or PM is selected separately.

Why does the field still accept an empty value?

The script explicitly allows an empty value. To require an entry, open the field's Properties in Prepare a form and select Required on the General tab.

Will the script format a pasted time automatically?

The colon insertion in this example is designed for typing into an empty field. Paste a value with the colon, such as 12:59; a pasted value such as 1259 will fail the final format check.

Will the validation work in every PDF viewer?

Not necessarily. PDF viewers differ in their support for Acrobat form JavaScript. Test the saved form in the viewer recipients will use.