$ show jstedfast/EmailValidation
A simple yet rigorously correct .NET library for validating email addresses according to RFC 5322 and Internationalized Email standards (RFC 653x). The core is a hand-written character-by-character parser that rejects invalid syntax while supporting quoted strings, IP literals, international characters, and length constraints per the spec. It provides a static `Validate`/`TryValidate` method and a DataAnnotations `EmailAttribute` for easy integration into ASP.NET or other validation frameworks. The library is well-tested with hundreds of valid and invalid examples, including edge cases like surrogate pairs and maximum-length addresses. It targets multiple .NET frameworks (net462, net8.0, net10.0, netstandard2.0/2.1) and is distributed as a NuGet package with signed assemblies. The code is clean, well-commented, and free of external dependencies for the core validation, making it a trustworthy component for any .NET application needing email input validation.
The LLM identified 2 files worth highlighting for reuse:
The central email validation engine implementing a manual parser that iterates over the address character-by-character, enforcing RFC 5322 and RFC 653x grammar rules (atoms, quoted strings, domain labels, IPv4/IPv6 literals). It correctly handles length limits, international characters via surrogate pair awareness, and provides detailed error information via `TryValidate`. The code is self-contained (no external dependencies), meticulously structured with helper functions for each token type, and demonstrates deep understanding of the email specification. This component is highly reusable as a reference implementation for any RFC-based parsing task in .NET.
A custom DataAnnotations `ValidationAttribute` that delegates to `EmailValidator.Validate`. It supports two optional modes: `AllowTopLevelDomains` and `AllowInternational`. The implementation correctly handles null values (passes validation) and integrates with the standard .NET validation pipeline. This component exemplifies how to create a reusable, configurable validation attribute with proper error messaging and member name tracking.