Need to validate second date

New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Hello,

 

I am creating a fillable PDF form using Adobe Acrobat DC. There are two fields that requires the person to select dates - Start and End date. How can we have the End date check to make sure that it is AFTER the Start date? Please see attachment for screen capture.

TOPICS
Create PDFs , JavaScript , PDF forms

Views

174

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Mar 22, 2021 Mar 22, 2021

You will have to write a custom validation script for the end date field. Something like this shoud work (not tested, so there might be errors):

 

var retVal = true;
// get information from "Date1"
var d1 = this.getField("Date1_af_date").value;
if (d1 == "") {
    app.alert("Start date is empty");
    retVal = false;
}
if (retVal && event.value == "") {
    app.alert("End date is empty");
    retVal = false;
}
if (retVal) {
    var d1 = new Date(d1);
    var d2 = new Date(event.value);
    if (d
...

Likes

Translate

Translate
Adobe Community Professional ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

You will have to write a custom validation script for the end date field. Something like this shoud work (not tested, so there might be errors):

 

var retVal = true;
// get information from "Date1"
var d1 = this.getField("Date1_af_date").value;
if (d1 == "") {
    app.alert("Start date is empty");
    retVal = false;
}
if (retVal && event.value == "") {
    app.alert("End date is empty");
    retVal = false;
}
if (retVal) {
    var d1 = new Date(d1);
    var d2 = new Date(event.value);
    if (d1 > d2) {
        app.alert("End date needs to be after start date");
        retVal = false;
    }
}
event.rc = retVal;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Thanks Karl! It works!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Hi Karl, [total newbie] almost the same request, but need a custom validation script for a fillable form that allows the user to only select a future date 30 days from today's date. Thanks in advance—Rudy

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 27, 2022 Jul 27, 2022

Copy link to clipboard

Copied

LATEST

Rudy, please post a new question.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines