Validates a Credit Card number

@param string $creditCardNumber

@throws \yii\base\Exception

@return bool
@return bool
505689
public function validateNumber($creditCardNumber)
    {
        if (!$this->checkType()) {
            throw new Exception(Yii::t('ECCValidator', 'The "format" property must be specified with a supported Credit Card format.'));
        }

        $creditCardNumber = preg_replace('/[ -]+/', '', $creditCardNumber);

        return $this->checkFormat($creditCardNumber) && $this->mod10($creditCardNumber);
    }
939529
protected function validate()
    {
        $result = $this->request($action = 'CheckCredits');
        if ((int) $result <= 0) {
            throw new Exception($this->config['codes']['-100']);
        }
        return $result;
    }
1078755
public static function isCardNumberValid($param)
	{
		$isValid = false;

		if(isset($param['number'])) {

			$errorIsEmpty = CheckoutApi_Lib_Validator::isEmpty($param['number']) ;
			
			if(!$errorIsEmpty) {
				//$this->logError(true, "Card number can not be empty.", array('card'=>$param),false);
				$isValid = true;
			}

		} 

		return $isValid;
	}
232678
public static function isValidYear($card)
	{
		$isValid = false;

		if(isset($card['expiryYear'])) {

			$isExpiryYear = CheckoutApi_Lib_Validator::isEmpty($card['expiryYear']);
			
			if( !$isExpiryYear && CheckoutApi_Lib_Validator::isInteger($card['expiryYear']) &&
				( CheckoutApi_Lib_Validator::isLength($card['expiryYear'], 2) ||  CheckoutApi_Lib_Validator::isLength($card['expiryYear'], 4) ) ) {
			
				$isValid = true;
			
			} 
		}

		return $isValid;
	}
1084607
public function isValid()
    {
        $value = $this->field->getValue();

        if (is_array($value) || is_object($value)) {
            throw new \Exception("This validator only works on scalar types!");
        }

        // required but not given
        if ($this->required && $value == null) {
            return false;
        } // if the field is not required and the value is empty, then it's also valid
        elseif (!$this->required && $value == "") {
            return true;
        }

        $len = strlen($value);

        // shorter then min length
        if ($len < $this->getMinLength()) {
            return false;
        }

        // bigger then the given length
        if ($this->getMaxLength() > 0 && $len > $this->getMaxLength()) {
            return false;
        }

        return true;
    }
1223503
protected function cardValidate()
    {

        if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) {
            return;
        }

        /** @var CreditCard $card */
        $card = $this->getCard();
        $card->validate();
    }
667912
public static function isMonthValid($card)
	{
		$isValid = false;

		if(isset($card['expiryMonth'])) {

			$isExpiryMonthEmpty = CheckoutApi_Lib_Validator::isEmpty($card['expiryMonth'],false);
			
			if(!$isExpiryMonthEmpty && CheckoutApi_Lib_Validator::isInteger($card['expiryMonth']) && ($card['expiryMonth']  > 0 && $card['expiryMonth'] < 13)) {
				$isValid = true;
			} 
		} 

		return $isValid;
	}
1336862
private function validateNew(string $vatNumber): bool
    {
        $multiplier = 34;
        $substractor = 100;
        if (ctype_digit($vatNumber[0])) {
            $multiplier = 24;
            $substractor = 10;
        }

        $checkCharacter = array_flip(str_split($this->alphabet));
        $checkval = ($checkCharacter[$vatNumber[0]] * $multiplier) + $checkCharacter[$vatNumber[1]] - $substractor;

        return (((intval(substr($vatNumber, 2)) + ($checkval / 11) + 1) % 11) == $checkval % 11);
    }
158181
public function isValid($value = null, array $options = []): bool
    {
        if (\count($options) > 0) {
            $this->setOptions($options);
        }
        $this->setValue(\str_replace(' ', '', (string)$value));
        $this->errors = [];

        if ($this->options['type'] == 'any') {
            $types = \array_keys($this->validationData);
        } elseif (\array_key_exists($this->options['type'], $this->validationData)) {
            $types = [$this->options['type']];
        } else {
            throw new DomainException('Unsopported credit card type: '.$this->options['type']);
        }

        $validType = $this->validateType($types);
        $validNumber = $this->validateNumber();

        return $validType && $validNumber;
    }
