Advanced email validation component for Microsoft Silverlight
Furthermore, it comes with embedded support for standard Data Annotations, which allows for an easy development experience on existing Silverlight data-centric and LOB applications.
Validating an email address in your Silverlight application is easy as writing a single line of code, with EmailVerify for Silverlight. A complete set of classes assists you with the configuration of the component, if you the default one is not okay for you, and a detailed enumeration contains every possible result the library can handle.
Here is, for example, what it takes to check an email address up to the ISP-specific level of validation (yes, it is more than one line of code: we broke the original one-liner for the sake of readibility):
var engine = new VerificationEngine(); var result = engine.Run("john@example.com", VerificationLevel.IspSpecificSyntax).Result; if (result.LastStatus == VerificationStatus.Success) { // TODO: Show a message box with the great news }
And if you need to plug our email validation engine into your Silverlight data-centric or LOB application, you can also take advantage of the built-in Data Annotations support EmailVerify for Silverlight comes with, by way of its EmailAddress data annotation attribute:
using Cobisi.EmailVerify.DataAnnotations; class CustomerViewModel { private string _primaryEmailAddress; [EmailAddress] public string PrimaryEmailAddress { get { return _primaryEmailAddress; } set { // Standard Data Annotations code, used to validate the property Validator.ValidateProperty(value, new ValidationContext(this)); // If validation passes, sets the backing field as required _primaryEmailAddress = value; } } }
Born as a fork of the original EmailVerify for .NET code base, EmailVerify for Silverlight offers three different e-mail address verification levels (Syntax, IspSpecificSyntax, DeaDomain) and allows you to configure every possible aspect of the validation process, including adherence to IETF standards preferences, and even your own custom validation rules, embedded into the main email verification pipeline.
In the following snippet, for example, EmailVerify for Silverlight is configured not to allow domain literals in e-mail addresses, while allowing comments and quoted strings:
var settings = new VerificationSettings { AllowDomainLiterals = false, AllowComments = true, AllowQuotedStrings = true }; // Pass the configured settings to the verification engine var result = engine.Run("john@example.com", VerificationLevel.Syntax, settings).Result; // ...
engine.VerificationLevelStarted += (sender, args) => { Debug.WriteLine("The address {0} reached level {1}", args.Verification.InputData, args.Level); };