Python Email Validation: How to Validate Email Addresses in Python

If you’ve tried the usual one-line regex for Python email validation, you’ve probably seen it accept ava..lopez@example.com and even liam carter@example.com, space and all.

The fix is the email-validator package: validate_email() returns a cleaned-up address or raises EmailNotValidError with a plain-English reason. It can also check that the domain accepts mail.

In this tutorial, I’ll walk through python email validation four ways: a strict regex, email-validator, Pydantic’s EmailStr, and a DNS check that tells you whether the domain exists. Then we’ll clean a real sign-up CSV.

My test machine ran Python 3.12.5, email-validator 2.3.0 and Pydantic 2.14.3, and every output below was copied from the Command Prompt window you see in the screenshots.

The Sample Sign-Up Emails We’ll Validate

Say a Denver bike shop collects newsletter sign-ups from a web form. Here are eight addresses from that list:

signups = [
    "olivia.bennett@example.com", "Ethan.Cole@Example.COM",
    "sophia+news@example.com", "mason.reed@example",
    "ava..lopez@example.com", "liam carter@example.com",
    "noah@@example.com", ".grace@example.com",
]

Three are fine (yes, the +news one too). The other five each break a different rule: no top-level domain, a double dot, a space, two @ signs, and a leading period.

Those are the mistakes real people type, so they’re what any Python check has to catch. If the address comes from a console prompt instead of a form, see how the input() function works in Python.

Method 1: Validate an Email Address in Python with Regex

A regular expression is the no-install option. Use it for a quick sanity check in a script, or when you can’t add a dependency. Same sample list of eight sign-ups, now tested in Python against the popular loose pattern and a stricter one.

Here’s the code:

import re

signups = [
    "olivia.bennett@example.com", "Ethan.Cole@Example.COM",
    "sophia+news@example.com", "mason.reed@example",
    "ava..lopez@example.com", "liam carter@example.com",
    "noah@@example.com", ".grace@example.com",
]

LOOSE = r"[^@]+@[^@]+\.[^@]+"      # the one-liner most answers share
STRICT = re.compile(r"""
    [A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+          # first chunk of the name
    (?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*   # more chunks, never ".."
    @
    (?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+   # domain labels
    [A-Za-z]{2,}                             # top-level domain
""", re.VERBOSE)

for email in signups:
    loose = bool(re.match(LOOSE, email))
    strict = bool(STRICT.fullmatch(email))
    print(f"{email:28} loose={loose!s:5} strict={strict}")

Output:

olivia.bennett@example.com   loose=True  strict=True
Ethan.Cole@Example.COM       loose=True  strict=True
sophia+news@example.com      loose=True  strict=True
mason.reed@example           loose=False strict=False
ava..lopez@example.com       loose=True  strict=False
liam carter@example.com      loose=True  strict=False
noah@@example.com            loose=False strict=False
.grace@example.com           loose=True  strict=False
Command Prompt output of a Python email regex check where the loose pattern accepts bad addresses and the strict pattern rejects them
The loose pattern passes six of the eight addresses; the strict one passes only the three good ones.

The loose pattern says True for ava..lopez, liam carter and .grace. The strict one rejects all three and still accepts sophia+news@example.com.

How does this code work?

[^@]+@[^@]+\.[^@]+ only asks for “something, an @, something with a dot”. A space or a double dot is still “something”, so it slips through.

The strict pattern builds the name from chunks of allowed characters joined by single dots, so .. and a leading dot can’t match. Each domain label must start and end with a letter or digit, and the top-level domain needs two or more letters.

Python’s re.VERBOSE flag lets me spread the pattern over lines with comments. Inside a character class, the # stays a literal character, so the comments don’t break it.

Important: use fullmatch(), not match(). re.match() only anchors the start, so jake@example.com, hi would pass. My regular expressions in Python tutorial covers the difference.

So here’s the catch: even a strict regex knows nothing about real domains, and it rejects international addresses like chloe@bücher.example. That’s why I only use regex for quick filters.

Method 2: Check If an Email Is Valid with email-validator (Recommended)

For anything users type into a real Python app, I reach for email-validator. It follows the email standards, gives a readable error for each failure, and returns a normalized address you can store.

Install it inside your project’s virtual environment (Python 3.8 or newer; I used 2.3.0):

pip install email-validator

If you need to match my exact version, pip can install a specific version too. Same sample list again, this time through validate_email():

from email_validator import validate_email, EmailNotValidError

signups = [
    "olivia.bennett@example.com", "Ethan.Cole@Example.COM",
    "sophia+news@example.com", "mason.reed@example",
    "ava..lopez@example.com", "liam carter@example.com",
    "noah@@example.com", ".grace@example.com",
]

for email in signups:
    try:
        info = validate_email(email, check_deliverability=False)
        print(f"OK   {info.normalized}")
    except EmailNotValidError as err:
        print(f"BAD  {email}: {err}")

Output:

OK   olivia.bennett@example.com
OK   Ethan.Cole@example.com
OK   sophia+news@example.com
BAD  mason.reed@example: The part after the @-sign is not valid. It should have a period.
BAD  ava..lopez@example.com: An email address cannot have two periods in a row.
BAD  liam carter@example.com: The email address contains invalid characters before the @-sign: SPACE.
BAD  noah@@example.com: The part after the @-sign contains invalid characters: '@'.
BAD  .grace@example.com: An email address cannot start with a period.
Command Prompt output of the Python email-validator library accepting three sign-ups and rejecting five with a reason for each
Three addresses come back as OK; each of the other five gets its own error message.

