Changeset 1670

Show
Ignore:
Timestamp:
01/04/2008 01:07:23 PM (12 months ago)
Author:
Shadowhand
Message:

Updated valid::creditcard:

  • Renamed valid::creditcard to valid::credit_card, as per naming convetions
  • Moved card definitions to config/credit_cards.php, to allow user extensions
  • Remove non-digit characters, rather than expecting all digits
Location:
trunk/system
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/valid.php

    r1579 r1670  
    123123 
    124124        /** 
    125          * Validates a credit card number using the Luhn (mod10) formula. Make sure 
    126          * to remove all non-digit characters from the number before using validating 
    127          * the card number or it will fail. 
     125         * Validates a credit card number using the Luhn (mod10) formula. 
    128126         * @see http://en.wikipedia.org/wiki/Luhn_algorithm 
    129127         * 
    130          * @param   integer  credit card number (13-16 digits) 
     128         * @param   integer  credit card number 
    131129         * @param   string   card type 
    132130         * @return  boolean 
    133131         */ 
    134         public static function creditcard($number, $type = 'default') 
    135         { 
    136                 // Make sure the number and expiration are not empty and consist of only numbers 
    137                 if (empty($number) OR ! ctype_digit((string) $number)) 
    138                         return FALSE; 
    139  
    140                 // Card types based on http://en.wikipedia.org/wiki/Credit_card_number 
    141                 $cards = array 
    142                 ( 
    143                         'default' => array 
    144                         ( 
    145                                 'length' => '13,14,15,16,17,18,19', 
    146                                 'prefix' => '', 
    147                                 'luhn'   => TRUE 
    148                         ), 
    149                         'american express' => array 
    150                         ( 
    151                                 'length' => '15', 
    152                                 'prefix' => '3[47]', 
    153                                 'luhn'   => TRUE 
    154                         ), 
    155                         'maestro' => array 
    156                         ( 
    157                                 'length' => '16,18', 
    158                                 'prefix' => '50(?:20|38)|6(?:304|759)', 
    159                                 'luhn'   => TRUE 
    160                         ), 
    161                         'mastercard' => array 
    162                         ( 
    163                                 'length' => '16', 
    164                                 'prefix' => '5[1-5]', 
    165                                 'luhn'   => TRUE 
    166                         ), 
    167                         'visa' => array 
    168                         ( 
    169                                 'length' => '13,16', 
    170                                 'prefix' => '4', 
    171                                 'luhn'   => TRUE 
    172                         ), 
    173                         'visa electron' => array 
    174                         ( 
    175                                 'length' => '16', 
    176                                 'prefix' => '4(?:17500|91[37]|508|844)', 
    177                                 'luhn'   => TRUE 
    178                         ), 
    179                 ); 
     132        public static function credit_card($number, $type = 'default') 
     133        { 
     134                // Remove all non-digit characters from the number 
     135                if (($number = preg_replace('/[^0-9]/', '', $number)) === '') 
     136                        return FALSE; 
     137 
     138                $cards = Config::item('credit_cards'); 
    180139 
    181140                // Check card type 
     
    188147                $length = strlen($number); 
    189148 
     149                // Validate the card length by the card type 
    190150                if ( ! preg_match('/\b'.$length.'\b/', $cards[$type]['length'])) 
    191151                        return FALSE; 
  • trunk/system/libraries/Calendar.php

    r1616 r1670  
    1717 
    1818        // Start the calendar on Sunday by default 
    19         public $week_start = 3; 
     19        public $week_start = 0; 
    2020 
    2121        // Event data