Fix a Date Range Validation Script in Adobe Acrobat Reader
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.

- 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.
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.
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.
Open the PDF in Adobe Acrobat Pro and choose All tools > Prepare a form. Select the date field and open its Properties.
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; }
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.
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.

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.

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.




