Skip to main content
Participant
June 18, 2024
Answered

PDF Form: Date Validation script

  • June 18, 2024
  • 1 reply
  • 1451 views

Good day All,

 

Please could someone kindly assist me with this query?

I would like to do some validation on three date fields "Order Date", "Delivery Date", "Operational Date". (All formatted as date field: dd/mm/yyyy)

 

Validation 1:

If the Delivery Date is less than or equal to the Order Date.

Alert Message: "Delivery date cannot be before the Order date"

 

Validation 2:

If the Operational Date is less than the Delievery Date. 

Alert Message: "Operational date cannot be before the Delivery date"

 

Your help & assistance will be greatly appreciated. I know this can be easily done - I just do not know scripting.

 

Regards

Neil

This topic has been closed for replies.
Correct answer Tariq Dar

Hi there

 

Thank you for this.

 

I tried it but nothing happened  😞


@Neil5E0F Do your Textbox names exactly match with the script given? Is there any syntax error in the console? 

~Tariq

1 reply

try67
Community Expert
Community Expert
June 18, 2024

- What should happen if the other field is empty?

- Should the entered value be rejected if it's invalid?

- What should happen if the user enters a valid value, but then goes back and edits the first field? Should it reset the second field? Re-validated it? Something else?

Neil5E0FAuthor
Participant
June 18, 2024

Hi there,

 

Thank you for your response & valid questions would I never considered. 

 

- What should happen if the other field is empty? 

The 3x date fields will be set as mandatory, so hopefully they completed in order & not left blank. If blank nothing       should happen.

- Should the entered value be rejected if it's invalid?

Yes please

- What should happen if the user enters a valid value, but then goes back and edits the first field? Should it reset the second field? Yes please Re-validated it? Yes please

try67
Community Expert
Community Expert
June 18, 2024

OK, then you can use this code as the custom Validation script of the Delivery Date field:

 

var orderDateString = this.getField("Order Date").valueAsString;
if (event.value && orderDateString!="") {
	var orderDate = util.scand("dd/mm/yyyy", orderDateString);
	var deliveryDate = util.scand("dd/mm/yyyy", event.value);
	
	if (deliveryDate.getTime()<=orderDate.getTime()) {
		app.alert("Error! The Delivery Date is less than or equal to the Order Date.");
		event.rc = false;
	}	
}

 

Note that you'll also need to apply a similar script to the Order Date field, to validate its value against Delivery Date, and the same with Delivery Date-Operational Date.