Regex Validation in a Form Question | XM Community
Skip to main content
I am trying to add validation to a form field. I would like the question to pass if the respondent has entered 6 digits - leading 0s are okay.

I have added Numerical Value as the validation and added the custom validation if Matches Regex ^[0-9]{6}$. However, when I test, it isn't recognizing the leading 0s. So, 000123 will not pass validation. What step am I missing? Thanks!
Hi @ttaggart

I am not sure why you are facing that problem as i tried your regex (i.e. ^[0-9]{6}$ ) seems o be working fine when i tried it.

Maybe your custom validation might not have been saved or you can try again publishing the survey.

Another Alternative for your regex code can be "^\\d{6}$".
Hi @NiC,



Thanks for looking at it! Did you use it in a form question? I double-checked my code and tried re-publishing my survey and it is still not allowing me to pass validation using a leading 0. When I tried 123456 it worked. When I tried 000123 I did not pass validation. I also used your alternate code and experienced the same thing.
Hi @ttaggart

Sorry i didn't try on the form data type.

If you remove any validation(like the numerical or any other) from the form entry you are verifying with the regex .

!

Here is an example of the code you want.

Survey Preview
@NiC Thank you! This worked perfectly.

I'm having the same issue? So I was hoping to see the answer, but it looks like ttaggart that you said you tried the alternate regex, and it didn't work. And then you said "Thank you! This worked perfectly." - But I don't see what you did that worked perfectly? Can you please share what worked?


mklubeck
My regex was correct, but I needed to change my validation on the form field to 'No Validation'
image.pngimage.png


Leave a Reply