GUMP::validate_valid_cc PHP Method

validate_valid_cc() protected method

See: http://stackoverflow.com/questions/174730/what-is-the-best-way-to-validate-a-credit-card-in-php Usage: '' => 'valid_cc'
protected validate_valid_cc ( string $field, array $input, $param = null ) : mixed
$field string
$input array
return mixed
    protected function validate_valid_cc($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }
        $number = preg_replace('/\\D/', '', $input[$field]);
        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;
        }
        if ($total % 10 == 0) {
            return;
            // Valid
        }
        return array('field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param);
    }