Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Digits.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/Abstract.php';
26 
34 {
35  const NOT_DIGITS = 'notDigits';
36  const STRING_EMPTY = 'digitsStringEmpty';
37  const INVALID = 'digitsInvalid';
38 
44  protected static $_filter = null;
45 
51  protected $_messageTemplates = array(
52  self::NOT_DIGITS => "'%value%' must contain only digits",
53  self::STRING_EMPTY => "'%value%' is an empty string",
54  self::INVALID => "Invalid type given. String, integer or float expected",
55  );
56 
65  public function isValid($value)
66  {
67  if (!is_string($value) && !is_int($value) && !is_float($value)) {
68  $this->_error(self::INVALID);
69  return false;
70  }
71 
72  $this->_setValue((string) $value);
73 
74  if ('' === $this->_value) {
75  $this->_error(self::STRING_EMPTY);
76  return false;
77  }
78 
79  if (null === self::$_filter) {
80  #require_once 'Zend/Filter/Digits.php';
81  self::$_filter = new Zend_Filter_Digits();
82  }
83 
84  if ($this->_value !== self::$_filter->filter($this->_value)) {
85  $this->_error(self::NOT_DIGITS);
86  return false;
87  }
88 
89  return true;
90  }
91 }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16