<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Credit Card Validation in C#</title>
	<atom:link href="http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp/feed" rel="self" type="application/rss+xml" />
	<link>http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp</link>
	<description></description>
	<lastBuildDate>Wed, 13 Oct 2010 08:27:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Marinus</title>
		<link>http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp/comment-page-1#comment-2583</link>
		<dc:creator>Marinus</dc:creator>
		<pubDate>Wed, 13 Oct 2010 08:27:13 +0000</pubDate>
		<guid isPermaLink="false">http://jlcoady.net/?p=145#comment-2583</guid>
		<description>Can you please tell me if i have a Text box how will it be possible to send the  text box text information through this class

public static bool Validate(CardType cardType, string cardNumber)</description>
		<content:encoded><![CDATA[<p>Can you please tell me if i have a Text box how will it be possible to send the  text box text information through this class</p>
<p>public static bool Validate(CardType cardType, string cardNumber)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Navnit</title>
		<link>http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp/comment-page-1#comment-506</link>
		<dc:creator>Navnit</dc:creator>
		<pubDate>Fri, 22 Jan 2010 09:11:04 +0000</pubDate>
		<guid isPermaLink="false">http://jlcoady.net/?p=145#comment-506</guid>
		<description>public sealed class Card_Validation
{
    string MasterCard, BankCard, Visa, AmericanExpress, Discover, DinersClub, JCB;
    private Card_Validation()
    {
    } // static only

    //public static bool Validate(CardType cardType, string cardNumber)
    public static  bool Validate(string  cardType, string cardNumber)
   {
      byte[] number = new byte[16]; // number to validate

      // Remove non-digits
      int len = 0;
      for(int i = 0; i  5)
               return false;
            break;

         case &quot;BankCard&quot;:
            if(len != 16)
               return false;
            if(number[0] != 5 &#124;&#124; number[1] != 6 &#124;&#124; number[2] &gt; 1)
               return false;
            break;

         case &quot;Visa&quot;:
            if(len != 16 &amp;&amp; len != 13)
               return false;
            if(number[0] != 4)
               return false;
            break;

         case &quot;AmericanExpress&quot;:
            if(len != 15)
               return false;
            if(number[0] != 3 &#124;&#124; (number[1] != 4 &amp;&amp; number[1] != 7))
               return false;
            break;

         case &quot;Discover&quot;:
            if(len != 16)
               return false;
            if(number[0] != 6 &#124;&#124; number[1] != 0 &#124;&#124; number[2] != 1 &#124;&#124; number[3] != 1)
               return false;
            break;

         case &quot;DinersClub&quot;:
            if(len != 14)
               return false;
            if(number[0] != 3 &#124;&#124; (number[1] != 0 &amp;&amp; number[1] != 6 &amp;&amp; number[1] != 8)
               &#124;&#124; number[1] == 0 &amp;&amp; number[2] &gt; 5)
               return false;
            break;

         case &quot;JCB&quot;:
            if(len != 16 &amp;&amp; len != 15)
               return false;
            if(number[0] != 3 &#124;&#124; number[1] != 5)
               return false;
            break;
      }

      // Use Luhn Algorithm to validate
      int sum = 0;
      for(int i = len - 1; i &gt;= 0; i--)
      {
         if(i % 2 == len % 2)
         {
            int n = number[i] * 2;
            sum += (n / 10) + (n % 10);
         }
         else
            sum += number[i];
      }
      return (sum % 10 == 0);
   }
}</description>
		<content:encoded><![CDATA[<p>public sealed class Card_Validation<br />
{<br />
    string MasterCard, BankCard, Visa, AmericanExpress, Discover, DinersClub, JCB;<br />
    private Card_Validation()<br />
    {<br />
    } // static only</p>
<p>    //public static bool Validate(CardType cardType, string cardNumber)<br />
    public static  bool Validate(string  cardType, string cardNumber)<br />
   {<br />
      byte[] number = new byte[16]; // number to validate</p>
<p>      // Remove non-digits<br />
      int len = 0;<br />
      for(int i = 0; i  5)<br />
               return false;<br />
            break;</p>
<p>         case &#8220;BankCard&#8221;:<br />
            if(len != 16)<br />
               return false;<br />
            if(number[0] != 5 || number[1] != 6 || number[2] &gt; 1)<br />
               return false;<br />
            break;</p>
<p>         case &#8220;Visa&#8221;:<br />
            if(len != 16 &amp;&amp; len != 13)<br />
               return false;<br />
            if(number[0] != 4)<br />
               return false;<br />
            break;</p>
<p>         case &#8220;AmericanExpress&#8221;:<br />
            if(len != 15)<br />
               return false;<br />
            if(number[0] != 3 || (number[1] != 4 &amp;&amp; number[1] != 7))<br />
               return false;<br />
            break;</p>
<p>         case &#8220;Discover&#8221;:<br />
            if(len != 16)<br />
               return false;<br />
            if(number[0] != 6 || number[1] != 0 || number[2] != 1 || number[3] != 1)<br />
               return false;<br />
            break;</p>
<p>         case &#8220;DinersClub&#8221;:<br />
            if(len != 14)<br />
               return false;<br />
            if(number[0] != 3 || (number[1] != 0 &amp;&amp; number[1] != 6 &amp;&amp; number[1] != 8)<br />
               || number[1] == 0 &amp;&amp; number[2] &gt; 5)<br />
               return false;<br />
            break;</p>
<p>         case &#8220;JCB&#8221;:<br />
            if(len != 16 &amp;&amp; len != 15)<br />
               return false;<br />
            if(number[0] != 3 || number[1] != 5)<br />
               return false;<br />
            break;<br />
      }</p>
<p>      // Use Luhn Algorithm to validate<br />
      int sum = 0;<br />
      for(int i = len &#8211; 1; i &gt;= 0; i&#8211;)<br />
      {<br />
         if(i % 2 == len % 2)<br />
         {<br />
            int n = number[i] * 2;<br />
            sum += (n / 10) + (n % 10);<br />
         }<br />
         else<br />
            sum += number[i];<br />
      }<br />
      return (sum % 10 == 0);<br />
   }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Navnit</title>
		<link>http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp/comment-page-1#comment-505</link>
		<dc:creator>Navnit</dc:creator>
		<pubDate>Fri, 22 Jan 2010 09:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://jlcoady.net/?p=145#comment-505</guid>
		<description>if(len == 16) return false; // number has too many digits
  number[len++] =Convert.ToByte(cardNumber[i]);</description>
		<content:encoded><![CDATA[<p>if(len == 16) return false; // number has too many digits<br />
  number[len++] =Convert.ToByte(cardNumber[i]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Howzilla</title>
		<link>http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp/comment-page-1#comment-363</link>
		<dc:creator>Howzilla</dc:creator>
		<pubDate>Tue, 29 Sep 2009 02:21:19 +0000</pubDate>
		<guid isPermaLink="false">http://jlcoady.net/?p=145#comment-363</guid>
		<description>Thanks for the code. You really saved me some time with this.</description>
		<content:encoded><![CDATA[<p>Thanks for the code. You really saved me some time with this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mexicotom</title>
		<link>http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp/comment-page-1#comment-305</link>
		<dc:creator>mexicotom</dc:creator>
		<pubDate>Wed, 05 Aug 2009 02:01:30 +0000</pubDate>
		<guid isPermaLink="false">http://jlcoady.net/?p=145#comment-305</guid>
		<description>Your Luhn algorithm is interesting, but according to my tests is 10x slower than this one:

http://orb-of-knowledge.blogspot.com/2009/08/extremely-fast-luhn-function-for-c.html

Also, line #23 is not compiling for me, as it complains that Byte.Parse cannot take a char, but must take a string. I then had to call .ToString() on the char value to make it work (which may account for some of the slowness mentioned above).</description>
		<content:encoded><![CDATA[<p>Your Luhn algorithm is interesting, but according to my tests is 10x slower than this one:</p>
<p><a href="http://orb-of-knowledge.blogspot.com/2009/08/extremely-fast-luhn-function-for-c.html" rel="nofollow">http://orb-of-knowledge.blogspot.com/2009/08/extremely-fast-luhn-function-for-c.html</a></p>
<p>Also, line #23 is not compiling for me, as it complains that Byte.Parse cannot take a char, but must take a string. I then had to call .ToString() on the char value to make it work (which may account for some of the slowness mentioned above).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nitin Sawant</title>
		<link>http://jlcoady.net/c-sharp/credit-card-validation-in-c-sharp/comment-page-1#comment-265</link>
		<dc:creator>Nitin Sawant</dc:creator>
		<pubDate>Sat, 02 May 2009 15:04:18 +0000</pubDate>
		<guid isPermaLink="false">http://jlcoady.net/?p=145#comment-265</guid>
		<description>can you provide C# code to generate valide credit cards??

regards,
Nitin Sawant</description>
		<content:encoded><![CDATA[<p>can you provide C# code to generate valide credit cards??</p>
<p>regards,<br />
Nitin Sawant</p>
]]></content:encoded>
	</item>
</channel>
</rss>

