code: protected function valid_cc($data)
      {
          $number = preg_replace('/\D/', '', $data);
          if (function_exists('mb_strlen')) {
              $number_length = mb_strlen($number);
          } else {
              $number_length = strlen($number);
          }
  
          $parity = $number_length % 2;
          $total = 0;
          for ($i = 0; $i < $number_length; $i++) {
              $digit = $number[$i];
  
              if ($i % 2 == $parity) {
                  $digit *= 2;
  
                  if ($digit > 9) {
                      $digit -= 9;
                  }
              }
  
              $total += $digit;
          }
  
          return ($total % 10 == 0) ? true : false;
      }
docs: Credit Card Validation
  
  @param string $data
  
  @return boolean