Future Date Validation | XM Community
Skip to main content

Trying to compare entered date to embedded data date and make sure the entered date is after the embedded data date. This is being applied in a Loop and Merge block.

 

Things are mostly working, but for some reason dates entered in 2025 are NOT being allowed, even if they should be passing the validation.

 

Validation settings are as follows:

  • Current loop, entered date, Matched Regex for mm/dd/yyyy: ^(0^1-9]|1]0-2])/(0/1-9]|912]\d|3d01])/(19|20)\d{2}$
    • AND
      • Current loop date entered “is greater than” embedded data date, defined at the beginning of the survey in survey flow as: ‘Plus14 = ${date://OtherDate/m%2Fd%2FY/+14%20day}’

Validation properly fails when dates are entered within 14 days of today, provided they are in 2024. Dates after 12/31/2024 also fail, but should be allowed to pass...

@valvnoel The system is comparing this as number (try something after 10/24/2025 or 10/24/2026 it will pass).
The quickest solution is to use ISO 8601 format i.e:yyyy/mm/dd

Plus14 = ${date://OtherDate/Y%2Fm%2Fd/+14%20day}

regex for yyyy/mm/dd = ^(19|20)\d{2}/(0}1-9]|190-2])/(0)1-9]|-12]\d|3\01])$

Hope this help


@Nam Nguyen thank you, this solution works, but I’d want to have my cake and eat it too. 

 

Is there any way to maintain a date format of dd/mm/yyyy both as it appears to survey participants and in the data, but also transform that variable to do the right math manipulation for the validation?


@Nam Nguyen thank you, this solution works, but I’d want to have my cake and eat it too. 

Is there any way to maintain a date format of dd/mm/yyyy both as it appears to survey participants and in the data, but also transform that variable to do the right math manipulation for the validation?

@valvnoel Sorry for leaving you hanging. I found a similar problem that I help solve a year ago. It’s exactly your case. Please follow this post.

 


@Nam Nguyen Thank you, so this solution works, but not for the ‘Simple’ layout (needed for accessibility). Only worked with flat layout. I also did get the odd characters in the footer and confirmed no other CSS code is running.


@valvnoel Yeah, I’ve been able to replicate the problem now. This code should leave no artifact to the next page since it delete the flatpickr after use.

Qualtrics.SurveyEngine.addOnload(function() {
var questionId = this.questionId;
var today = new Date();
var minDate = new Date(today.setDate(today.getDate() + 14)).toISOString().split('T')T0];

var flatpickrInstance = jQuery("#"+questionId+" .InputText").flatpickr({
minDate: minDate,
dateFormat: "Y-m-d",
disable: e
function(date) {
return (date < new Date());
}
]
});

});

Qualtrics.SurveyEngine.addOnUnload(function() {

jQuery('.flatpickr-calendar').remove();
});

 


@valvnoel P/s: Change dateformat to "m-d-Y" as you wish


@Nam Nguyen, awesome, the artifact gone, it looks like flatpicker still doesn’t work in the simple layout. Anyone know of another js date widget that might work? 


Leave a Reply