Regular expressions in terms

Difficulty level: Difficult

Disclaimer: If you have a professional user license, you can use all functions described in this page. However if you are stuck, you need an extended support contract (SLA) to get our assistance. Survalyzer product support does not include regular expressions. Contact our sales team to get a extended support contract.

What does the functionality do?

Regular expressions, also called RegEx, are a description of a sequence of characters that define a search pattern. A more detailed explanation, including a description of the syntax, can be found here: https://en.wikipedia.org/wiki/Regular_expression

NOTE: Regular expressions can only be used on input fields with the datatype Text (None). This means no direct validation can be applied to the input field.

On this page we will show some frequently used regular expressions. They can be used for validations and filters.

Use cases and how to set them up?

IBAN

Multi-national
Example: ES7921000813610123456789

^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$

Germany (with or without spaces)
Example: DE89 3704 0044 0532 0130 00 or DE89370400440532013000

^DE\d{2}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{2}|DE\d{20}$

Switzerland (with or without spaces)
Example: CH93 0076 2011 6238 5295 7 or CH9300762011623852957 or CH9300SURVALYZER0000X

^CH\d{2}[ ][A-Z0-9]{4}[ ][A-Z0-9]{4}[ ][A-Z0-9]{4}[ ][A-Z0-9]{4}[ ][A-Z0-9]{1}|CH\d{2}[A-Z0-9]{17}$

Netherlands
Example: NL91ABNA0417164300

^NL\d{2}[A-Z]{4}0\d{9}$

Email

This is the standard regular expression using the RFC 5322 Official Standard:
Example: john.doe@survalyzer.com

^(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$

Phone numbers

Germany
Allows several formats:
Examples: 004989123456, +49 89 123456, +49(89)123456, 089-1234-5678, 089 1234 5678, (089)1234-5678

^(((((((00|\+)49[ \-/]?)|0)[1-9][0-9]{1,4})[\-/]?)|((((00|\+)49\()|\(0)[1-9][0-9]{1,4}\)[ \-/]?))[0-9]{1,7}([\-/]?[0-9]{1,5})?)$

Switzerland
Allows several formats:
Examples: 044 276 47 44, +41442764744, 00412764744, +41 44 276 47 44

^(0|0041|\+41)?[1-9\s][0-9\s]{1,12}$

Netherlands
Allows several formats:
Examples: 0612345678, +31612345678, 0031612345678, +31(0)61 234 5678

^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9])((\s|\s?-\s?)?[0-9])((\s|\s?-\s?)?[0-9])\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]$

Generic
Allows several formats:
Examples: 089 123 4567/8, 0041-44-276-4744, +31.61.234.5678

^(0|00|\+)[1-9][0-9\s\-\/.]{1,}[0-9]$

ZIP codes

Germany:
Example: 24143

^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$

Switzerland:
Example: 5033

^([1-468][0-9]|[57][0-7]|9[0-6])[0-9]{2}$

Netherlands:
Example: 1000AB

^[0-9]{4}\s*[a-zA-Z]{2}$

If, in an open question, only the following postal codes may be entered by a participant: 3131, 3132, 3133, 3134, 3135, 3136, 3137 and 3138, you can use, for example, the following regular expression:

^(313[1-8])$

Years

When you are asking a participant for his/her year of birth in a survey, you can use an open question with the response data type None (Text) for this. You can define an upper and lower limit for this birth year. This can be done by means of a regular expression. Suppose a participant enters the year 2010 while you have indicated using a regular expression that the year of birth should be between 1900 and 2007, then the validation fails and the participant will have to enter another year of birth until the validation is successful.

After you have included an open question asking for the year of birth, you can add a validation element to the survey. In this element, you can record the following information:

  • The error message a participant will see when he/she enters a year of birth that is NOT between the defined period (here: 1900 up to 2007).
  • The filter condition on the Filter window which you can launch using the Edit conditions button. The condition can then look like this:
    • Hide this validation message
    • if – Question – q3 What is your year of birth? – matches Regex – ^(19[0-9]\d|200[0-7])$

In order to save the filter condition, you obviously still need to click the green Save changes button.

Examples

  • Year must be between 1900 and 2099: ^(19|20)\d{2}$
  • Year must be between 1900 and 2007: ^(19[0-9]\d|200[0-7])$
  • Year must be between 1950 and 2030: ^(19[5-9]\d|20[0-2]\d|2030)$
  • Year must be between 1945 and 2023: ^(194[5-9]|19[5-9]\d|200\d|201\d|202[0-3])$
  • Year must be between 1935 and 2023: ^(193[5-9]|19[4-9]\d|200\d|201\d|202[0-3])$

Updated on February 7, 2024

Was this article helpful?

Related Articles

Need Support?
Please login to your Survalyzer account and use the "Create Support Request" form.
Login to Survalyzer