Examples for validation rules

Several examples of regular expressions for custom data types

The following examples are shown concretely:

  • Excluding specific characters or words
  • English date format validation
  • Date and time validation
  • Dutch zip code validation
  • Numbers with a dot as the decimal separator

The configuration of the validator can be found under Constraints > Datatype > regular expression. Here you will find two fields, "Regexp" and "Error message". Enter the regular expression in the first field, and an error message in the second field. The error message is shown when the user enters invalid data that does not match the regular expression. Further information is available here.

Validator for excluding # (hash) and % (percent)

Regular expression:

^[^#%]*$

 

To exclude further characters, you have to insert the sign inside the square brackets. If the characters that are not allowed become more, it would be better to reverse this and instead put the allowed characters in the regular expression. For example only hash and percent are allowed: ^[#%]*$

Validator for excluding the word 'test'

Regular expression:

^(^(?!.*on).*)$

Validate date in format dd-mm-yyyy

Regular expression:

^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[13456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])-02-((19|[2-9]\d)\d{2}))|(29-02-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$

Validate date and time in format dd.mm.yyyy hh:mm

Regular expression:

^(((0[1-9]|[12]\d|3[01])\.(0[13578]|1[02])\.((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\.(0[13456789]|1[012])\.((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\.02\.((19|[2-9]\d)\d{2}))|(29\.02\.((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))) (([0-1]{0,1}[0-9]{1})|([2]{1}[0-3]{1})){1}[\:]{1}[0-5]{1}[0-9]{1}$

Validate dutch zip code

Regular expression:

^\d{4} ?[aA-zZ]{2}$

 

You may enter up to 7 characters.

Validate numbers with a dot as the decimal separator

Regular expression:

^[\-\+]?((([0-9]{1,3})([\.][0-9]{3})*)|([0-9]+))?([\.]([0-9]+))?$