Custom Validation to allow only numbers and decimals (no commas or $) | XM Community
Skip to main content

Hi, I have a matrix table where we want respondents to enter monetary values. We currently have it set with numerical validation, but we realized our analysis will run much smoother if respondents CANNOT enter commas, only decimals if need be. 

I tried using custom validation with matches regex using this code: ^^0-9]+$ 

But that does not work, I get an error even when only numbers are entered (no , or . ) I also tried some other code I found in other discussions, but those are a few years old and did not work either. 

Does anyone have a custom code that would allow these parameters? 

 

Thank you!

Can you use Custom Validation, with conditions where each field Does Not Contain a comma? Something like this:

 

 


That does solve the comma issue, but we want only numerical values to be entered as well. So with the way you suggest, respondents can now enter any character and numerical values, just no commas. 


Are you able to change the Matrix Type selection to “Constant Sum”? If so, that will prevent characters from being entered once they move to the next page.

 


Hi…

try to use the below js code

might work..

Qualtrics.SurveyEngine.addOnload(function() {
    var table = jQuery("#TABLEID"); // Replace TABLEID with the actual ID of your matrix table
    table.on("input", "input"type='text']", function() {
        var value = jQuery(this).val().trim();
        if (value !== "") {
            if (!/^\d+(\.\d{1,2})?$/.test(value)) {
                jQuery(this).val("");
            }
        }
    });
});
 


Use this regex instead on the class

^\d+(\.\d+)?$
 


Leave a Reply