I have one of these composite ID questions that require two digits each from first name, last name, month of dob and day of dob.
On the last two validation can be set for a numeric range, which is fine except that it will allow for a single character. The first two, can be set two either character data type, or a character limit of 2, but not to meet both of these criteria. I am thinking that this will require custom code, and can find examples of regex and other code that would do the validation, but I am too much of a novice to get the values from the questions, examine the input and write out the error text etc. to make this work. Am I right thinking that this can not be done without custom code? I know the question is way to simple for sages and wizards, but if you would point me to a resource or have some code I could use, I will really appreciate it.
Thanks in advance for any help you can give!
Page 1 / 1
Hello @MImre
As I understood from your above query you can do this with javascript .Kindly Have a look at the code snippet below and find the QSF File for Example:
VALIDATION OK CONDITION:First Two of Fname,Lname,dob_day,dob_Month
VALIDATION NOT OK :ANY OTHER THAN ABOVE CONDITION
PREVIEW LINK :https://ugamsandbox.ca1.qualtrics.com/jfe/form/SV_dfXD7V5RsUN0cJf
Qualtrics.SurveyEngine.addOnload(function()
{
var F_name,L_Name,DOB,DOB_Day,DOB_Month,PASS,C_Pass,PASS1;
this.questionclick=function(event,element)
{
document.getElementById('QR~QID5~87').addEventListener("input", function(){
F_name= document.getElementById('QR~QID5~87').value ;
F_name=F_name.substring(0,2);
});
document.getElementById('QR~QID5~88').addEventListener("input", function(){
L_Name= document.getElementById('QR~QID5~88').value ;
L_Name= L_Name.substring(0,2);
});
document.getElementById('QR~QID5~89').addEventListener("input", function(){
DOB_Day= document.getElementById('QR~QID5~89').value ;
DOB_Day=DOB_Day.substring(0,2);
});
document.getElementById('QR~QID5~90').addEventListener("input", function(){
DOB_Month= document.getElementById('QR~QID5~90').value ;
DOB_Month= DOB_Month.substring(0,2);
});
document.getElementById('QR~QID5~91').addEventListener("focusout", function(){
PASS= document.getElementById('QR~QID5~91').value ;
C_Pass= F_name+ L_Name+ DOB_Day+DOB_Month;
console.log(C_Pass);
PASS1=PASS
if(C_Pass== PASS1)
{
alert("passok");
}
else
{
alert("wrongpass");
}
});
}
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
As I understood from your above query you can do this with javascript .Kindly Have a look at the code snippet below and find the QSF File for Example:
VALIDATION OK CONDITION:First Two of Fname,Lname,dob_day,dob_Month
VALIDATION NOT OK :ANY OTHER THAN ABOVE CONDITION
PREVIEW LINK :https://ugamsandbox.ca1.qualtrics.com/jfe/form/SV_dfXD7V5RsUN0cJf
Qualtrics.SurveyEngine.addOnload(function()
{
var F_name,L_Name,DOB,DOB_Day,DOB_Month,PASS,C_Pass,PASS1;
this.questionclick=function(event,element)
{
document.getElementById('QR~QID5~87').addEventListener("input", function(){
F_name= document.getElementById('QR~QID5~87').value ;
F_name=F_name.substring(0,2);
});
document.getElementById('QR~QID5~88').addEventListener("input", function(){
L_Name= document.getElementById('QR~QID5~88').value ;
L_Name= L_Name.substring(0,2);
});
document.getElementById('QR~QID5~89').addEventListener("input", function(){
DOB_Day= document.getElementById('QR~QID5~89').value ;
DOB_Day=DOB_Day.substring(0,2);
});
document.getElementById('QR~QID5~90').addEventListener("input", function(){
DOB_Month= document.getElementById('QR~QID5~90').value ;
DOB_Month= DOB_Month.substring(0,2);
});
document.getElementById('QR~QID5~91').addEventListener("focusout", function(){
PASS= document.getElementById('QR~QID5~91').value ;
C_Pass= F_name+ L_Name+ DOB_Day+DOB_Month;
console.log(C_Pass);
PASS1=PASS
if(C_Pass== PASS1)
{
alert("passok");
}
else
{
alert("wrongpass");
}
});
}
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Hello @sankeskumar,
Thank you for responding to me question!
If I am reading your java code correctly, it will pull the first two characters of the first and last name, then do same for dob, and then put it together as the full ID, and test to see if meets criteria.
What I need is slightly different, I have 4 questions each with a textbox. First is the first name, then lastname, then the dob month and day fields. The user is asked to input only two characters for each of the textboxes. What I have to do is to pull the Question ID and test that the input is character or numeric, and that it is exactly two characters long.
For character validation it is something like this:
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
var value1 = this.questionId;
if (value1.search(/[^a-zA-Z]+/)) {
alert("There are non characters.");
}
});
This works except it seems to examine every field on the page, so I will need to limit it to the correct question ID. I am hoping to have four separate validation steps, one each for each of the fields, providing a warning (preferable in red letters next to the textbox like standard qualtrics error message) when the input does not meet criteria.
Does that make sense?
Again, I appreciate you taking the time looking into my question!
Thank you for responding to me question!
If I am reading your java code correctly, it will pull the first two characters of the first and last name, then do same for dob, and then put it together as the full ID, and test to see if meets criteria.
What I need is slightly different, I have 4 questions each with a textbox. First is the first name, then lastname, then the dob month and day fields. The user is asked to input only two characters for each of the textboxes. What I have to do is to pull the Question ID and test that the input is character or numeric, and that it is exactly two characters long.
For character validation it is something like this:
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
var value1 = this.questionId;
if (value1.search(/[^a-zA-Z]+/)) {
alert("There are non characters.");
}
});
This works except it seems to examine every field on the page, so I will need to limit it to the correct question ID. I am hoping to have four separate validation steps, one each for each of the fields, providing a warning (preferable in red letters next to the textbox like standard qualtrics error message) when the input does not meet criteria.
Does that make sense?
Again, I appreciate you taking the time looking into my question!
Hello @MImre ,
1. For first and last name validation use "matches regex" in "custom validation" option and enter the following code(without quotes) in the box beside "match regex" :
"^[A-Za-z]{2}$"
2. For month and day validation use "matches regex" in "custom validation" option and enter the following code(without quotes) in the box beside "match regex" : "^[0-9]{2}$"
1. For first and last name validation use "matches regex" in "custom validation" option and enter the following code(without quotes) in the box beside "match regex" :
"^[A-Za-z]{2}$"
2. For month and day validation use "matches regex" in "custom validation" option and enter the following code(without quotes) in the box beside "match regex" : "^[0-9]{2}$"
Hi Shashi,
Thank you for that response, that must be the easiest way of getting this done. Actually, I can't believe I didn't see this there (I did look, but somehow missed it). Thanks again, great advice!
Thank you for that response, that must be the easiest way of getting this done. Actually, I can't believe I didn't see this there (I did look, but somehow missed it). Thanks again, great advice!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.