<?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
* ------------------------------------------------------------------------
*/