BaseValidator
API reference › HTML Helper › Base › BaseValidator
1 subclass
Provides reusable validation helpers for numeric and allow-list checks.
Enum for enum normalization during allow-list validation.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
intLike() static | Validates whether a value is an integer or an integer-like string within a specified range. | BaseValidator |
offsetLike() static | Validates whether a value represents an offset value. | BaseValidator |
oneOf() static | Validates that a value is one of the allowed options for an HTML attribute or tag argument. | BaseValidator |
positiveLike() static | Validates whether a value is a positive numeric value within a specified range. | BaseValidator |
Method details
Section titled “Method details”intLike()
Section titled “intLike() ”public static function intLike(int|string|Stringable $value, int|null $min = null, int|null $max = null): boolValidates whether a value is an integer or an integer-like string within a specified range.
Returns true only for non-empty integer input within bounds.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int|Stringable | Value to validate as integer-like. |
$min | int| | Minimum allowed value (inclusive). If null, minimum is zero. |
$max | int| | Optional maximum allowed value (inclusive). If null, no upper bound is enforced. |
Returns
bool: true if the value is integer-like and within bounds, false otherwise.
offsetLike()
Section titled “offsetLike() ”public static function offsetLike(float|int|string|Stringable $value): boolValidates whether a value represents an offset value.
If the value is a string that ends with ’%’, the numeric part is validated as a non-negative number not greater than ‘100’. Otherwise, the value is validated as a non-negative number not greater than ‘1’.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float|Stringable | Value to validate. |
Returns
bool: true if the value matches the accepted format and bounds, false otherwise.
oneOf()
Section titled “oneOf() ”public static function oneOf(int|string|Stringable|UnitEnum|null $value, list<scalar|UnitEnum|null> $allowed, string|UnitEnum $argumentName = 'value'): voidValidates that a value is one of the allowed options for an HTML attribute or tag argument.
Normalizes the provided value and allowed list, and checks strict membership. If the value is empty or null,
validation passes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int|Stringable|UnitEnum| | Value to validate. |
$allowed | list<scalar|UnitEnum| | List of allowed values for validation. |
$argumentName | string|UnitEnum | Argument name for error reporting (default: ‘value’). |
Throws
InvalidArgumentException: if the value is not in the allowed list.
positiveLike()
Section titled “positiveLike() ”public static function positiveLike(float|int|string|Stringable $value, float|null $min = null, float|null $max = null): boolValidates whether a value is a positive numeric value within a specified range.
Returns true only for non-negative numeric input within bounds.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float|Stringable | Value to validate as positive numeric. |
$min | float| | Minimum allowed value (inclusive). Defaults to ‘0.0’. If provided and less than ‘0.0’, it is forced to ‘0.0’. The value must be greater than or equal to this bound. |
$max | float| | Optional maximum allowed value (inclusive). If null, no upper bound is enforced. |
Returns
bool: true if the value is non-negative numeric and within bounds, false otherwise.