Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes | Static Protected Attributes
Zend_Validate_Ccnum Class Reference
Inheritance diagram for Zend_Validate_Ccnum:
Zend_Validate_Abstract Zend_Validate_Interface

Public Member Functions

 __construct ()
 
 isValid ($value)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 

Data Fields

const LENGTH = 'ccnumLength'
 
const CHECKSUM = 'ccnumChecksum'
 

Protected Attributes

 $_messageTemplates
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Static Protected Attributes

static $_filter = null
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 

Detailed Description

Definition at line 33 of file Ccnum.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Definition at line 62 of file Ccnum.php.

63  {
64  trigger_error('Using the Ccnum validator is deprecated in favor of the CreditCard validator');
65  }

Member Function Documentation

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)

Parameters
string$value
Returns
boolean
See also
Zend_Filter_Digits

Implements Zend_Validate_Interface.

Definition at line 75 of file Ccnum.php.

76  {
77  $this->_setValue($value);
78 
79  if (null === self::$_filter) {
83  #require_once 'Zend/Filter/Digits.php';
84  self::$_filter = new Zend_Filter_Digits();
85  }
86 
87  $valueFiltered = self::$_filter->filter($value);
88 
89  $length = strlen($valueFiltered);
90 
91  if ($length < 13 || $length > 19) {
92  $this->_error(self::LENGTH);
93  return false;
94  }
95 
96  $sum = 0;
97  $weight = 2;
98 
99  for ($i = $length - 2; $i >= 0; $i--) {
100  $digit = $weight * $valueFiltered[$i];
101  $sum += floor($digit / 10) + $digit % 10;
102  $weight = $weight % 2 + 1;
103  }
104 
105  if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) {
106  $this->_error(self::CHECKSUM, $valueFiltered);
107  return false;
108  }
109 
110  return true;
111  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16
$i
Definition: gallery.phtml:31

Field Documentation

◆ $_filter

$_filter = null
staticprotected

Definition at line 50 of file Ccnum.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::LENGTH => "'%value%' must contain between 13 and 19 digits",
self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'"
)

Definition at line 57 of file Ccnum.php.

◆ CHECKSUM

const CHECKSUM = 'ccnumChecksum'

Validation failure message key for when the value fails the mod-10 checksum

Definition at line 43 of file Ccnum.php.

◆ LENGTH

const LENGTH = 'ccnumLength'

Validation failure message key for when the value is not of valid length

Definition at line 38 of file Ccnum.php.


The documentation for this class was generated from the following file: