NumberValidator
Use NumberValidator for quantities, ages, prices, scores, and other numeric fields.
Create a rule
Section titled “Create a rule”Rule::number(string $field): NumberValidatorMethods
Section titled “Methods”| Method | Description |
|---|---|
min(int|float $value) | Set the inclusive lower bound. |
max(int|float $value) | Set the inclusive upper bound. |
length(int $min, int $max) | Configure inherited length limits when needed. |
required(bool $required = true) | Mark the field as required. |
optional() | Allow a missing value. |
validate(mixed $value) | Return the first error or null. |
validateAll(mixed $value) | Return every applicable error. |
Example
Section titled “Example”use Fynix\Rule;
$validator = Rule::number('quantity') ->min(1) ->max(1000);
$errors = $validator->validateAll(0);Bounds must be finite numbers. Non-numeric input and values outside the configured range produce validation errors.