Three addresses pass and five fail. Notice Ethan.Cole@Example.COM comes back as Ethan.Cole@example.com.

How does this code work?

validate_email() parses the address into its name and domain parts and checks each one. On success it returns a ValidatedEmail object; on failure it raises EmailNotValidError.

The error text is written for end users. “An email address cannot have two periods in a row.” can go straight under a form field.

info.normalized lowercases the domain but keeps the name’s case, because the part before the @ can be case-sensitive on some mail servers. Store that normalized value, not the raw input.

I passed check_deliverability=False to keep this a pure syntax check with no network calls. Wrapping the call in try/except is standard Python; catching multiple exceptions in Python shows how to handle more than one error type.

Pro Tip: validate when the address arrives (sign-up form, API request), and store the normalized form. Then a later login with Ethan.Cole@EXAMPLE.com still finds the same account.

Method 3: Validate Email Fields with Pydantic EmailStr

If your Python data already flows through Pydantic models, as it does in FastAPI, don’t call the validator by hand. Type the field as EmailStr and the model checks it for you.

EmailStr needs email-validator installed (pip install "pydantic[email]" pulls it in). Same list of addresses, now as Python model objects:

from pydantic import BaseModel, EmailStr, ValidationError


class Signup(BaseModel):
    name: str
    email: EmailStr


print(Signup(name="Ethan Cole", email="Ethan.Cole@Example.COM"))

try:
    Signup(name="Ava Lopez", email="ava..lopez@example.com")
except ValidationError as err:
    print(err)

Output:

name='Ethan Cole' email='Ethan.Cole@example.com'
1 validation error for Signup
email
  value is not a valid email address: An email address cannot have two periods in a row. [type=value_error, input_value='ava..lopez@example.com', input_type=str]

Ethan’s address is accepted and normalized the same way as in Method 2. Ava’s address raises a ValidationError naming the field and the reason.

How does this code work?

Pydantic hands the email value to email-validator when the object is created. If the check fails, you get a ValidationError with the field name, the message and the bad input.

In a FastAPI app that error becomes a 422 response automatically, so bad emails never reach your code. My FastAPI tutorial for beginners shows where models like Signup fit.

Note: EmailStr checks syntax only. It doesn’t look up the domain, which is what the next method adds.

Method 4: Check If an Email Address Exists in Python (Domain and MX Check)

Syntax isn’t everything in Python email validation. A valid-looking address can still point at a domain that doesn’t exist or doesn’t take mail. To validate that an email exists as far as DNS can tell, leave deliverability checking on (the default).

These four addresses are different from the sign-up list, because the shop’s list uses example.com and I wanted a real mail domain in the mix:

from email_validator import validate_email, EmailNotValidError

addresses = [
    "noreply@github.com",
    "olivia.bennett@example.com",
    "sales@harborline-goods-2026.com",
    "help@gmial.com",                  # typo of gmail.com
]

for email in addresses:
    try:
        info = validate_email(email)   # DNS check is on by default
        fb = info.mx_fallback_type     # set when there's no MX record
        how = f" ({fb} record)" if fb else ""
        print(f"OK   {email:36} mail server: {info.mx[0][1]}{how}")
    except EmailNotValidError as err:
        print(f"BAD  {email:36} {err}")

Output:

OK   noreply@github.com                   mail server: github-com.mail.protection.outlook.com
BAD  olivia.bennett@example.com           The domain name example.com does not accept email.
BAD  sales@harborline-goods-2026.com      The domain name harborline-goods-2026.com does not exist.
OK   help@gmial.com                       mail server: gmial.com (A record)
Command Prompt output of a Python email-validator DNS check: one domain has a mail server, one refuses email, one doesn't exist, and a typo domain passes
GitHub’s domain has a mail server, example.com refuses mail, the made-up domain doesn’t exist, and the gmial.com typo still passes.

noreply@github.com passes with mail server github-com.mail.protection.outlook.com. example.com is rejected because it doesn’t accept email, and the made-up shop domain doesn’t exist at all.

How does this code work?

With deliverability on, validate_email() uses dnspython to look up the domain’s MX records, the DNS entries that say which server receives its mail. No MX record means it tries an A or AAAA record instead.

example.com publishes a “null MX” record that says “no mail here”, so it fails. The made-up domain returns no records at all.

Now the surprise: help@gmial.com passes. The typo domain has an A record, so DNS says mail could be delivered. A DNS check can’t catch typos of real domains.

Important: no Python library can prove a mailbox exists. Probing the mail server over SMTP is unreliable (many servers accept every address, and port 25 is often blocked). The only real proof is a confirmation link, like the Django registration with email confirmation flow.

Sending that message is plain Python too; sending email using Python covers smtplib.

Validate a List of Email Addresses from a CSV File

Most of the time a Python script isn’t checking one address but a whole export. Here’s the shop’s sign-up sheet as a CSV, with one person who signed up twice with different capitals:

name,email
Olivia Bennett,olivia.bennet