<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Social Vitamin &#187; regex</title>
	<atom:link href="http://www.socialvitamin.com/tag/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.socialvitamin.com</link>
	<description>Give your social space a vitamin boost.</description>
	<lastBuildDate>Tue, 17 Aug 2010 20:34:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>C# Form Validation Class</title>
		<link>http://www.socialvitamin.com/2009/05/19/c-form-validation-class/</link>
		<comments>http://www.socialvitamin.com/2009/05/19/c-form-validation-class/#comments</comments>
		<pubDate>Tue, 19 May 2009 17:41:18 +0000</pubDate>
		<dc:creator>Michael D. Irizarry</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.socialvitamin.com/?p=192</guid>
		<description><![CDATA[A nice little form validation class. It provides validation for Phone, Email, URL and Zipcode but its real easy to extend. Code public class FormValidator { public static IDictionary RegexDictionary [...]]]></description>
			<content:encoded><![CDATA[<p>A nice little form validation class. It provides validation for Phone, Email, URL and Zipcode but its real easy to extend.<br />
<span id="more-192"></span><br />
Code</p>
<pre lang="Java">
    public class FormValidator
    {

        public static IDictionary<string, Regex> RegexDictionary = new Dictionary<string, Regex>() {
        { "Phone", new Regex("^[2-9]\\d{2}-\\d{3}-\\d{4}$")},
        { "Email", new Regex(@"^(([^<>()[\]\\.,;:\s@\""]+"
          + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
          + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
          + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
          + @"[a-zA-Z]{2,}))$"
        )},
        { "URL", new Regex(@"(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&#038;=]*)?")},
        { "ZipCode", new Regex("^[0-9]{5}$")}
        };

        public static bool IsPhoneValid(string phone)
        {
            return RegexDictionary["Phone"].IsMatch(phone);
        }

        public static bool IsEmailValid(string email)
        {
            return RegexDictionary["Email"].IsMatch(email);
        }

        public static bool IsURLValid(string url)
        {
            return RegexDictionary["URL"].IsMatch(url);
        }

        public static bool IsZipCodeValid(string url)
        {
            return RegexDictionary["ZipCode"].IsMatch(url);
        }

    }
</pre>
<p>Use</p>
<pre lang="Java">
if (String.IsNullOrEmpty(email) || !FormValidator.IsEmailValid(email))
// Do something email is required
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.socialvitamin.com/2009/05/19/c-form-validation-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
