Conditioning/Logic on Matches Regex | XM Community
Skip to main content
I want to condition on a question that has a custom validation Matches Regex (code: ^((0[1-9])|(1[0-2]))\\/((19[0-9][0-9])|(20[0-1][0-9]))$ which allows the user to simply type the mm/yyyy as opposed to a full date). If the date is less than 12/2018, then I want to ask a subsequent question. If the answer is 12/2018 or "higher" (e.g. 01/2019) then I will not ask the subsequent question.
Hello @rstage ,



Please follow the below steps:



Step 1: Create an embedded data(qdate) in the survey flow before date question



Step 2: Paste the below code in the js(onReady) of the date question.



var that=this.questionId;

jQuery("#"+that+" .InputText").on('blur',function(){

var selected = jQuery("#"+that+" .InputText").val();

var s=selected.split("/");

var s1=s[1]+s[0];

console.log(s1);

Qualtrics.SurveyEngine.setEmbeddedData('qdate',s1);

});



Step 3: If the user enters 01/2016 then the js will set the embedded data (qdate) to 201601, Now we can compare this date with 201812, as two numbers.



Step 4: Add display logic to question - if embedded data (qdate) is less than 201812.

Leave a Reply