By using the 'Match' constraint you can validate responses against certain “patterns” or “regular expressions” (RegEx). You can also use validation operators (predefined regular expressions representing common algorithms or formats).


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 RegExr, a free online tool to help you build your own regular expressions.


Some examples of RegEx:


RegEx examples

Explanation

Successful 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. This is equivalent to using the Equals constraint.

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

 ^[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

 ^[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][1-7][0-9]{7}$

Validates whether the response is a South African mobile number (including the leading international dialing code). Alternatively, you could use a validation operator. 

0828091234



Example in form designer: 

Adding validation to a field to ensure the mobile number that is entered is exactly 10 digits long.

  1. Add number/phone field type.
  2. Add 'Match' constraint. 
  3. Enter the relevant RegEx as the constraint's value. 
  4. Select 'Create Constraint'.
  5. Select 'Save'.




Validation operators


Instead of writing your own regular expressions (or when a pattern is too complex to be validated using a regular expression), you can use the following predefined validation operators:

  • VALID_GS1_ID - validates the response according to the GS1 System of identification which allows you to validate barcodes and IDs which make use of a GS1 check digit.
  • VALID_RSA_ID - validates that the response is according to the South African National ID number standard.
  • VALID_RSA_MOBILE - validates that the response is a South African mobile number.
  • VALID_ZWE_MOBILE - validates that the response is a Zimbabwean mobile number.



Example in form designer: 

Adding validation to a field to ensure that the response will be in the format of a valid South African ID number.

  1. Add number/phone field type.
  2. Add 'Match' constraint. 
  3. Enter the relevant RegEx as the constraint's value. 
  4. Select 'Create Constraint'.
  5. Select 'Save'.




Note: Numeric inputs of 10 digits or more cannot be entered; please use a text or phone number question type in these cases.