/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a valid integer * * @param string|integer $value * @return boolean */ public function isValid($value) { if (!is_string($value) && !is_int($value) && !is_float($value)) { $this->_error(self::INVALID); return false; } if (is_int($value)) { return true; } $this->_setValue($value); if ($this->_locale === null) { $locale = localeconv(); $valueFiltered = str_replace($locale['decimal_point'], '.', $value); $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered); if (strval(intval($valueFiltered)) != $valueFiltered) { $this->_error(self::NOT_INT); return false; } } else { try { if (!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { $this->_error(self::NOT_INT); return false; } } catch (Zend_Locale_Exception $e) { $this->_error(self::NOT_INT); return false; } } return true; }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a valid integer * * @param string $value * @return boolean */ public function isValid($value) { $valueString = (string) $value; $this->_setValue($valueString); if (is_bool($value)) { $this->_error(); return false; } try { if (!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { $this->_error(); return false; } } catch (Zend_Locale_Exception $e) { $this->_error(); return false; } return true; }
/** * test isInteger * expected boolean */ public function testIsInteger() { $this->assertTrue( Zend_Locale_Format::isInteger('-1.234.567,12345', array('locale' => 'de_AT'))); $this->assertFalse(Zend_Locale_Format::isInteger('textwithoutnumber', array('locale' => 'de_AT'))); }
/** * test isInteger * expected boolean */ public function testIsInteger() { $this->assertEquals(Zend_Locale_Format::isInteger('-1.234.567,12345', array('locale' => 'de_AT')), TRUE, "TRUE expected"); $this->assertEquals(Zend_Locale_Format::isInteger('textwithoutnumber', array('locale' => 'de_AT')), FALSE, "FALSE expected"); }
public function testShortNotation() { $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(0.12345)); $options = array('locale' => 'de'); $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options)); $this->assertEquals('0,75', Zend_Locale_Format::toNumber(0.75, array('locale' => 'de_DE', 'precision' => 2))); $this->assertTrue(Zend_Locale_Format::isNumber(',12345', array('locale' => 'de_AT'))); $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(0.12345)); $options = array('locale' => 'de'); $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options)); $options = array('locale' => 'ar_QA'); $this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options)); $this->assertTrue(Zend_Locale_Format::isFloat(',12345', array('locale' => 'de_AT'))); $this->assertEquals(0, Zend_Locale_Format::getInteger(0.1234567)); $options = array('locale' => 'de'); $this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options)); $this->assertEquals('0', Zend_Locale_Format::toInteger(0.123, array('locale' => 'de'))); $options = array('locale' => 'de_AT'); $this->assertEquals('0', Zend_Locale_Format::toInteger(0.12345, $options)); $this->assertFalse(Zend_Locale_Format::isInteger(',12345', array('locale' => 'de_AT'))); $options = array('locale' => 'de_AT'); $this->assertEquals('0,567', Zend_Locale_Format::toNumber(0.5669999999999999, $options)); }
/** * test if isNumberFailed * expected boolean */ public function testIsIntegerFailed() { $value = Zend_Locale_Format::isInteger('textwithoutnumber', 'de_AT'); $this->assertEquals($value, FALSE, "FALSE expected"); }
/** Checks if a given string is valid representation of an integer in the current locale. * @return bool * @example http://www.concrete5.org/documentation/how-tos/developers/formatting-numbers/ See the Formatting numbers how-to for more details */ public function isInteger($string) { return Zend_Locale_Format::isInteger($string, array('locale' => $this->getZendLocale())); }
/** * @group GH-430 */ public function testIsIntegerForLocaleZhHK() { $this->assertTrue(Zend_Locale_Format::isInteger('1', array('locale' => 'zh_HK'))); }
/** * Defined by Zend_Filter_Interface * * Normalizes the given input * * @param string $value Value to normalized * @return string|array The normalized value */ public function filter($value) { if ($this->_options['date_format'] === null && strpos($value, ':') !== false) { // Special case, no date format specified, detect time input return Zend_Locale_Format::getTime($value, $this->_options); } else { if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) { // Detect date or time input return Zend_Locale_Format::getDate($value, $this->_options); } else { if ($this->_options['precision'] === 0 && Zend_Locale_Format::isInteger($value, $this->_options)) { // Detect integer return Zend_Locale_Format::getInteger($value, $this->_options); } else { if ($this->_options['precision'] === null && Zend_Locale_Format::isFloat($value, $this->_options)) { // Detect float return Zend_Locale_Format::getFloat($value, $this->_options); } else { if (Zend_Locale_Format::isNumber($value, $this->_options)) { // Detect all other numbers return Zend_Locale_Format::getNumber($value, $this->_options); } } } } } return $value; }
public static function isBillrunKey($billrun_key) { return is_string($billrun_key) && Zend_Locale_Format::isInteger($billrun_key) && strlen($billrun_key) == 6 && substr($billrun_key, 4, 2) >= '01' && substr($billrun_key, 4, 2) <= '12'; }