Regex Validation in a Form Question | XM Community
Skip to main content
Solved

Regex Validation in a Form Question

  • January 3, 2019
  • 6 replies
  • 678 views

Forum|alt.badge.img+2
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!

Best answer by NiC

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

6 replies

NiC
QPN Level 5 ●●●●●
Forum|alt.badge.img+27
  • QPN Level 5 ●●●●●
  • 255 replies
  • January 3, 2019
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}$".

Forum|alt.badge.img+2
  • Author
  • 6 replies
  • January 4, 2019
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.

NiC
QPN Level 5 ●●●●●
Forum|alt.badge.img+27
  • QPN Level 5 ●●●●●
  • 255 replies
  • Answer
  • January 4, 2019
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

Forum|alt.badge.img+2
  • Author
  • 6 replies
  • January 4, 2019
@NiC Thank you! This worked perfectly.

mklubeck
Level 3 ●●●
Forum|alt.badge.img+8
  • Level 3 ●●●
  • 233 replies
  • May 22, 2020

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?


Forum|alt.badge.img+2
  • Author
  • 6 replies
  • June 11, 2020

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