Welcome Guest, Not a member yet? Register   Sign In
how to know credit card
#5

(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
 * ------------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
how to know credit card - by nady - 12-12-2015, 03:45 AM
RE: how to know credit card - by Narf - 12-12-2015, 06:12 AM
RE: how to know credit card - by rfulcher - 12-16-2015, 09:17 AM
RE: how to know credit card - by attrox - 12-16-2015, 09:23 AM
RE: how to know credit card - by InsiteFX - 12-16-2015, 09:56 AM
RE: how to know credit card - by Rahmacruz - 02-25-2019, 11:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB