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

GitHub Gists is a tool developed by GitHub which provides a simple way to share code snippets with other people….
In today’s world, we’re constantly being bombarded with information from countless sources – news outlets, social media, blogs, etc….
As we continue our collective programming journey, building on the foundation of intermediate programming, we’re ready to venture into…
Higher-order functions take other functions as arguments and/or return other functions as a result. These powerful abstractions allow us…

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

Request Full Resume