Last active
October 22, 2025 18:10
-
-
Save claudiosanches/26d9668f21dbdc787472 to your computer and use it in GitHub Desktop.
Revisions
-
claudiosanches revised this gist
May 1, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ <?php // Test cards $cards = array( '378282246310005', // American Express '371449635398431', // American Express @@ -18,6 +19,7 @@ '4012888888881881', // Visa ); // Brands regex $brands = array( 'visa' => '/^4\d{12}(\d{3})?$/', 'mastercard' => '/^(5[1-5]\d{4}|677189)\d{10}$/', @@ -31,6 +33,7 @@ 'maestro' => '/^(?:5[0678]\d\d|6304|6390|67\d\d)\d{8,15}$/', ); // Run test foreach ( $cards as $number ) { $brand = 'undefined'; -
claudiosanches revised this gist
May 1, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ <?php $cards = array( '378282246310005', // American Express '371449635398431', // American Express @@ -13,11 +12,12 @@ '6062825624254001', // Hipercard '5555555555554444', // MasterCard '5105105105105100', // MasterCard '6759649826438453', // Maestro '6799990100000000019', // Maestro '4111111111111111', // Visa '4012888888881881', // Visa ); $brands = array( 'visa' => '/^4\d{12}(\d{3})?$/', 'mastercard' => '/^(5[1-5]\d{4}|677189)\d{10}$/', @@ -27,10 +27,10 @@ 'amex' => '/^3[47]\d{13}$/', 'jcb' => '/^(?:2131|1800|35\d{3})\d{11}$/', 'aura' => '/^(5078\d{2})(\d{2})(\d{11})$/', 'hipercard' => '/^(606282\d{10}(\d{3})?)|(3841\d{15})$/', 'maestro' => '/^(?:5[0678]\d\d|6304|6390|67\d\d)\d{8,15}$/', ); foreach ( $cards as $number ) { $brand = 'undefined'; -
claudiosanches created this gist
May 1, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ <?php // Test cards $cards = array( '378282246310005', // American Express '371449635398431', // American Express '5078601870000127985', // Aura '5078601800003247449', // Aura '30569309025904', // Diners Club '38520000023237', // Diners Club '6011111111111117', // Discover '6362970000457013', // Elo '6062825624254001', // Hipercard '5555555555554444', // MasterCard '5105105105105100', // MasterCard '4111111111111111', // Visa '4012888888881881', // Visa ); // Brands regex $brands = array( 'visa' => '/^4\d{12}(\d{3})?$/', 'mastercard' => '/^(5[1-5]\d{4}|677189)\d{10}$/', 'diners' => '/^3(0[0-5]|[68]\d)\d{11}$/', 'discover' => '/^6(?:011|5[0-9]{2})[0-9]{12}$/', 'elo' => '/^((((636368)|(438935)|(504175)|(451416)|(636297))\d{0,10})|((5067)|(4576)|(4011))\d{0,12})$/', 'amex' => '/^3[47]\d{13}$/', 'jcb' => '/^(?:2131|1800|35\d{3})\d{11}$/', 'aura' => '/^(5078\d{2})(\d{2})(\d{11})$/', 'hipercard' => '/^(606282\d{10}(\d{3})?)|(3841\d{15})$/' ); // Run test foreach ( $cards as $number ) { $brand = 'undefined'; foreach ( $brands as $_brand => $regex ) { if ( preg_match( $regex, $number ) ) { $brand = $_brand; break; } } echo '<pre>' . print_r( array( $number, $brand ), true ) . '</pre>'; }