Checks Credit Card Prefixes

@param $cardNumber

@return bool
764253
protected function checkFormat($cardNumber)
    {
        return preg_match('/^[0-9]+$/', $cardNumber) && preg_match($this->patterns[$this->format], $cardNumber);
    }
1211718
protected function checkDigitOurNumber()
    {
        $title = $this->title;
        $assignment = $title->assignment;

        $our_number = BankInterchange\Utils::padNumber($assignment->agency, 3)
            . BankInterchange\Utils::padNumber($title->our_number, 8);

        return $title->checkDigitOurNumberAlgorithm($our_number);
    }
871577
def credit_card_number(self, card_type=None):
        
        card = self._credit_card_type(card_type)
        prefix = self.random_element(card.prefixes)
        number = self._generate_number(self.numerify(prefix), card.length)
        return number
210691
public function verifyCard(Card $card)
    {
        if ($this->verifySelfSignature) {
            if (!$this->validateSignerSignature($card, 'self', $card->getPublicKey())) {
                return false;
            }
        }

        if ($this->verifyVirgilSignature) {
            if (!$this->validateSignerSignature($card, 'virgil', $this->virgilPublicKey)) {
                return false;
            }
        }

        foreach ($this->whiteLists as $whiteList) {
            $isOk = false;
            foreach ($whiteList->getCredentials() as $credentials) {
                if ($this->validateSignerSignature($card, $credentials->getSigner(), $credentials->getPublicKey())) {
                    $isOk = true;
                    break;
                }
            }

            if (!$isOk) {
                return false;
            }
        }

        return true;
    }
602808
public function getEmployeeIdByKey($cardNumber)
    {
        $cardNumber = $this->prepareKey($cardNumber);
        $result     = null;
        $this->addHeader();
        try {
            $soapResult = $this->getSoap()->GetAssignedAcsKeyByKeyNumber([
                'keyNumber' => $cardNumber
            ]);
            if (isset($soapResult->GetAssignedAcsKeyByKeyNumberResult->AcsEmployeeId)) {
                $result = $soapResult->GetAssignedAcsKeyByKeyNumberResult->AcsEmployeeId;
            }
        } catch (\SoapFault $ex) {
            $this->logError();
        }

        return $result;
    }
947232
public function rule_credit_card($a)
    {
        // Card formats keep changing and there is too high a risk
        // of false negatives if we get clever. So we just check it
        // with the Luhn Mod 10 formula

        // Calculate the Luhn check number

        $msg = 'Not a valid card number';

        $sum = 0;
        $alt = false;

        for ($i = strlen($a) - 1; $i >= 0; --$i) {
            $n = substr($a, $i, 1);
            if ($alt) {
                //square n
                $n *= 2;
                if ($n > 9) {
                    //calculate remainder
                    $n = ($n % 10) + 1;
                }
            }
            $sum += $n;
            $alt = !$alt;
        }

        // If $sum divides exactly by 10 it's valid

        if (!($sum % 10 == 0)) {
            return $this->fail($msg);
        } else {
            // Luhn check seems to return true for any string of 0s

            $stripped = str_replace('0', '', $a);

            if (strlen($stripped) == 0) {
                return $this->fail($msg);
            }
        }
    }
789960
public boolean validateCardNumber() {
        boolean cardNumberIsValid =
                CardUtils.isValidCardNumber(mCardNumberEditText.getCardNumber());
        mCardNumberEditText.setShouldShowError(!cardNumberIsValid);
        return cardNumberIsValid;
    }
573210
public function cardNumber($value): bool
    {
        if (!is_string($value) || strlen($value) < 12) {
            return false;
        }

        $result = 0;
        $odd = strlen($value) % 2;
        preg_replace('/[^0-9]+/', '', $value);

        for ($i = 0; $i < strlen($value); ++$i) {
            $result += $odd
                ? $value[$i]
                : (($value[$i] * 2 > 9) ? $value[$i] * 2 - 9 : $value[$i] * 2);

            $odd = !$odd;
        }

        // Check validity.
        return ($result % 10 == 0) ? true : false;
    }
659061
function confirmation() {
    $confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_TYPE,
                                                  'field' => $this->cc_card_type),
                                            array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_OWNER,
                                                  'field' => $_POST['authorizenet_aim_cc_owner']),
                                            array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_NUMBER,
                                                  'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
                                            array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_EXPIRES,
                                                  'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['authorizenet_aim_cc_expires_month'], 1, '20' . $_POST['authorizenet_aim_cc_expires_year']))) ));
    return $confirmation;
  }
413006
protected function _isValidType($type, $number)
    {
        // testing if card type is known and matches pattern
        if (isset($this->_aCardsInfo[$type])) {
            return preg_match($this->_aCardsInfo[$type], $number);
        }

        return true;
    }
