Skip to content
PHP Ecosystem
Explore

BaseValidator

API reference › HTML Helper › Base › BaseValidator

abstract classUIAwesome\Html\Helper\Base\BaseValidator
Sourcesrc/Base/BaseValidator.php
1 subclass

Provides reusable validation helpers for numeric and allow-list checks.

Enum for enum normalization during allow-list validation.

MethodDescriptionDefined by
intLike() staticValidates whether a value is an integer or an integer-like string within a specified range.BaseValidator
offsetLike() staticValidates whether a value represents an offset value.BaseValidator
oneOf() staticValidates that a value is one of the allowed options for an HTML attribute or tag argument.BaseValidator
positiveLike() staticValidates whether a value is a positive numeric value within a specified range.BaseValidator
public static function intLike(int|string|Stringable $value, int|null $min = null, int|null $max = null): bool

Validates 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

ParameterTypeDescription
$valueint|string|StringableValue to validate as integer-like.
$minint|nullMinimum allowed value (inclusive). If null, minimum is zero.
$maxint|nullOptional 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.

public static function offsetLike(float|int|string|Stringable $value): bool

Validates 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

ParameterTypeDescription
$valuefloat|int|string|StringableValue to validate.

Returns

bool: true if the value matches the accepted format and bounds, false otherwise.

public static function oneOf(int|string|Stringable|UnitEnum|null $value, list<scalar|UnitEnum|null> $allowed, string|UnitEnum $argumentName = 'value'): void

Validates 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

ParameterTypeDescription
$valueint|string|Stringable|UnitEnum|nullValue to validate.
$allowedlist<scalar|UnitEnum|null>List of allowed values for validation.
$argumentNamestring|UnitEnumArgument name for error reporting (default: ‘value’).

Throws

public static function positiveLike(float|int|string|Stringable $value, float|null $min = null, float|null $max = null): bool

Validates whether a value is a positive numeric value within a specified range.

Returns true only for non-negative numeric input within bounds.

Parameters

ParameterTypeDescription
$valuefloat|int|string|StringableValue to validate as positive numeric.
$minfloat|nullMinimum 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.
$maxfloat|nullOptional 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.