Validatio Velectrica: Email Input Validation I

Validatio, validationis (feminine noun) – validation; approval; confirmation.
Velectrica, velectricae (neuter noun) – electric.

Table of Contents

Input validation lets us ensure only properly formed data is entering the workflow in an information system, preventing malformed data from reaching the database and triggering malfunction of various downstream components. RegEx is a powerful pattern-matching engine designed to search and match complex patterns: From email addresses to IP addresses to phone numbers to infinitely complex text patterns.

In this Amulet, we’ll use regular expressions to match some email addresses.

Problem Statement

We are presented with a set of email addresses containing different structures. A sample of the complete set can be found below:

Our job is to match all the valid email addresses, using whichever flavor suits us best. A typical email address is composed of the following parts:

  • A unique username: dougie.jones
  • A domain name: luckyseven
  • A top-level domain name: .com

Requirements

  • Only the valid addresses must be matched.
  • Each address must be a complete and single match, meaning we must not do partial matches on fragments of the address.
  • Our expression has to be flexible, meaning it has to account for all possible and top-level domains.
  • We must name each part of the email address with its respective section. That means:
    • Username
    • Domain name
    • Top-level domain name


Tackling Groups

Tackling group by group and composing a final expression in the end can significantly ease the task.




The RegEx expression can be written in any flavor using any tool. However, the solution only includes the expression in PCRE2 flavor (PHP >=7.3).

References

Related

In today’s world, we’re constantly being bombarded with information from countless sources – news outlets, social media, blogs, etc….
Over the past decade, programming has emerged as an indispensable tool, enabling us to tackle challenges previously thought impossible….
A Big Data file format is designed to store high volumes of variable data optimally. This can be achieved…
In the first part of this 3-article series, we introduced the concepts of columnar file formats & row-based file formats. We also…

All content on this post is licensed under a Creative Commons Attribution 4.0 International license.

Request Full Resume