Custom validation set with numeric range from URL query string | XM Community
Skip to main content

I have an anonymous survey link onto which I’ve added some query strings. For one of the URL query strings I would like to set a range rather than a consistent value, so urlexample.com?id_range:01-100

 

Then I would like to have a text entry question with custom validation (I believe the best way to do this, though maybe just in the java editor) to only accept answers within the range specified in the URL query string range (so in the example, 01 through 100).

 

I do have id_range set as an embedded variable from the URL in the survey flow.

 

Thank you!

I think this is doable using JS in the question editr. I am that id_range from the URL as an embedded variable (e.g., id_range = 01-100) has already been capture.d
 

Qualtrics.SurveyEngine.addOnload(function() {
// Get the embedded variable
var range = "${e://Field/id_range}".split("-");
var min = parseInt(range[0], 10);
var max = parseInt(range[1], 10);

var input = this.getQuestionTextContainer().querySelector("input");

this.questionclick = function(event, element){
var val = parseInt(input.value.trim(), 10);
if (isNaN(val) || val < min || val > max) {
alert("Please enter a number between " + min + " and " + max + ".");
return false;
}
return true;
};
});

Let me know if it helps.
Rochak