Regex validation questions with strings and numbers | XM Community
Skip to main content
Hello,



Our group is developing surveys for a large study, and we give each participant an ID number. For new participants, the format is "AJA-XXXX" where the X's are digits 0-9. For visiting participants, the format is "AJA-XXXX.X." Here are some ID numbers that fit:



> * 1. AJA-2001

> * 2. AJA-2163

> * 3. AJA-2003.1

> * 4. AJA-2002.2

>







However, we don't want the following:

> * aja-2002 (first part not capitalized)

> * AJA3012 (no dash)

> * AJA-2009. (a period, but no digit afterwards)

> * AJA-1008.01 (two digits after the period)

>

After some googling, I came up with ``[t][r][t]\\-\\d{4}[\\.]?[\\d{1}]?`` but it didn't work 😕



I would be extremely grateful for any help or suggestions. Thanks!
I have tried this through javascript..



jQuery("[id='QR~QID15']").bind('keyup', function(e) {



var s=jQuery("[id='QR~QID15']").val();



if(s.length == 😎 {



if(s.substring(0,3) != "AJA" || s.charAt(3) != '-' )

{

alert("Wrong input");

}

else

{

var n=parseInt( s.substring(4,8) );

var i=0;



while(n!=0)

{

n=Math.floor(n/10);

i++;

}



if(i != s.substring(4,8).length)



alert("Wrong input");

}

}



if(s.length>8)



alert("Wrong input");

});
Try this regex:

^AJA\\-[0-9]{4}(\\.[0-9])?$



One issue is that Qualtrics regex validation is case insensitive. So, you'll have to use JavaScript to convert to upper case.

```

Qualtrics.SurveyEngine.addOnload(function() {

jQuery("#"+this.questionId+" .InputText").on('blur', function() {

this.value = this.value.toUpperCase();

});

});

```
hi @sajeevan ,



Regex for this foramt e.g AJA-2001.1: /AJA-[0-9]{4}.[0-9]{1}/g

OR

Regex for this foramt e.g AJA-2001: /AJA-[0-9]{4}/g



You can use this regex in custom validation options.

!

To whoever is searching.

 

For the insensitivity of the letters I simply added the “/” before and after then if works : /^ A-Z]{2}$/

I struggle a long time before figuring that out. Without the “/”s, it is indeed insensitive.


Leave a Reply