Permitting only letters, no spaces, in a text field | XM Community
Skip to main content

Hi all,
I've been trying everything I can to make this work and can't figure it out. I'm trying to correct the trailing space that iPhones create when responders autocomplete a text field. (e.g. I want "ABCD" not "ABCD ")
The solution that looks most promising is to use custom validation for the field and I thought I had it correct with "^[A-Za-z]$" but unfortunately, that won't permit anything to be accepted. Can you point out what I'm doing wrong?
Thanks for any and all help,
JMag

^\\D{4}$
More at regex101.com
However, this will only confuse your respondents, as they won't be able to see the trailing space. This JS should do it for you:
Qualtrics.SurveyEngine.addOnReady(function () {
    let prolems_created_by_apple = this.questionContainer.querySelectorAll(".InputText");
    document.querySelector("#NextButton").onclick = function () {
        prolems_created_by_apple.forEach((bad_thing_done_by_iphone) => {
            bad_thing_done_by_iphone.value = bad_thing_done_by_iphone.value.trim();
        });
    };
});


Leave a Reply