/** * @return Float */ public static function floatValidator() { $validator = new IsFloat(); $validator->setMessage("Input harus digit angka."); return $validator; }
/** * Returns true if and only if $value is a number correctly expressed with the scientific notation * * Note that it can only validate string inputs. * * @param mixed $value * @return bool */ public function isValid($value) { if (!is_scalar($value) || is_bool($value)) { $this->error(self::INVALID_INPUT); return false; } $formatter = new \NumberFormatter($this->getLocale(), \NumberFormatter::SCIENTIFIC); $flags = 'i'; $expSymbol = 'E'; if (StringUtils::hasPcreUnicodeSupport()) { $expSymbol = preg_quote($formatter->getSymbol(\NumberFormatter::EXPONENTIAL_SYMBOL)); $flags .= 'u'; } // Check that exponentation symbol is present $search = str_replace("", '', sprintf('/%s/%s', $expSymbol, $flags)); $value = str_replace("", '', $value); if (!preg_match($search, $value)) { $this->error(self::NOT_SCIENTIFIC); return false; } // Check that the number expressed in scientific notation is a valid number $float = new IsFloat(['locale' => $this->getLocale()]); if (!$float->isValid($value)) { $this->error(self::NOT_NUMBER); return false; } return true; }
/** * {@inheritdoc} */ public function isValid($value) { $validator = new IsFloat($this->options); return $validator->isValid($value); }