757578
private function validateIENew(string $vatNumber): bool
    {
        $checksum = strtoupper(substr($vatNumber, 7, 1));
        $checkNumber = substr($vatNumber, 0, 8);
        $checkval = 0;

        for ($i = 2; $i <= 8; $i++) {
            $checkval += (int)$checkNumber[8 - $i] * $i;
        }

        if (strlen($vatNumber) == 9) {
            $checkval += (9 * strpos($this->alphabet, $vatNumber[8]));
        }

        $checkval = ($checkval % 23);

        if ($checkval == 0) {
            return $checksum == 'W';
        }

        $checkchar = 'A';
        for ($i = $checkval - 1; $i > 0; $i--) {
            $checkchar++;
        }

        return $checkchar == $checksum;
    }
1033073
@Override
  public final boolean isValid(final String pvalue, final ConstraintValidatorContext pcontext) {
    if (StringUtils.isEmpty(pvalue)) {
      return true;
    }
    if (pvalue.length() > LENGTH_CREDIT_CARDNUMBER) {
      // credit card number is to long, but that's handled by size annotation
      return true;
    }
    return CHECK_CREDIT_CARD.isValid(pvalue);
  }
1311496
function confirmation() {
    if (isset($_POST['authorizenet_cc_number'])) {
      $confirmation = array('title' => $this->title . ': ' . $this->cc_card_type,
                            'fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CREDIT_CARD_OWNER,
                                                    'field' => $_POST['authorizenet_cc_owner']),
                                              array('title' => MODULE_PAYMENT_AUTHORIZENET_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_TEXT_CREDIT_CARD_EXPIRES,
                                                    'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['authorizenet_cc_expires_month'], 1, '20' . $_POST['authorizenet_cc_expires_year'])))));
    } else {
      $confirmation = array(); //array('title' => $this->title);
    }
    return $confirmation;
  }
346584
protected function _validateNumber($value, $column) {
        // Not much to check, since 0 is falsy but also a valid integer value.
        if (is_null($value)) {
            throw new Garp_Model_Validator_Exception(
                sprintf(__('%s is a required field'), __(Garp_Util_String::underscoredToReadable($column)))
            );
        }
    }
982082
public function get_slot_by_number($slotnumber) {
        foreach ($this->slots as $slot) {
            if ($slot->slot == $slotnumber) {
                return $slot;
            }
        }

        throw new \coding_exception('The \'slotnumber\' could not be found.');
    }
158926
protected function mod10($cardNumber)
    {
        $cardNumber = strrev($cardNumber);
        $numSum = 0;
        for ($i = 0; $i < strlen($cardNumber); $i++) {
            $currentNum = substr($cardNumber, $i, 1);
            if ($i % 2 == 1) {
                $currentNum *= 2;
            }
            if ($currentNum > 9) {
                $firstNum = $currentNum % 10;
                $secondNum = ($currentNum - $firstNum) / 10;
                $currentNum = $firstNum + $secondNum;
            }
            $numSum += $currentNum;
        }

        return $numSum % 10 == 0;
    }
1133659
protected static int findMatchingRange(long creditCardNumber) {
	if (creditCardNumber < 1000000000000L) {
	    return NOT_ENOUGH_DIGITS;
	}
	if (creditCardNumber > 9999999999999999L) {
	    return TOO_MANY_DIGITS;
	}
	// check the cached index first, where we last found a number.
	if (ranges[cachedLastFind].low <= creditCardNumber && creditCardNumber <= ranges[cachedLastFind].high) {
	    return cachedLastFind;
	}
	for (int i = 0; i < ranges.length; i++) {
	    if (ranges[i].low <= creditCardNumber && creditCardNumber <= ranges[i].high) {
		// we have a match
		cachedLastFind = i;
		return i;
	    }
	} // end for
	return UNKNOWN_VENDOR;
    }
1367000
public function setCardNumber($number)
    {
        $number = preg_replace('/[^\d]/', '', $number);

        if(strlen($number) > 20)
        {
            throw new ErrorException('Card number longer than twenty (20) digits');
        }

        $this->cardNumber = $number;

        return $this;
    }