Skip to content

Numeric

Pieter Hordijk edited this page Jan 1, 2019 · 1 revision

TOC

FloatType

Validates the input (mixed) to be a float or a string representing a float.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\FloatType;

(new FloatType())->validate('12.5');

Failure reasons

  • Numeric.FloatType when the value does not represent a float

Integer

Validates the input (mixed) to be an integer or a string representing an integer.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\Integer;

(new Integer())->validate('12');

Failure reasons

  • Numeric.Integer when the value does not represent an integer

Maximum

Validates the input (numeric) to be smaller than or exactly the maximum value (float).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\Maximum;

(new Maximum(16))->validate('12');

Failure reasons

  • Numeric.NumericType when the value is not a numeric type
  • Numeric.Maximum when the value is greater than maximum

Minimum

Validates the input (numeric) to be greater than or exactly the minimum value (float).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\Minimum;

(new Minimum(9))->validate('12');

Failure reasons

  • Numeric.NumericType when the value is not a numeric type
  • Numeric.Minimum when the value is smaller than minimum

Negative

Validates the input (numeric) to be a negative value. A value is being considered negative when it is smaller than zero (0).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\Negative;

(new Negative())->validate(-1);

Failure reasons

  • Numeric.NumericType when the value is not a numeric type
  • Numeric.Negative when the value is smaller than zero

NumericType

Validates the input (mixed) to be a numeric type.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\NumericType;

(new NumericType())->validate(1200);

Failure reasons

  • Numeric.NumericType when the value is not a numeric type

Positive

Validates the input (numeric) to be a positive value. A value is being considered positive when it is greater than or equal to zero (0).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\Positive;

(new Positive())->validate(1);

Failure reasons

  • Numeric.NumericType when the value is not a numeric type
  • Numeric.Positive when the value is greater than or equal to zero

Range

Validates the input (numeric) to be within the defined range (numeric, numeric) inclusive.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Numeric\Range;

(new Range(10, 200))->validate(38);

Failure reasons

  • Numeric.NumericType when the value is not a numeric type
  • Numeric.Minimum when the value is smaller than minimum
  • Numeric.Maximum when the value is greater than maximum