You can apply advanced validation to check responses against certain “patterns” or “regular expressions” (RegEx).


Regular expressions use a powerful syntax which you can use to build very complex patterns. See the cheat sheet attached to this article for a reference or try, Regex101 or RegExr, free online tools to help you build your own regular expressions.


Commonly used RegEx examples:


RegEx examples

Explanation

Valid input

 taken

Validates whether the response contains the string "taken".

Undertaken

 ^taken

Validates whether the response starts with the string "taken".

taken over

 ^taken$

Validates whether the response matches the string "taken" exactly.

taken

 ^[0-9]{4}$

Validates whether the response is exactly 4 digits in length.

0063

 ^[0-9]{4,10}$

Validates whether the response is a 4 to 10 digit number.

1234567890

 ^[a-zA-Z0-9]{10}$Validates whether the input is exactly 10 alphanumeric characters in length.

d147s05F2p
 ^[A-Z][a-z]*Validates whether the response starts with an uppercase letter and is followed by any number of lowercase letters.
Start
 ^[vVbB][0-9]{6}$

Validates whether the response begins with either the letter 'V' or 'B' (upper or lower case) followed by a 6-digit number.

B123456

 ^PID[0-9]{4}$Validates whether the response begins with PID (upper case) followed by a 4-digit number.PID1234
^[0-9]{2}-[0-9]{6,7}\s[a-zA-Z]\s[0-9]{2}$
Validates whether the response starts with two digits, a dash, and then six or seven digits; after the 6/7 string of digits there is always a space, then a letter then a space and finally two more digits; not case sensitive.

07-1234567 G 01

 ^(\+?27|0)[6-9][0-9][0-9]{7}$

Validates whether the response is a South African mobile number (including the optional leading international dialling code).

0828091234
+27828091234
^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$Validates whether the input is a valid email address.test-email@gmail.com
 ^\d{4}\/\d{1,}\/\d{2}$Validates whether the input is a valid company registration number which has a format of 4 digits / 1+ digits / 2 digits.

2000/123456/78
^(((\d{2}((0[13578]|1[02])(0[1-9]|[12]\d|3[01])|(0[13456789]|1[012])(0[1-9]|[12]\d|30)|02(0[1-9]|1\d|2[0-8])))|([02468][048]|[13579][26])0229))(( |-)(\d{4})( |-)(\d{3})|(\d{7}))$Validates whether the input is a South African ID number.8808180143089


Hint: Test your validation rules by using the 'Previewbutton on the far right in your top toolbar.  



Examples of adding validation


Validating the mobile number that is entered is exactly 10 digits


  1. Create a new text field to capture the participant's mobile number. (Note: the text field type should be used instead of the number field type for capturing numeric identifiers such a mobile numbers and participant identifiers)
  2. Click on the Validation tab.
  3. Click the 'Configure validation rules' button (if no rules have been set up yet).
  4. Select that the response will only be valid when either 'all' or 'any' of the criteria are met.
  5. Select that the response must match the RegEx criteria by choosing 'matches regex'.
  6. Use the RegEx function to specify the regular expression rules. Ensure you put the pattern in quotes. For example: "^[0-9]{10}$"
  7. An optional error message can be added to give the respondent information on the validation criteria. If the message is blank, the default "Value not allowed" message will be displayed.
  8. Additional validation criteria can be added as needed.





Validating that the identifier matches the required format: 'PID', followed by 4 digits


  1. After adding a text field to capture the PID, click on the Validation tab and select 'Configure validation rules' as per steps 1-3 above.
  2. Select that the response will only be valid when 'all' of the criteria are met.
  3. Select that the response must match the regex criteria.
  4. Specify the regular expression to evaluate the value against - ensure you put the pattern in quotes - in this case: "^PID[0-9]{4}$"