Validation rules: required, email, length and more, plus check() to collect errors.

V:: Phlat\Toolkit\V 23 methods

Presence 2

  • required True if the value is non-empty (not null, not empty string, not empty array).
  • blank True if the value is null or empty string (opposite of required).

Format 12

  • email Whether the value is a valid email address.
  • url Whether the value is a valid URL.
  • slug A page path segment: lowercase letters and digits, single hyphens between them.
  • filename A file name: a slug stem plus one or more extensions - photo.jpg, htmx.min.js.
  • variant A variant of a file, as PageImage names it: the file's stem, `~`, a slug or hash, and the extension - photo~card.jpg.
  • numeric Whether the value is a number or numeric string.
  • integer Whether the value is an integer or an integer string.
  • alpha Whether the value holds only letters.
  • alphanumeric Whether the value holds only letters and digits.
  • date Whether the value parses as a date.
  • match True if $value matches the regex $pattern.
  • allowedExtension True if $filename's extension is in the $allowed list (case-insensitive, no leading dot).

Length 2

  • minLength Whether the value has at least $min characters.
  • maxLength Whether the value has at most $max characters.

Range 3

  • min Whether the value is at least $min.
  • max Whether the value is at most $max.
  • between Whether the value is between $min and $max, inclusive.

Comparison 3

  • in True if $value is one of the allowed $options.
  • same True if $a and $b are identical - for password confirmation etc.
  • accepted True if the value is truthy - for checkbox/toggle fields.

Collector 1

  • check Runs a set of per-field rules and returns only the failing fields.

Presence

V::required(mixed $value): bool

True if the value is non-empty (not null, not empty string, not empty array).

Parameters (1)
$value mixed

Returns bool

phlat/src/Toolkit/V.php:17
V::blank(mixed $value): bool

True if the value is null or empty string (opposite of required).

Parameters (1)
$value mixed

Returns bool

phlat/src/Toolkit/V.php:25

Format

V::email(string $value): bool

Whether the value is a valid email address.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:33

url

V::url(string $value): bool

Whether the value is a valid URL.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:39
V::slug(string $value): bool

A page path segment: lowercase letters and digits, single hyphens between them.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:45
V::filename(string $value): bool

A file name: a slug stem plus one or more extensions - photo.jpg, htmx.min.js.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:51
V::variant(string $value): bool

A variant of a file, as PageImage names it: the file's stem, `~`, a slug or hash, and the extension - photo~card.jpg.

An author can't upload one: filename() has no ~.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:57
V::numeric(mixed $value): bool

Whether the value is a number or numeric string.

Parameters (1)
$value mixed

Returns bool

phlat/src/Toolkit/V.php:63
V::integer(mixed $value): bool

Whether the value is an integer or an integer string.

Parameters (1)
$value mixed

Returns bool

phlat/src/Toolkit/V.php:69
V::alpha(string $value): bool

Whether the value holds only letters.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:75
V::alphanumeric(string $value): bool

Whether the value holds only letters and digits.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:81
V::date(string $value): bool

Whether the value parses as a date.

Parameters (1)
$value string

Returns bool

phlat/src/Toolkit/V.php:87
V::match(string $value, string $pattern): bool

True if $value matches the regex $pattern.

Parameters (2)
$value string
$pattern string

Returns bool

phlat/src/Toolkit/V.php:93
V::allowedExtension(string $filename, array $allowed): bool

True if $filename's extension is in the $allowed list (case-insensitive, no leading dot).

Parameters (2)
$filename string
$allowed array

Returns bool

phlat/src/Toolkit/V.php:99

Length

V::minLength(string $value, int $min): bool

Whether the value has at least $min characters.

Parameters (2)
$value string
$min int

Returns bool

phlat/src/Toolkit/V.php:107
V::maxLength(string $value, int $max): bool

Whether the value has at most $max characters.

Parameters (2)
$value string
$max int

Returns bool

phlat/src/Toolkit/V.php:113

Range

min

V::min(int|float $value, int|float $min): bool

Whether the value is at least $min.

Parameters (2)
$value int|float
$min int|float

Returns bool

phlat/src/Toolkit/V.php:121

max

V::max(int|float $value, int|float $max): bool

Whether the value is at most $max.

Parameters (2)
$value int|float
$max int|float

Returns bool

phlat/src/Toolkit/V.php:127
V::between(int|float $value, int|float $min, int|float $max): bool

Whether the value is between $min and $max, inclusive.

Parameters (3)
$value int|float
$min int|float
$max int|float

Returns bool

phlat/src/Toolkit/V.php:133

Comparison

in

V::in(mixed $value, array $options): bool

True if $value is one of the allowed $options.

Parameters (2)
$value mixed
$options array

Returns bool

phlat/src/Toolkit/V.php:141
V::same(mixed $a, mixed $b): bool

True if $a and $b are identical - for password confirmation etc.

Parameters (2)
$a mixed
$b mixed

Returns bool

phlat/src/Toolkit/V.php:147
V::accepted(mixed $value): bool

True if the value is truthy - for checkbox/toggle fields.

Parameters (1)
$value mixed

Returns bool

phlat/src/Toolkit/V.php:153

Collector

V::check(array<string, array<array{bool, string}>> $rules): array<string, string>

Runs a set of per-field rules and returns only the failing fields.

Each field maps to an array of [bool $passes, string $message] pairs. Evaluation stops at the first failure per field.

Usage: $errors = V::check([ 'email' => [ [V::required($email), 'Required'], [V::email($email), 'Invalid email'], ], ]); if ($errors) throw new ValidationException($errors);

Parameters (1)
$rules array<string, array<array{bool, string}>>

Returns array<string, string>

phlat/src/Toolkit/V.php:180