Date Validation

Copy link to clipboard
Copied
Hi All,
I have two date boxes on my PDF form. One start date and One end date. I need to validate the end date to ensure it is never more than One year after the start date.
For example.
Start date: 19/01/2017
End Date: 19/08/2017
^^^^ This is okay. However, If this happens;
Start date: 19/01/2017
End Date: 19/03/2018
^^^^ I would like an error message to pop up saying "End Date cannot be more than 12 months from the start date." and the box to be empty so the user can enter the correct date.
Does anybody if this is possible and if so, how do I do it?
Any help is appreciated.
Thanks
Copy link to clipboard
Copied
Hi Sam Orchard,
Did you try the Validate tab in the property dialog?
You can access the same by
1. Right clicking the desired field.
2. Click "Properties"
3. Go to "Validate" tab.
You can perform the validation in this tab.You can run a custom validation script here to suit your needs.
You can also refer to the forum post for more details around the javascript validations Date validation

Copy link to clipboard
Copied
I know where the script would go, but I don't the script....
Copy link to clipboard
Copied
Have a look at the following forum post Date validation
This may help you

Copy link to clipboard
Copied
Not quite what I'm looking for....

Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi.
Try this JavaScript as a Validation script in the end date field:
var startDat = new Date(this.getField("start").value);
var endDat = new Date(event.target.value);
var nStartDat = startDat.getTime();
var nEndDat = endDat.getTime();
var nMilliResult = (nEndDat - nStartDat) * 1;
if (nMilliResult > 31556952000) {
app.alert("End Date cannot be more than 12 months from the start date.");
event.rc = false;
} else {
console.clear();
console.show();
console.println("Difference is less than a year");
}
You should remove the else statement after testing.
PDF Acrobatic, InDesigner & Photoshoptographer

Copy link to clipboard
Copied
Hi JR_Bouley,
Almost perfect!!! The only issue is the app.alert only pops up if they clear the end date date field then tab.
I need it to pop up as soon as they enter the wrong date and try to tab out.... so basically it's impossible to put a date in 12 months after the "Start_Date".
As the image below, it shouldn't let me tab out of the completion date if i've entered 25/03/2018.
Thanks for your help.
Cheers,
Sam

Copy link to clipboard
Copied

