How to check for valid email address?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Checking whether an email address is "valid" can mean several different things. It might mean the string has a reasonable email shape, the domain exists, or the user actually controls that mailbox and can receive mail.
Those are different levels of validation, and they should not be confused. A regex can check syntax-like structure, but it cannot prove the mailbox exists or that the user owns it.
Decide What "Valid" Means
In most applications, the practical validation stack looks like this:
- basic format check
- optional domain-level validation
- actual ownership check with a verification email
That third step is the only reliable proof that the address is usable by the person who entered it.
A Reasonable Basic Format Check
For lightweight validation, a simple regular expression is usually enough. The goal is not to implement the full email RFC grammar. The goal is to reject obvious mistakes such as missing @ signs or spaces.
This is intentionally modest. It catches common user-input mistakes without pretending to be a complete RFC parser.
Better Validation with a Library
If you want stronger validation in Python, use a dedicated library instead of writing a giant regex. The email-validator package is a common choice because it normalizes addresses and performs useful checks.
Example:
This gives you stronger parsing behavior and normalized output without re-implementing mail syntax rules yourself.
Domain Checks and Deliverability
Some validation libraries can also check whether the domain has usable mail records. That is stronger than a regex, but it still does not prove the individual mailbox exists.
For example:
This can catch clearly non-deliverable domains, but it depends on DNS and network availability, so many applications reserve it for later steps or background checks.
Verification Email Is the Real Test
If the application actually needs a working mailbox, send a verification email with a time-limited token.
Example workflow:
The app stores the token, emails a link to the user, and marks the address as verified only after the link is clicked. That confirms ownership in a way that syntax validation never can.
What Not to Do
Avoid trying to fully validate every RFC edge case with a hand-written regex. Email syntax is broader than most people expect, and a "perfect" regex usually becomes unreadable while still missing real-world concerns.
Also avoid SMTP probing as a sign-up-time check. Many mail servers block or mislead those probes, and the approach creates latency, privacy issues, and deliverability risks.
Common Pitfalls
The biggest pitfall is treating regex validation as proof that the email address exists. It only proves that the string looks plausible.
Another mistake is using an overly strict regex that rejects real addresses users legitimately own. Real systems should optimize for practical correctness, not theoretical regex cleverness.
Developers also sometimes skip normalization. Case sensitivity rules are subtle, but normalizing whitespace, Unicode handling, and domain casing usually improves consistency.
Finally, do not conflate domain existence with user ownership. A domain with valid mail records still does not prove the mailbox is real or controlled by the current user.
Summary
- "Valid email" can mean syntax, domain deliverability, or actual mailbox ownership.
- A simple regex is fine for basic input screening.
- A dedicated validation library is better than a hand-written giant regex.
- Domain checks are stronger than syntax checks but still not proof of ownership.
- Verification email is the most reliable confirmation that the address can actually be used.
- Choose the level of validation that matches the business requirement instead of over-validating everything at input time.

