This is how you best format email addresses

Usually you can find email addresses as attribute of a lot of entities, e.g. "user", "owner", or "contact" in various third party systems. This depends on the system, but the output often looks something like this:

  "first_name": "Oliver",
  "last_name": "Doe",
  "email": "",

However, sometimes the email might be a free-form text field in the third party system, so some customers add a comment or even just use non-valid emails. Here are two examples:

  1. "email": " (brother)"

  2. "email": "oliver.doe@go"

In theses cases we have to make sure that the email is either fixable or recognized as a non-valid email. One can use the following Jinja code to do so:

 "email": {% if != None %}{% set mail_list = regex_search(, "([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+" ) %}{% if probe(mail_list, 0) %}"{{ mail_list.0 }}"{% else %}""{% endif %}{% else %}""{% endif %}

This returns the email in a correct format, or if it's not possible, an empty String "". For our examples that would mean:

  1. "email": ""

  2. "email": ""

Last updated