Zero-dependency, offline email validation for .NET.
EmailGuard validates email addresses through a fast three-step pipeline — no network calls, no external dependencies.
| Step | What it does | Speed |
|---|---|---|
| 1. Quick Guard | Compiled regex rejects obvious junk (missing @, spaces, no domain dot) |
⚡ ~nanoseconds |
| 2. RFC Validation | Enforces RFC 5321/5322 rules: atext chars, dot positions, length limits | ⚡ ~microseconds |
| 3. TLD Check | Verifies the domain's TLD against a static IANA root zone list | ⚡ ~microseconds |
- 🚫 Zero dependencies — pure .NET, nothing to install
- 🔌 Fully offline — no DNS lookups, no HTTP calls
- 🎯 Multi-target — supports
net8.0,net9.0,net10.0 - 📋 Detailed results — tells you which step failed, not just pass/fail
- ⚡ Fast — source-generated regex,
Span<T>-based parsing,HashSet<T>TLD lookup
dotnet add package EmailGuardusing EmailGuard;
// Simple boolean check
if (EmailValidator.IsValid("user@example.com"))
Console.WriteLine("Valid!");
// Detailed result
var result = EmailValidator.Validate("user@example.com");
switch (result)
{
case EmailValidationResult.Valid:
Console.WriteLine("✅ Valid email address.");
break;
case EmailValidationResult.InvalidFormat:
Console.WriteLine("❌ Bad format.");
break;
case EmailValidationResult.RfcViolation:
Console.WriteLine("❌ RFC 5321/5322 violation.");
break;
case EmailValidationResult.InvalidTld:
Console.WriteLine("❌ Unknown TLD.");
break;
}Returns an EmailValidationResult enum:
| Value | Meaning |
|---|---|
Valid |
Passed all three validation steps |
InvalidFormat |
Failed the quick regex guard (step 1) |
RfcViolation |
Failed RFC 5321/5322 structural checks (step 2) |
InvalidTld |
Domain TLD not found in the IANA list (step 3) |
Returns true if the email passes all validation steps; false otherwise.
Returns true if the domain's TLD is in the known IANA list.
- Exactly one
@separating local-part and domain - Total address length ≤ 254 characters
- Local-part length ≤ 64 characters
- Local-part: only RFC 5322
atextcharacters + dots; no leading, trailing, or consecutive dots - Domain labels: 1–63 characters each, alphanumeric + hyphens, no leading/trailing hyphens
- At least two domain labels (e.g.,
example.com)
The TLD list is sourced from the IANA Root Zone Database and is embedded as a static HashSet<string>. It includes all country-code, generic, and internationalized (punycode xn--) TLDs.
Last updated: 2026-02-24
To update, replace the list in TldValidator.cs and bump the version.
EmailGuard/
├── src/
│ └── EmailGuard/ # The NuGet package library
├── tests/
│ └── EmailGuard.Tests/ # xUnit unit + smoke tests
├── samples/
│ └── EmailGuard.Sample/ # Console demo app
├── EmailGuard.sln
├── README.md
└── LICENSE