Alphanumeric validation | XM Community
Skip to main content
Solved

Alphanumeric validation

  • May 22, 2020
  • 2 replies
  • 156 views

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

Best answer by ClairJ

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

2 replies

Forum|alt.badge.img+2
  • Level 2 ●●
  • 99 replies
  • May 26, 2020

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');
}
*/
}


ClairJ
Level 4 ●●●●
Forum|alt.badge.img+15
  • Level 4 ●●●●
  • 218 replies
  • Answer
  • May 27, 2020

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