<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to determine invalid credit card number in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-to-determine-invalid-credit-card-number/m-p/18780#M10393</link>
    <description>&lt;P&gt;Sorry for asking stupid questions, but aside from maybe basic length checking, why are you bothering with this at all? Leave it to Authorize.net to do anything advanced that needs doing.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Nov 2011 09:08:16 GMT</pubDate>
    <dc:creator>TJPride</dc:creator>
    <dc:date>2011-11-10T09:08:16Z</dc:date>
    <item>
      <title>How to determine invalid credit card number</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-to-determine-invalid-credit-card-number/m-p/18772#M10389</link>
      <description>&lt;P&gt;I am needing help with a credit card validation script. I have figured out how to determine if a credit card is valid/invalid but what I am needing is this:&lt;/P&gt;&lt;P&gt;If someone enters an invalid credit card number, is there a way to determine which number is invalid? If so, please show me how :D. Here is my current code to determine if a card is valid/invalid:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function validateCreditcard_number($credit_card_number) {

    //Get the first digit
    $firstnumber = substr($credit_card_number, 0, 1);
    //Make sure it is the correct amount of digits. Account for dashes being present.
    switch ($firstnumber) {
        case 3:
            if (!preg_match('/^3\d{3}[ \-]?\d{6}[ \-]?\d{5}$/', $credit_card_number)) {
               return '&amp;lt;li&amp;gt;This is not a valid American Express card number. Please use a different credit/debit card or re-enter your credit/debit card details.&amp;lt;/li&amp;gt;';
            }
            break;
        case 4:
            if (!preg_match('/^4\d{3}[ \-]?\d{4}[ \-]?\d{4}[ \-]?\d{4}$/', $credit_card_number)) {
                return '&amp;lt;li&amp;gt;This is not a valid Visa card number. Please use a different credit/debit card or re-enter your credit/debit card details.&amp;lt;/li&amp;gt;';
            }
            break;
        case 5:
            if (!preg_match('/^5\d{3}[ \-]?\d{4}[ \-]?\d{4}[ \-]?\d{4}$/', $credit_card_number)) {
                 return '&amp;lt;li&amp;gt;This is not a valid MasterCard card number. Please use a different credit/debit card or re-enter your credit/debit card details.&amp;lt;/li&amp;gt;';
            }
            break;
        case 6:
            if (!preg_match('/^6011[ \-]?\d{4}[ \-]?\d{4}[ \-]?\d{4}$/', $credit_card_number)) {
                return '&amp;lt;li&amp;gt;This is not a valid Discover card number. Please use a different credit/debit card or re-enter your credit/debit card details.&amp;lt;/li&amp;gt;';
            }
            break;
        default:
            return '&amp;lt;li&amp;gt;This is not a valid credit card number. Please use a different credit/debit card or re-enter your credit/debit card details.&amp;lt;/li&amp;gt;';
    } //END Switch statement
    
	//Luhn Algorithm
    $credit_card_number = str_replace('.', '', $credit_card_number);
	$credit_card_number = str_replace('-', '', $credit_card_number);
	$credit_card_number = str_replace(' ', '', $credit_card_number);
    $map = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
                0, 2, 4, 6, 8, 1, 3, 5, 7, 9);
    $sum = 0;
    $last = strlen($credit_card_number) - 1;
    
    for ($i = 0; $i &amp;lt;= $last; $i++) {
        $sum += $map[$credit_card_number[$last - $i] + ($i &amp;amp; 1) * 10];
    }
    
    if ($sum % 10 != 0) {
       return '&amp;lt;li&amp;gt;This is not a valid credit card number. Please use a different credit/debit card or re-enter your credit/debit card details.&amp;lt;/li&amp;gt;';
    } else {
       //If we made it this far the credit card number is in a valid format
       return 'This is a valid credit card number' ;
    }
   
} //END validateCreditcard_number&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2011 00:40:32 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-to-determine-invalid-credit-card-number/m-p/18772#M10389</guid>
      <dc:creator>three3</dc:creator>
      <dc:date>2011-11-10T00:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine invalid credit card number</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-to-determine-invalid-credit-card-number/m-p/18774#M10390</link>
      <description>&lt;P&gt;From &lt;A href="http://stackoverflow.com/questions/8073682/how-to-determine-which-number-in-a-series-is-the-invalid-credit-card-number" target="_self"&gt;StackOverflow&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;The Luhn checksum can't detect which digit is incorrect, it can only detect single-digit errors and some multi-digit errors. It's entirely possible to mistype two digits and get a number with a valid checksum."&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2011 01:25:16 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-to-determine-invalid-credit-card-number/m-p/18774#M10390</guid>
      <dc:creator>stymiee</dc:creator>
      <dc:date>2011-11-10T01:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine invalid credit card number</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-to-determine-invalid-credit-card-number/m-p/18780#M10393</link>
      <description>&lt;P&gt;Sorry for asking stupid questions, but aside from maybe basic length checking, why are you bothering with this at all? Leave it to Authorize.net to do anything advanced that needs doing.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2011 09:08:16 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-to-determine-invalid-credit-card-number/m-p/18780#M10393</guid>
      <dc:creator>TJPride</dc:creator>
      <dc:date>2011-11-10T09:08:16Z</dc:date>
    </item>
  </channel>
</rss>

