Validate
in package
Static utility class for validation without throwing exceptions.
The Validate class provides boolean validation methods that return true/false rather than throwing exceptions. These methods are used by the Parse class to check validity before conversion. All methods are static and the class is marked final to prevent extension.
Table of Contents
Methods
- arrayKey() : bool
- Validates that a key exists in an associative array.
- arrayValue() : bool
- Validates that a value exists in an array.
- bool() : bool
- Validates if a string can be parsed as a boolean.
- currency() : bool
- Validates if a string can be parsed as a currency amount.
- dateTime() : bool
- Validates if a string can be parsed as a date-time.
- emailAddress() : bool
- Validates if a string is a valid email address.
- emailUsername() : bool
- Validates if a string is a valid email username (local part).
- existingDirectory() : bool
- Validates if a path is an existing directory.
- existingFilename() : bool
- Validates if a path is an existing file or directory.
- float() : bool
- Validates if a string can be parsed as a floating-point number.
- floatRangeClosed() : bool
- Validates if a string is a float within a closed range (exclusive bounds).
- floatRangeHalfClosed() : bool
- Validates if a string is a float within a half-closed range [min, max).
- floatRangeOpen() : bool
- Validates if a string is a float within an open range [min, max].
- hostname() : bool
- Validates if a string is a valid hostname.
- int() : bool
- Validates if a string can be parsed as an integer.
- intRangeClosed() : bool
- Validates if a string is an integer within a closed range (exclusive bounds).
- intRangeHalfClosed() : bool
- Validates if a string is an integer within a half-closed range [min, max).
- intRangeOpen() : bool
- Validates if a string is an integer within an open range [min, max].
- ip() : bool
- Validates if a string is a valid IP address (IPv4 or IPv6).
- ipv4() : bool
- Validates if a string is a valid IPv4 address.
- ipv6() : bool
- Validates if a string is a valid IPv6 address.
- nonexistentFilename() : bool
- Validates that a filename path does not exist.
- positiveFloat() : bool
- Validates if a string is a positive floating-point number (> 0).
- positiveInt() : bool
- Validates if a string is a positive integer (> 0).
- unsignedFloat() : bool
- Validates if a string is a non-negative floating-point number (>= 0).
- unsignedInt() : bool
- Validates if a string is a non-negative integer (>= 0).
Methods
arrayKey()
Validates that a key exists in an associative array.
public
static arrayKey(string $i_stKey, array<string, mixed> $i_r) : bool
Parameters
- $i_stKey : string
-
The key to check for
- $i_r : array<string, mixed>
-
The array to search
Return values
bool —True if the key exists, false otherwise
arrayValue()
Validates that a value exists in an array.
public
static arrayValue(string $i_stValue, array<int|string, string> $i_r) : bool
Parameters
- $i_stValue : string
-
The value to search for
- $i_r : array<int|string, string>
-
The array of values to search
Return values
bool —True if the value exists in the array, false otherwise
bool()
Validates if a string can be parsed as a boolean.
public
static bool(string $i_stBool) : bool
Accepts numeric values and text values like 'true', 'yes', 'on', 'false', 'no', 'off' (case-insensitive).
Parameters
- $i_stBool : string
-
The string to validate
Return values
bool —True if the string can be parsed as a boolean, false otherwise
currency()
Validates if a string can be parsed as a currency amount.
public
static currency(string $i_stCurrency) : bool
Parameters
- $i_stCurrency : string
-
The string to validate
Return values
bool —True if the string can be parsed as currency, false otherwise
dateTime()
Validates if a string can be parsed as a date-time.
public
static dateTime(string $i_stDate) : bool
Parameters
- $i_stDate : string
-
The string to validate
Return values
bool —True if the string can be parsed as a date-time, false otherwise
emailAddress()
Validates if a string is a valid email address.
public
static emailAddress(string $i_stEmail) : bool
Parameters
- $i_stEmail : string
-
The string to validate
Return values
bool —True if the string is a valid email address, false otherwise
emailUsername()
Validates if a string is a valid email username (local part).
public
static emailUsername(string $i_stUsername) : bool
Parameters
- $i_stUsername : string
-
The string to validate
Return values
bool —True if the string is a valid email username, false otherwise
existingDirectory()
Validates if a path is an existing directory.
public
static existingDirectory(string $i_stDir) : bool
Parameters
- $i_stDir : string
-
The path to validate
Return values
bool —True if the path is an existing directory, false otherwise
existingFilename()
Validates if a path is an existing file or directory.
public
static existingFilename(string $i_stFile) : bool
Parameters
- $i_stFile : string
-
The path to validate
Return values
bool —True if the path exists, false otherwise
float()
Validates if a string can be parsed as a floating-point number.
public
static float(string $i_stFloat) : bool
Parameters
- $i_stFloat : string
-
The string to validate
Return values
bool —True if the string is numeric, false otherwise
floatRangeClosed()
Validates if a string is a float within a closed range (exclusive bounds).
public
static floatRangeClosed(string $i_stFloat, float $i_fMin, float $i_fMax) : bool
Parameters
- $i_stFloat : string
-
The string to validate
- $i_fMin : float
-
The minimum value (exclusive)
- $i_fMax : float
-
The maximum value (exclusive)
Return values
bool —True if the string is a valid float within the range, false otherwise
floatRangeHalfClosed()
Validates if a string is a float within a half-closed range [min, max).
public
static floatRangeHalfClosed(string $i_stFloat, float $i_fMin, float $i_fMax) : bool
Parameters
- $i_stFloat : string
-
The string to validate
- $i_fMin : float
-
The minimum value (inclusive)
- $i_fMax : float
-
The maximum value (exclusive)
Return values
bool —True if the string is a valid float within the range, false otherwise
floatRangeOpen()
Validates if a string is a float within an open range [min, max].
public
static floatRangeOpen(string $i_stFloat, float $i_fMin, float $i_fMax) : bool
Parameters
- $i_stFloat : string
-
The string to validate
- $i_fMin : float
-
The minimum value (inclusive)
- $i_fMax : float
-
The maximum value (inclusive)
Return values
bool —True if the string is a valid float within the range, false otherwise
hostname()
Validates if a string is a valid hostname.
public
static hostname(string $i_stHost) : bool
Requires at least one dot and rejects hostnames ending with a dot.
Parameters
- $i_stHost : string
-
The string to validate
Return values
bool —True if the string is a valid hostname, false otherwise
int()
Validates if a string can be parsed as an integer.
public
static int(string $i_stInt) : bool
Parameters
- $i_stInt : string
-
The string to validate
Return values
bool —True if the string is numeric, false otherwise
intRangeClosed()
Validates if a string is an integer within a closed range (exclusive bounds).
public
static intRangeClosed(string $i_stInt, int $i_nuMin, int $i_nuMax) : bool
Parameters
- $i_stInt : string
-
The string to validate
- $i_nuMin : int
-
The minimum value (exclusive)
- $i_nuMax : int
-
The maximum value (exclusive)
Return values
bool —True if the string is a valid integer within the range, false otherwise
intRangeHalfClosed()
Validates if a string is an integer within a half-closed range [min, max).
public
static intRangeHalfClosed(string $i_stInt, int $i_nuMin, int $i_nuMax) : bool
Parameters
- $i_stInt : string
-
The string to validate
- $i_nuMin : int
-
The minimum value (inclusive)
- $i_nuMax : int
-
The maximum value (exclusive)
Return values
bool —True if the string is a valid integer within the range, false otherwise
intRangeOpen()
Validates if a string is an integer within an open range [min, max].
public
static intRangeOpen(string $i_stInt, int $i_nuMin, int $i_nuMax) : bool
Parameters
- $i_stInt : string
-
The string to validate
- $i_nuMin : int
-
The minimum value (inclusive)
- $i_nuMax : int
-
The maximum value (inclusive)
Return values
bool —True if the string is a valid integer within the range, false otherwise
ip()
Validates if a string is a valid IP address (IPv4 or IPv6).
public
static ip(string $i_stIP) : bool
Parameters
- $i_stIP : string
-
The string to validate
Return values
bool —True if the string is a valid IP address, false otherwise
ipv4()
Validates if a string is a valid IPv4 address.
public
static ipv4(string $i_stIP) : bool
Parameters
- $i_stIP : string
-
The string to validate
Return values
bool —True if the string is a valid IPv4 address, false otherwise
ipv6()
Validates if a string is a valid IPv6 address.
public
static ipv6(string $i_stIP) : bool
Parameters
- $i_stIP : string
-
The string to validate
Return values
bool —True if the string is a valid IPv6 address, false otherwise
nonexistentFilename()
Validates that a filename path does not exist.
public
static nonexistentFilename(string $i_stFile) : bool
Also validates that the parent directory exists if specified.
Parameters
- $i_stFile : string
-
The file path to validate
Return values
bool —True if the file does not exist and parent directory is valid, false otherwise
positiveFloat()
Validates if a string is a positive floating-point number (> 0).
public
static positiveFloat(string $i_stFloat) : bool
Parameters
- $i_stFloat : string
-
The string to validate
Return values
bool —True if the string is a positive float, false otherwise
positiveInt()
Validates if a string is a positive integer (> 0).
public
static positiveInt(string $i_stInt) : bool
Parameters
- $i_stInt : string
-
The string to validate
Return values
bool —True if the string is a positive integer, false otherwise
unsignedFloat()
Validates if a string is a non-negative floating-point number (>= 0).
public
static unsignedFloat(string $i_stInt) : bool
Parameters
- $i_stInt : string
-
The string to validate
Return values
bool —True if the string is a non-negative float, false otherwise
unsignedInt()
Validates if a string is a non-negative integer (>= 0).
public
static unsignedInt(string $i_stInt) : bool
Parameters
- $i_stInt : string
-
The string to validate
Return values
bool —True if the string is a non-negative integer, false otherwise