/**
* Check that Credit Card number is valid or not.
*
* @author Junaid Atari <mj.atari@gmail.com>
* @version 1.1
* @param array $number Credit Card number
* @param string $cctype Card Type to check.
* @return bool TRUE on valid | else FALSE
*/
function isCCNumberValid ( $number, $cctype )
{
if ( !is_string ( $number)
|| !trim ( $number ) )
return false;
$ccs = array (
/* Patterns written by Junaid Atari */
// Master Card
'master' => '/^(5[1-5]{1})(\d{14})$/',
// American Express
'amex' => '/^3(4|7)\d{13}$/',
// Discover Card
'discover' => '/^6(011|22|4|5)(\d{12}|\d{13}|\d{14})$/',
// Visa Card
'visa' => '/^4(\d{12}|\d{15})$/',
// Dinners Club
'dinners' => '/^(305|36|38|54|55)(\d{12}|\d{14})$/',
// Carte Blanche
'carte' => '/^(30[0-5]{1})(\d{11})$/',
// enRoute
'enroute' => '/^2(014|149)\d{11}$/',
// Laser
'laser' => '/^6(304|706|771|709)(\d{12}|\d{13}|\d{14}'.
'|d{\15})$/',
// Visa Electron
'visaelec' => '/^4(17500|917|913|844|508)(\d{10}|\d{12})$/',
);
if ( !is_string ( $cctype )
|| !array_key_exists( strtolower ($cctype) , $ccs ) )
return false;
return (bool) preg_match ( $ccs[$cctype], $number );
}
* Check that Credit Card number is valid or not.
*
* @author Junaid Atari <mj.atari@gmail.com>
* @version 1.1
* @param array $number Credit Card number
* @param string $cctype Card Type to check.
* @return bool TRUE on valid | else FALSE
*/
function isCCNumberValid ( $number, $cctype )
{
if ( !is_string ( $number)
|| !trim ( $number ) )
return false;
$ccs = array (
/* Patterns written by Junaid Atari */
// Master Card
'master' => '/^(5[1-5]{1})(\d{14})$/',
// American Express
'amex' => '/^3(4|7)\d{13}$/',
// Discover Card
'discover' => '/^6(011|22|4|5)(\d{12}|\d{13}|\d{14})$/',
// Visa Card
'visa' => '/^4(\d{12}|\d{15})$/',
// Dinners Club
'dinners' => '/^(305|36|38|54|55)(\d{12}|\d{14})$/',
// Carte Blanche
'carte' => '/^(30[0-5]{1})(\d{11})$/',
// enRoute
'enroute' => '/^2(014|149)\d{11}$/',
// Laser
'laser' => '/^6(304|706|771|709)(\d{12}|\d{13}|\d{14}'.
'|d{\15})$/',
// Visa Electron
'visaelec' => '/^4(17500|917|913|844|508)(\d{10}|\d{12})$/',
);
if ( !is_string ( $cctype )
|| !array_key_exists( strtolower ($cctype) , $ccs ) )
return false;
return (bool) preg_match ( $ccs[$cctype], $number );
}
0 comments:
Post a Comment