Survey Question Field Validation (INTERPODIA ADMIN ONLY)

How to create regular expression field validation for text field survey questions

Text field survey questions allow for field validation through the use of a regular expression. In short, these expressions limit what text in what format can be entered into a survey question text field.

In Django, these can be set up from 'Survey_App > Survey questions'. Selecting or creating a new survey question, the regular expression is entered in the 'Validation' field:

The example above uses a regular expression that limits the text field to contain a MM/DD/YYYY date.

The following tool can be used to create and validate a regular expression to limit a survey question text field to only contain desired text: https://regex101.com/

In the above screenshot, we can see that it validates the test string as being a 'Full match' when tested against the MM/DD/YYYY date regular expression. The highlighted 'Quick Reference' area will detail the information needed to write a new regular expression. 

When completing a regular expression, please include it in the below list so that it can be re-used in future setups.

Regular Expression List

  • MM/DD/YYYY - either / . or - separating the numbers

^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/?|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:(?:0?2)(\/?|-|\.)(?:29)\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/?|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$

  • One digit, one dash, and 7 digits

(^\d{1}\-\d{7}$)

  • Phone number xxx-xxx-xxxx

([0-9]{3}[-][0-9]{3}[-][0-9]{4})

  • Email example@test.com : any string of characters + @ + any string of characters + . + at least 2 letters

[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}

  • Only numbers, min 2 no limits 

[0-9]{2,}