Guides
Last updated
July 20, 2025

5 Ways to Validate Emails with Regex

Nicolas Rios
Nicolas Rios
Table of Contents:
ON THIS PAGE
Get your free
email validation
 API key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

Using regular expressions to validate email addresses is a common first line of defense against bad data. We'll explore five regex implementations with working code, examine their inherent pitfalls, and then see how Abstract API addresses these shortcomings.

How to Implement Email Validation With Regex

These regular expressions offer different levels of strictness for email validation. Each pattern provides a specific approach to filter addresses based on syntax rules, from basic to highly complex.

Minimal Structural Filter

This pattern provides a fast, dialect-agnostic check. It is useful for a quick front-end filter or for pre-processing logs to remove obviously malformed entries. The expression confirms the presence of characters before and after the "@" symbol and after the final dot, while it disallows spaces.

^[^\s@]+@[^\s@]+\.[^\s@]+$

HTML Standard ABNF Pattern

This regex aligns with the grammar that modern browsers use to validate input fields with "type=email". It correctly accepts dot-atoms and 63-character DNS labels. The pattern rejects comments and quoted strings, which are valid under some specifications but rarely used in practice.

/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

Near-RFC 5322 Pattern

For a more thorough validation, this pattern closely follows the official email address specification. It is significantly more complex, as it accounts for less common formats like quoted local-parts and domain literals that contain IP addresses. The complete expression is quite large but offers one of the most comprehensive syntax checks available through regular expressions.

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:\d{1,3}\.){3}\d{1,3}|IPv6:[0-9a-fA-F:.]+)\])

TLD-Whitelisted Pattern

This method involves a regex that checks the email's top-level domain (TLD) against a predefined list. This list is generated from an official source like the IANA root zone. By explicitly list valid TLDs like "com" or "org", the pattern helps catch common typos in the domain extension. The list requires periodic updates as new TLDs become available.

^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.(?:com|net|org|io|…)$

Challenges of Implementing Email Validation in Regex

While regular expressions offer a quick syntax check, they present significant drawbacks. These limitations range from unmanageable complexity and performance bottlenecks to an inability to confirm an email's actual deliverability.

  • The near-RFC 5322 pattern becomes incredibly complex and unreadable. It must account for obscure formats like nested comments and IP-literals, which makes the expression difficult to review or modify safely.
  • A regex only validates text syntax and cannot query DNS. An address can pass a minimal structural filter or HTML standard check but still bounce because the domain lacks MX records or is parked.
  • The TLD-whitelisted pattern requires constant updates. The list of valid TLDs and international domain names changes frequently, so the regex quickly becomes outdated and misses valid emails or accepts typos.
  • Complex patterns that attempt to catch all edge cases rely on heavy backtracking. At scale, this creates CPU hotspots and introduces security risks like Regular Expression Denial of Service (ReDoS) attacks.

Validate Emails with Abstract API
Ensure the quality of your user data by implementing proper email validation from the start.
Get started for free

How Abstract API Handles Email Validation

Abstract API addresses the core weaknesses of traditional methods. It combines a fast syntax check with multiple real-world deliverability tests.

  • It provides typo autocorrection suggestions and a quality score to rank email addresses.
  • It performs real-time MX lookups and SMTP handshakes to confirm an address can receive mail.
  • It checks against frequently updated lists of disposable, free, role-based, and catch-all domains.
  • Its risk model uses data from over three billion historical validations, with frequent data refreshes that require no code changes.

How to Add Abstract API to Your Dev Environment

Once you know Abstract’s capabilities, you can add its email validation API to your project with ease.

  • Sign up at Abstract API and copy the Email Validation API key from your dashboard.
  • Store the key as an environment variable, for example, "ABSTRACT_API_KEY". Never hard-code it.
  • Add an HTTP client to your project, such as "requests" for Python or "axios" for Node.
  • Write a thin wrapper that performs a GET request to the API endpoint with your key and the email as query parameters.
  • Parse the JSON response. Check that "deliverability" equals "DELIVERABLE" and "is_valid_format" is "true" before you persist the address.
  • Optionally, gate the endpoint with a circuit breaker based on the HTTP 4xx or 5xx codes the API returns.
import os, requests
API_KEY = os.getenv("ABSTRACT_API_KEY")
email = "johnsmith@gmail.com"
resp = requests.get("https://emailvalidation.abstractapi.com/v1/",
  params={"api_key": API_KEY, "email": email}, timeout=3)
data = resp.json()
if data["deliverability"] == "DELIVERABLE" and data["is_valid_format"]["value"]:
  # accept user
  pass

Sample Email Validation Implementation with Abstract API

While a regex check only confirms a string matches a pattern, it has no knowledge of deliverability. The Python snippet above sends an email address to Abstract API and receives a detailed JSON response that answers two questions: “Does it look right?” and “Will it actually land?” This happens through real-time MX lookups, SMTP handshakes, and checks against constantly refreshed lists of disposable or toxic domains.

The API returns a comprehensive data object. It includes a "deliverability" status, a machine-learning-based "quality_score", and boolean flags for format validity, disposable domains, and more. This layered result eliminates the developer hours spent on the maintenance of complex regex rules.

{
  "email": "johnsmith@gmail.com",
  "autocorrect": "",
  "deliverability": "DELIVERABLE",
  "quality_score": 0.9,
  "is_valid_format": { "value": true, "text": "TRUE" },
  "is_free_email": { "value": true, "text": "TRUE" },
  "is_disposable_email": { "value": false, "text": "FALSE" },
  "is_role_email": { "value": false, "text": "FALSE" },
  "is_catchall_email": { "value": false, "text": "FALSE" },
  "is_mx_found": { "value": true, "text": "TRUE" },
  "is_smtp_valid": { "value": true, "text": "TRUE" }
}

Final Thoughts

Traditional regex checks are brittle. They often fail to catch undeliverable addresses and incorrectly flag valid ones. Abstract API overcomes these limits with real-time deliverability tests and comprehensive domain checks. To validate user emails with confidence, create an account on Abstract API and get your free API key.

Validate Emails with Abstract API
Implement proper email validation to maintain clean user data and improve your email deliverability rates.
Get started for free

Related Articles

Phone Validation
key now
Get your free
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required