--- trunk/library/Zend/Validate/CreditCard.php (revision 21561) +++ trunk/library/Zend/Validate/CreditCard.php (working copy) @@ -55,6 +55,7 @@ const INVALID = 'creditcardInvalid'; const LENGTH = 'creditcardLength'; const PREFIX = 'creditcardPrefix'; + const NOPREFIX = 'creditcardNoPrefix'; const SERVICE = 'creditcardService'; const SERVICEFAILURE = 'creditcardServiceFailure'; @@ -69,6 +70,7 @@ self::INVALID => "Invalid type given, value should be a string", self::LENGTH => "'%value%' contains an invalid amount of digits", self::PREFIX => "'%value%' is not from an allowed institute", + self::NOPREFIX => "'%value%' is not from a known institute", self::SERVICE => "Validation of '%value%' has been failed by the service", self::SERVICEFAILURE => "The service returned a failure while validating '%value%'", ); @@ -258,27 +260,31 @@ } $length = strlen($value); - $types = $this->getType(); + $types = array_keys($this->_cardLength); $found = false; foreach ($types as $type) { - if (in_array($length, $this->_cardLength[$type])) { - foreach ($this->_cardType[$type] as $prefix) { - if (substr($value, 0, strlen($prefix)) == $prefix) { - $found = true; - break; - } + foreach ($this->_cardType[$type] as $prefix) { + if (substr($value, 0, strlen($prefix)) == $prefix) { + $found = true; + break 2; } } } + + if (false == $found) { + $this->_error(self::NOPREFIX, $value); + return false; + } + + $allowedTypes = $this->getType(); + if (true == $found && !in_array($type, $allowedTypes)) { + $this->_error(self::PREFIX, $value); + return false; + } - if ($found == false) { - if (!in_array($length, $this->_cardLength[$type])) { - $this->_error(self::LENGTH, $value); - return false; - } else { - $this->_error(self::PREFIX, $value); - return false; - } + if (true == $found && !in_array($length, $this->_cardLength[$type])) { + $this->_error(self::LENGTH, $value); + return false; } $sum = 0;