Ignore spaces in numerical validation | XM Community
Skip to main content
Question

Ignore spaces in numerical validation

  • March 16, 2021
  • 1 reply
  • 66 views

Hi all,
I am looking for a solution that allows a question to pass a numerical validation condition if there is also a space in the question. For example, the following question:
How many employees does your organisation have?
If I write an answer such as 40, but with a space in front or after the number, the validation won't pass. Is there some way around this issue?
Regards,
Michael

1 reply

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2028 replies
  • March 17, 2021

You can add this JS to take care of that:
Qualtrics.SurveyEngine.addOnReady(function () {
    let qc = this.questionContainer;
    document.querySelector("#NextButton").onclick = function () {
        qc.querySelectorAll(".InputText").forEach((input) => {
            input.value = input.value.trim();
        });
    };
});

The validation will still fail if there are spaces between numbers.