Regex Validation in a Form Question | XM Community
Solved

Regex Validation in a Form Question

  • 3 January 2019
  • 6 replies
  • 465 views

Badge +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!
icon

Best answer by NiC 4 January 2019, 16:02

View original

6 replies

Userlevel 7
Badge +27
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}$".
Badge +2
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.
Userlevel 7
Badge +27
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
Badge +2
@NiC Thank you! This worked perfectly.
Userlevel 6
Badge +8

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?

Badge +2

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