Alphanumeric validation | XM Community
Solved

Alphanumeric validation


  • Anonymous
  • 0 replies

Hi Can someone guide how to ensure text entere is Alppha numeric of 21 characters.

icon

Best answer by ClairJ 27 May 2020, 16:40

View original

2 replies

Userlevel 3
Badge +2

Rock can you read JavaScript, this is what I used before to enforce a validation on phone number using JavaScript:
Qualtrics.SurveyEngine.addOnload(function () {
    const qC = this.questionContainer;
    const tempInput = qC.querySelector('.QuestionBody input');
    try {
        tempInput.type = 'tel';
tempInput.pattern = "\\\\d{10,12}";
tempInput.addEventListener('input',eL,false);
//console.log('ver: 88893');
    } catch (err) {
        console.log('change input type failed.');
    }
});
function eL(e){
this.value = this.value.replace(/\\D/g,'');
if(this.value.length > 12){
this.value = this.value.substr(0,12);
}
/*
if ((this.value.length < 10) || (this.value.length > 12)){
console.log('not valid length');
}else{
console.log('valid length');
}
*/
}

Userlevel 5
Badge +15

Hi Rock you can use Regex validation for this. In your question settings, under Validation Type, select Custom Validation. Under choice, select "Click to select question text", and then in the next dropdown, select "Matches Regex". In the last box, enter your regex code.
I think this code will do it, but you can use this regex tester if you need to: ([a-zA-Z0-9]{21})

Leave a Reply