Syntax validation features
EmailVerify for Silverlight features a complete syntactical email validation engine that obeys to the current IETF standards, including:
- RFC 1123 - Requirements for Internet Hosts
- RFC 2821 - Simple Mail Transfer Protocol
- RFC 2822 - Internet Message Format
- RFC 3696 - Application Techniques for Checking and Transformation of Names
- RFC 4291 - IP Version 6 Addressing Architecture
- RFC 5321 - Simple Mail Transfer Protocol
- RFC 5322 - Internet Message Format (updates)
Whenever EmailVerify for Silverlight detects an invalid email address syntax, it aborts the validation process and returns the exact cause of the error,
along with the position in the email address where the failure happened:
var engine = new VerificationEngine();
// ...
var result = engine.Run("seti@home@example.com",
VerificationLevel.Syntax).Result;
if (result.SyntaxFailureIndex.HasValue)
{
// Will output: InvalidCharacterInSequence
Debug.WriteLine(result.Status);
// Will output: 9
Debug.WriteLine(result.SyntaxFailureIndex);
}
Despite the strong adherence to IETF standards, the component is fully configurable and allows to adjust its validation settings
with ease; the following sections discuss some of these settings and explore the different email validation results you can obtain.
Quoted strings and quoted pairs
According to
RFC 2822, email addresses can contain characters from a subset of
the US-ASCII charset, including the latin letters, numbers and a few punctuation marks; the same RFC, however, allows email addresses
to include nearly any other US-ASCII character by means of quoted strings and, possibly, quoted pairs.
In the event the local part of an email address needs to contain a space (ASCII code 32, or 0x20 hexadecimal), for example, and being this character
not allowed in its free form, the aforementioned RFC allows to use it only if it comes within a string delimited by quotes. Here is an example
of a valid email address containing multiple spaces:
"the quick brown fox"@example.com
On top of that, email addresses can even contain some special characters like the @ symbol by prepending them with an escape character, like in the
following valid email address:
"seti\@home"@example.com
EmailVerify for Silverlight detects quoted strings and quoted pairs and handle them correctly; if needed, however, you can easily turn this support off by setting
the related AllowQuotedStrings property:
var engine = new VerificationEngine();
// Turn quoted strings (and pairs) support off
engine.DefaultSettings.AllowQuotedStrings = false;
Comments
Even if it is rare nowadays to see such usage, EmailVerify for Silverlight supports even comments within email addresses, as per the already
mentioned
RFC 2822. In this case, the standards require comments to be enclosed
within parentheses (round brackets) and to be placed at specific points only.
The following valid email address, for example, contains a total of three comments (the middle one being also a nested comment):
john(smith)@(my (domain))example.com(tld)
By default, EmailVerify for Silverlight handles comments automatically and provide you with an easy way to extract them, if needed:
var engine = new VerificationEngine();
// ...
var result = engine.Run("john(smith)@(my (domain))example.com(tld)",
VerificationLevel.Syntax).Result;
// Show the email address without comments
// Will output: john@example.com
Debug.WriteLine(result.EmailAddress);
// Show each extracted comment
// Will output: smith, my domain and tld
foreach (var comment in result.Comments)
{
Debug.WriteLine(comment);
}
If needed, support for comments can be disabled with a single line of code:
var engine = new VerificationEngine();
// Turn comments support off
engine.DefaultSettings.AllowComments = false;
Domain literals
In some environments, domain literals can be used to send email messages to a specific IP address instead of relying on the domain name
system (DNS); the RFCs allows to use this information within email addresses, replacing their domain parts with the required IP address
(being it an IPv4 or an IPv6 address) enclosed between square brackets, like in the following example:
test@[173.194.69.27]
By default, EmailVerify for Silverlight validates email addresses with domain literals automatically; if needed, you may turn this feature off by using
this line of code:
var engine = new VerificationEngine();
// Turn domain literals support off
engine.DefaultSettings.AllowDomainLiterals = false;