Using Regex for a custom validation | XM Community
Skip to main content

Hi,
I've an ID that follows a specific format, & I want to enforce that this format is adhered to during input using custom validation. Looks like I might be able to do this using Regex. I'm new to Regex, & haven't been able to get my head around it just yet:

The ID is made of 3 parts following this format:
Always starts with P0
then 2 numbers
then 3 numbers

Any help/advice would be greatly appreciated!
Thanks!

Matches Regex:

^P0\\d{5}$


Perfect, thank you! (I see where I as going wrong now).


I good place to get started with Regex is www.regex101.com. It provides quite a good explanation for the expression one enters.


Hi,
Similarly, I also need an ID that follows a specific format for custom validation. I am totally clueless about REGEX, can someone please help?
The ID is made of 3 parts following this format:
Always starts with a "B"
then 1-digit or 2-digit number (maximum 2)
followed by a "-"
then 1-digit or 2-digit number (maximum 2)

for example, B8-2, B12-8, or B11-13
Any help/advice would be greatly appreciated!
Thank you!


https://community.qualtrics.com/XMcommunity/discussion/comment/49135#Comment_49135Matches Regex:

^B\\d{1,2}-\\d{1,2}$


Thank you, Tom! You are my lifesaver! It worked!


Hi,
I now find out that some of the IDs may include alphabets (small letters or CAP). So, the custom validation needs to follow the following format:
Always starts with a "B"
then 1-digit or 2-digit number or alphabet (small or CAP) [maximum 2]
followed by a "-"
then 1-digit or 2-digit number or alphabet (small or CAP) [maximum 2]
for example, B8-2a, B12-c8, or B11-VA
How should the Regex be changed to? Please help. Thank you in advance!


https://community.qualtrics.com/XMcommunity/discussion/comment/49290#Comment_49290Regex Matches: ^B[a-zA-Z0-9]{1,2}-[a-zA-Z0-9]{1,2}$


Thank you, Tom! I'm so grateful for your help!


Hi,

I’m new to regex. If I wanted the ID to be text only with a maximum of 6 letters long. What would be the expression for this?

 

Thank you,

Keri


Hi,

I’m new to regex. If I wanted the ID to be text only with a maximum of 6 letters long. What would be the expression for this?

 

Thank you,

Keri

@kerikw  ^dA-Za-z]{1,6}$


Thanks a lot Nam Nguyen! 

 

If I have a preset list, do you know whether I can match the answer in the form to that list? I realised that I don’t have access to ‘autocomplete’ and I’m trying to match participant’s ID number of their school to an existing list that I have. I’m not sure what the best way of doing this is. Any help would be most appreciated! 

E.g.,

I have pre-assigned a list of codes to specific schools (e.g. ,SchoolID).

I’d like to have participants type in this ‘schoolID’ in the form. And I want to double-check that what they have typed in matched the ‘SchoolID’ from my existing database/list. 

How would I set this up?

 

Best,

Keri


You could convert the school id form field to a drop-down.  If you are interested, the formSelects function does that.


Thanks Tom! 

I thought of that as an option too, but the list will be in the 150+ and because of GDPR, I’m hoping that participants don’t need to see which other schools are taking part. 

 

Do you think there’s another way of matching a participant’s response on the form to a database?

 

Best,
Keri


@kerikw,

Yes, you could put all the codes in an array, and check to make sure the entered code is in the array. I would add a hidden field to flag correct answers and base the validation off that.  


Leave a Reply