Requiring Number Validation for Constant Sum Matrix Table | XM Community
Question

Requiring Number Validation for Constant Sum Matrix Table

  • 13 March 2024
  • 5 replies
  • 26 views

Badge +2

Hello! I am working with a constant sum matrix table where respondents input a number that is 0-100 at each column-row intersection and each column totals to 100 at the bottom. Is there a way to further limit them so that they may only input numbers that are increments of 5? E.g., instead of being able to give a 47%, 53% split, they are required to give a 45%, 55% split?

 


5 replies

Userlevel 6
Badge +27

One of the way is to use JS to check number entered on blur event if divisible by 5.

OR we can also use match regex custom validation for each text entry box using below regex:

^[0-9]*[05]$

 

Badge +2

One of the way is to use JS to check number entered on blur event if divisible by 5.

OR we can also use match regex custom validation for each text entry box using below regex:

^[0-9]*[05]$

 

Thank you! Do you know what the JS code would be? There are 170 text entry boxes so i think the regex match would be too manual @Shashi 

Userlevel 6
Badge +27

One of the way is to use JS to check number entered on blur event if divisible by 5.

OR we can also use match regex custom validation for each text entry box using below regex:

^[0-9]*[05]$

 

Thank you! Do you know what the JS code would be? There are 170 text entry boxes so i think the regex match would be too manual @Shashi 

Try this:

jQuery("#"+this.questionId+" input[type='text']").on('blur',function(){
if(jQuery(this).val()%5!=0){
jQuery(this).val('').focus();
alert("Number should be divisible by 5");
}
});

 

Badge +2

One of the way is to use JS to check number entered on blur event if divisible by 5.

OR we can also use match regex custom validation for each text entry box using below regex:

^[0-9]*[05]$

 

Thank you! Do you know what the JS code would be? There are 170 text entry boxes so i think the regex match would be too manual @Shashi 

Try this:

jQuery("#"+this.questionId+" input[type='text']").on('blur',function(){
if(jQuery(this).val()%5!=0){
jQuery(this).val('').focus();
alert("Number should be divisible by 5");
}
});

 

@Shashi Hmm this didn’t work

Userlevel 6
Badge +27

@Shashi Hmm this didn’t work

Please check if the code is pasted in correct function.

Leave a Reply