Regular Expressions 101

Community Patterns

Email validation regex

0

Regular Expression
Python

r"
((^[a-zA-Z0-9]+)(([_]?)|([.]|[-])?[a-zA-Z0-9]+)*@([a-zA-Z0-9]+)(([_]?)|([.]|[-])?[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{2,}$)
"
gm

Description

This email validation regex works perfectly (99.99%) for validating email address entries.

The regex does not match email addresses with with the following characteristics:

  • Addresses that begin/end with a special character
  • Addresses with consecutive repeated special characters

Special characters matched are:

  • Period (".")
  • Hyphen ("-")
  • Underscore ("_")

https://regex101.com/r/0NVXwu/1

Submitted by Bright Owusu - 2 years ago (Last modified 2 years ago)