CodeIgniter Forums
how to know credit card - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to know credit card (/showthread.php?tid=63823)



how to know credit card - nady - 12-12-2015

Hallo everyone
i just wanted to know that if user input his credit card details then how can i check it's master card, visa card or etc.
Help me..
Thanks
Nady


RE: how to know credit card - Narf - 12-12-2015

Please stop posting the same thread in different sections of the forums; I've deleted 4 duplicates from you since yesterday.


RE: how to know credit card - rfulcher - 12-16-2015

One of the easiest ways to figure that out is to use this https://github.com/stripe/jquery.payment. On the page as the card is being entered you can store the card type to a field.

If you want to do it in PHP there are many ways it can be done.  Read over this post http://stackoverflow.com/questions/72768/how-do-you-detect-credit-card-type-based-on-number.

Good luck.


RE: how to know credit card - attrox - 12-16-2015

Mastercard number starts with 5.
Visa starts with 4.
Discover starts with 6.
AMEX starts with 3.


RE: how to know credit card - InsiteFX - 12-16-2015

(12-12-2015, 03:45 AM)nady Wrote: Hallo everyone
i just wanted to know that if user input his credit card details then how can i check it's master card, visa card or etc.
Help me..
Thanks
Nady


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ------------------------------------------------------------------------
 * Editor   : PhpStorm 10.0.2
 * Date     : 12/16/2015
 * Time     : 11:45 AM
 * Authors  : Raymond L King Sr.
 * ------------------------------------------------------------------------
 * 
 * Class        creditcard_helper
 * 
 * @project     Fx
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2015 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ------------------------------------------------------------------------
 */

/**
 * card_type ()
 * ------------------------------------------------------------------------
 *
 * Return  credit card type if card number is valid
 *
 * @param  $card_number string
 * @return string
 **/
if ( ! function_exists('card_type'))
{
    
/**
     * ------------------------------------------------------------------------
     * card_type ()
     * ------------------------------------------------------------------------
     *
     * @param  $card_number
     * @return string
     */
    
function card_type($card_number)
    {
        
$card_number preg_replace('/[^\d]/'''$card_number);

        if (
preg_match('/^3[47][0-9]{13}$/'$card_number))
        {
            return 
'American Express';
        }
        elseif (
preg_match('/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/'$card_number))
        {
            return 
'Diners Club';
        }
        elseif (
preg_match('/^6(?:011|5[0-9][0-9])[0-9]{12}$/'$card_number))
        {
            return 
'Discover';
        }
        elseif (
preg_match('/^(?:2131|1800|35\d{3})\d{11}$/'$card_number))
        {
            return 
'JCB';
        }
        elseif (
preg_match('/^5[1-5][0-9]{14}$/'$card_number))
        {
            return 
'MasterCard';
        }
        elseif (
preg_match('/^4[0-9]{12}(?:[0-9]{3})?$/'$card_number))
        {
            return 
'Visa';
        }
        else
        {
            return 
'Unknown';
        }
    }
}

/**
 * ------------------------------------------------------------------------
 * Filename: creditcard_helper.php
 * Location: ./application/helpers/creditcard_helper.php
 * ------------------------------------------------------------------------
 */ 



RE: how to know credit card - Rahmacruz - 02-25-2019

From my point of view you can't do this as per the laws. **Link redacted**