491460
private boolean checkNlTaxNumber(final String ptaxNumber) {
    final int checkSum = ptaxNumber.charAt(8) - '0';
    int sum = 0;
    for (int i = 0; i < ptaxNumber.length() - 1; i++) {
      sum += (ptaxNumber.charAt(i) - '0') * (9 - i);
    }
    sum -= checkSum;
    return sum % 11 == 0;
  }
145274
public static function threeOfAKind(CardCollection $cards)
    {
        $judgedHand = self::nNumberOfCardsInSet($cards, 3);

        if ($judgedHand === null) {
            return false;
        }

        $highCards = $cards->diff($judgedHand)->sortByValue()->reverse()->take(2);

        return $judgedHand
            ->merge($highCards)
            ->switchAceValue()
            ->sortByValue();
    }
1190466
public function validate($bankAccountNumber)
    {
        if (is_array($bankAccountNumber)) {
            $parts = $bankAccountNumber;
        } else {
            $parts = $this->parseNumber($bankAccountNumber);
        }

        if (empty($parts)) {
            return false;
        }
        list($firstPart, $secondPart, $bankCode) = $parts;

        if (!$this->validateBankCode($bankCode)) {
            return false;
        }

        if (null !== $firstPart && !$this->validateCheckSum($firstPart)) {
            return false;
        }

        if (!$this->validateCheckSum($secondPart)) {
            return false;
        }

        return true;
    }
1020741
public function delCard($card_id) {
        $data = array(
            'card_id' => $card_id,
        );
        if (!$this->access_token && !$this->checkAuth()) return false;
        $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_DELETE . 'access_token=' . $this->access_token, self::json_encode($data));
        if ($result) {
            $json = json_decode($result, true);
            if (!$json || !empty($json['errcode'])) {
                $this->errCode = $json['errcode'];
                $this->errMsg  = $json['errmsg'];
                return false;
            }
            return true;
        }
        return false;
    }
1114423
protected function validateCreditCard($field, $value, $params)
    {
        /**
         * I there has been an array of valid cards supplied, or the name of the users card
         * or the name and an array of valid cards
         */
        if (!empty($params)) {
            /**
             * array of valid cards
             */
            if (\is_array($params[0])) {
                $cards = $params[0];
            } elseif (\is_string($params[0])) {
                $cardType = $params[0];
                if (isset($params[1]) && \is_array($params[1])) {
                    $cards = $params[1];
                    if (!\in_array($cardType, $cards, true)) {
                        return false;
                    }
                }
            }
        }


        if ($this->creditCardNumberIsValid($value)) {
            $cardRegex = [
                'visa' => '#^4[0-9]{12}(?:[0-9]{3})?$#',
                'mastercard' => '#^(5[1-5]|2[2-7])[0-9]{14}$#',
                'amex' => '#^3[47][0-9]{13}$#',
                'dinersclub' => '#^3(?:0[0-5]|[68][0-9])[0-9]{11}$#',
                'discover' => '#^6(?:011|5[0-9]{2})[0-9]{12}$#',
            ];

            if (isset($cardType)) {
                // if we don't have any valid cards specified and the card we've been given isn't in our regex array
                if (!isset($cards) && !isset($cardRegex[$cardType])) {
                    return false;
                }

                // we only need to test against one card type
                return (\preg_match($cardRegex[$cardType], $value) === 1);
            }

            if (isset($cards)) {
                // if we have cards, check our users card against only the ones we have
                foreach ($cards as $card) {
                    if (
                        isset($cardRegex[$card]) &&
                        \preg_match($cardRegex[$card], $value) === 1 // if the card is valid, we want to stop looping
                    ) {
                        return true;
                    }
                }
            } else {
                // loop through every card
                foreach ($cardRegex as $regex) {
                    // until we find a valid one
                    if (\preg_match($regex, $value) === 1) {
                        return true;
                    }
                }
            }
        }

        // if we've got this far, the card has passed no validation so it's invalid!
        return false;
    }
332073
private function sourceExists(StripeLocalCard $card, Collection $sources)
    {
        /** @var Card $source */
        foreach ($sources->data as $source) {
            if ($card->getId() === $source->id) {
                return true;
            }
        }

        return false;
    }
568070
public static function fourOfAKind(CardCollection $cards)
    {
        $judgedHand = self::nNumberOfCardsInSet($cards, 4);

        if ($judgedHand === null) {
            return false;
        }

        $highCard = self::highCard($cards->diff($judgedHand))->last();

        return $judgedHand
            ->push($highCard)
            ->switchAceValue()
            ->sortByValue();
    }