Requiring Number Validation for Constant Sum Matrix Table | XM Community
Skip to main content
Question

Requiring Number Validation for Constant Sum Matrix Table

  • March 13, 2024
  • 5 replies
  • 51 views

Forum|alt.badge.img+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

Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+34
  • Level 8 ●●●●●●●●
  • 654 replies
  • March 13, 2024

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]$

 


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 11 replies
  • March 13, 2024

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 


Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+34
  • Level 8 ●●●●●●●●
  • 654 replies
  • March 13, 2024

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");
}
});

 


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 11 replies
  • March 13, 2024

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


Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+34
  • Level 8 ●●●●●●●●
  • 654 replies
  • March 13, 2024

@Shashi Hmm this didn’t work

Please check if the code is pasted in correct function.