Alpha Numeric Validation with a set character range | XM Community
Skip to main content
Solved

Alpha Numeric Validation with a set character range


Hello!
I'm trying to set up a regex validation between 6-7 characters that could be either numbers or letters, I was trying to work with this code:
[a-zA-Z0-9]{6,7}
But the code isn't validating, it's letting anything in. Can someone let me know what's wrong with the above?

Best answer by ahmedA

You are not enforcing a string length, therefore, even if the text is 100 chars long, as long as it had a sequence of 6 or 7 letters and numbers, it'll pass.
Add the start of and end of string tokens to get it to work:

^[a-zA-Z0-9]{6,7}$

View original

4 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2028 replies
  • Answer
  • March 25, 2021

You are not enforcing a string length, therefore, even if the text is 100 chars long, as long as it had a sequence of 6 or 7 letters and numbers, it'll pass.
Add the start of and end of string tokens to get it to work:

^[a-zA-Z0-9]{6,7}$


  • Author
  • 2 replies
  • March 25, 2021

https://www.qualtrics.com/community/discussion/comment/36022#Comment_36022Thank you so much, that seemed to do the trick! So putting ^ at the beginning and $ at the end is what's enforcing the {6,7}?


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2028 replies
  • March 25, 2021

Yes. You can read more and even tryout things here: regex101.com


  • Author
  • 2 replies
  • March 25, 2021

Leave a Reply