PDF Editing Issues

Fix a Date Range Validation Script in Adobe Acrobat Reader

Elise WilliamsElise Williams Nov 18, 2026 869 views

Question details

The user needs a PDF form validation script that accepts dates from 2022 and alerts users when a date is outside that year.

Fix a Date Range Validation Script in Adobe Acrobat Reader
Product
Adobe Acrobat Reader DC
Device & OS
not provided
Scenario
A custom Acrobat JavaScript validates a date entered in a PDF form field.
Observed behavior
The script does not correctly validate dates in Acrobat Reader DC.
Before you start

Check the date format configured for the form field and use the same format in the script. You need a PDF form editor such as Adobe Acrobat Pro to change the field's validation script; Acrobat Reader can be used to test the completed form.

Solution 1Recommended

Parse the form date before checking its year

Use an Acrobat Date object to check whether the entered date falls in 2022.

Date.parse() returns a number, so calling getFullYear() directly on its result does not work. Acrobat's util.scand() parses the field value into a Date object using the specified format.

1
Open the form for editing

Open the PDF in Adobe Acrobat Pro and choose All tools > Prepare a form. Select the date field and open its Properties.

2
Replace the validation script

On the Validate tab, choose Run custom validation script and click Edit. Replace the existing code with: var d = util.scand("mm/dd/yyyy", event.value); if (!d || d.getFullYear() != 2022) { app.alert("Invalid date"); event.rc = false; }

3
Match the field format

On the field's Format tab, check the configured date format. Change "mm/dd/yyyy" in the script if the form uses a different format.

4
Save and test the form

Save the PDF, open it in Acrobat Reader, and enter dates from 2022 and another year. Move out of the field after each entry to trigger validation.

Parse the form date before checking its year
Check JavaScript settings: If the validation does not run in Reader, open Preferences > JavaScript and check that Acrobat JavaScript is enabled. Test the PDF in Reader rather than a browser PDF viewer, which may not support the same scripts.
Free Microsoft Office alternative

Work with PDF forms and Office files in WPS Office

WPS Office is a free, lightweight alternative for everyday document work, with a familiar interface and support for common Microsoft Office formats to make migration easier. It can help you view PDF forms, but it does not fix Acrobat Reader's JavaScript validation.

Open and view PDF forms alongside other documentsCompatible with Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface for everyday office tasksMove between common Office files without changing your workflow
QA img-9

Frequently Asked Questions

Why does getFullYear() fail after Date.parse()?

Date.parse() returns a numeric timestamp, not a Date object. Use util.scand() with the form's date format to obtain a Date object before calling getFullYear().

Where do I add the date validation script?

In Acrobat Pro, choose All tools > Prepare a form, open the date field's Properties, and select Validate > Run custom validation script > Edit.

Can I change the validation script in Acrobat Reader?

Acrobat Reader is intended for filling and testing the form, not editing its field scripts. Use a PDF form editor such as Acrobat Pro to update the script.

What if the form uses a different date format?

Check the field's Properties > Format tab and replace "mm/dd/yyyy" in util.scand() with the format configured for that field.

Why does the alert not appear when I test the form?

Check Preferences > JavaScript in Acrobat Reader to make sure Acrobat JavaScript is enabled. Open the saved PDF in Reader and move out of the date field to trigger validation.