Validation Recipies - SurveyEngine GmbH

Validation Recipies

All input validation in SurveyEngine is achieved using custom perl code.

Where to input the validation

In this example we will assume the use input is given by the variable named ‘input’. Validation is enabled by checking the ‘Validation’ checkbox, entering the boolean expression test and the error message if the test fails, as below

When addressing this variable in perl code – you need to call it $input

While any validaiton expressions can be used, ‘regular expresssions’ (a RegEx) are the most widely used method for general pattern matching.

A great resource is the excellent site regex101.com

Regex – the basic pattern

$input =~/pattern/

RegEx expressions have 3 parts. The variable you are matching ($input), the regex operator (=~) and then the pattern (/the pattern/)

RegEx Recipies

Email matching – simple

$input=~/.+@.+/

* note, this just ensures there is an @ symbol somwhere in the middle of a string

Date Matching – dd/mm/yyyy

$input =~ /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/

Note this will not match iinvalid dates like 31/02/2022

2 decimal places – 2343.99

$input =~/^\d+\.\d\d$/

complicated huh? Here’s what’s going on

  • ^means starting with, i.e. no spaces
  • \d+ One of more digits (same as [0-9])
  • \. Matches the period character
  • \d\d Matches the two decimal places
  • $ means end of the line, i.e. no trailing spaces

Scroll to Top