# BaseValidator

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

[API reference](/docs/api/index.md) › [HTML Helper](/docs/extensions/html-helper/reference/index.md) › [Base](/docs/extensions/html-helper/reference/base/index.md) › BaseValidator

| abstract class | `UIAwesome\Html\Helper\Base\BaseValidator` |
| --- | --- |
| Source | [`src/Base/BaseValidator.php`](https://github.com/ui-awesome/html-helper/blob/main/src/Base/BaseValidator.php#L30) |

1 subclass:

- [`UIAwesome\Html\Helper\Validator`](/docs/extensions/html-helper/reference/validator/index.md)

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

[`Enum`](/docs/extensions/html-helper/reference/enum/index.md) for enum normalization during allow-list validation.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`intLike()`](#method-intLike) static | Validates whether a value is an integer or an integer-like string within a specified range. | `BaseValidator` |
| [`offsetLike()`](#method-offsetLike) static | Validates whether a value represents an offset value. | `BaseValidator` |
| [`oneOf()`](#method-oneOf) static | Validates that a value is one of the allowed options for an HTML attribute or tag argument. | `BaseValidator` |
| [`positiveLike()`](#method-positiveLike) static | Validates whether a value is a positive numeric value within a specified range. | `BaseValidator` |

## Method details

### intLike() <span id="method-intLike"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Value to validate as integer-like. |
| `$min` | `int\|null` | Minimum allowed value (inclusive). If `null`, minimum is zero. |
| `$max` | `int\|null` | 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() <span id="method-offsetLike"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Value to validate. |

**Returns**

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

### oneOf() <span id="method-oneOf"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Value to validate. |
| `$allowed` | `list<scalar\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null>` | List of allowed values for validation. |
| `$argumentName` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Argument name for error reporting (default: 'value'). |

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if the value is not in the allowed list.

### positiveLike() <span id="method-positiveLike"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Value to validate as positive numeric. |
| `$min` | `float\|null` | 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\|null` | 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.