Using MEF in a Windows Store App: Listing 1

ValidateEmail class.

using System.Composition;
using System.Text.RegularExpressions;

namespace BusinessRules
{
    [Export(typeof(IValidate))]
    [ExportMetadata("Name", "Email")]
    public class ValidateEmail : IValidate
    {
        const string EMAIL_PATTERN = @"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$";

        public string Validate(string input)
        {
            if (Regex.IsMatch(input, EMAIL_PATTERN))
            {
                return "Email is valid.";
            }
            else
            {
                return "Email is not valid.";
            }
        }
    }
}

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at vogelvision@gmail.com.

comments powered by Disqus

Featured

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events