Validation for each character in a text entry question | XM Community
Skip to main content
Solved

Validation for each character in a text entry question

  • December 23, 2023
  • 2 replies
  • 200 views

Forum|alt.badge.img+1

I have a text entry question which needs to have the following format:

-it needs to be exactly 6 characters long

-The first character can only be one of the letters p,m.l,k,n (both uppercase and lowercase are fine)

-The second character can only be a number

-The next three can only be letters (any letter, uppercase or lowercase)

-The last one has to be a number. 

How can I set this on the survey platform?

Best answer by omkarkewat

Hi @avantika23 
You can use custom validation in the text entry question and set condition as matches regex = ^[pmlk'nPMLK'N]\d[a-zA-Z]{3}\d$

 

Explanation of the regex:

^: Asserts the start of the string.
[pmlk'nPMLK'N]: Matches one of the specified letters (p, m, l, k, n, P, M, L, K, N).
\d: Matches a digit (0-9).
[a-zA-Z]{3}: Matches three letters (any case).
\d: Matches another digit.
$: Asserts the end of the string.

2 replies

Forum|alt.badge.img+21
  • QPN Level 5 ●●●●●
  • 306 replies
  • Answer
  • December 25, 2023

Hi @avantika23 
You can use custom validation in the text entry question and set condition as matches regex = ^[pmlk'nPMLK'N]\d[a-zA-Z]{3}\d$

 

Explanation of the regex:

^: Asserts the start of the string.
[pmlk'nPMLK'N]: Matches one of the specified letters (p, m, l, k, n, P, M, L, K, N).
\d: Matches a digit (0-9).
[a-zA-Z]{3}: Matches three letters (any case).
\d: Matches another digit.
$: Asserts the end of the string.


Forum|alt.badge.img+1
  • Author
  • 1 reply
  • December 28, 2023

Thank you!