Using MEF in a Windows Store App: Listing 2

ValidateUSPhone class.

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

namespace BusinessRules
{
    [Export(typeof(IValidate))]
    [ExportMetadata("Name", "U.S. Phone")]
    public class ValidateUSPhone : IValidate
    {
        const string PHONE_PATTERN = @"^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$";

        public string Validate(string input)
        {
            if (Regex.IsMatch(input, PHONE_PATTERN))
            {
                return "Phone number is valid.";
            }
            else
            {
                return "Phone number 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 [email protected].

comments powered by Disqus

Featured

Subscribe on YouTube