PHP Luminova: Validating Common Value Formats
Check deterministic identifiers, email addresses, URLs, phone values, binary data, check digits, integers, and geographic coordinates.
Use these static checks when working with an individual value. For complete request validation and field errors, see Input Validation. A format check cannot establish that an email address, phone number, or URL is reachable.
Usage
use Luminova\Utility\Validator;
$email = '[email protected]';
var_dump(Validator::isEmail($email)); // bool(true)
$valid = Validator::isLatLng('3.1390', '101.6869', strict: true, precision: 4);
var_dump($valid); // bool(true)Class Definition
- Full namespace:
Luminova\Utility\Validator - This class is final.
Methods
isIdentifier
Check the identifier format, regenerate it, and compare with hash_equals(). Pass the same algorithm, length, and grouping options used to generate the identifier. This method defaults to xxh128, while Random::identifier() defaults to sha256.
public static function isIdentifier(
string $from,
string $identifier,
int $length = 23,
int $group = 5,
string $algo = 'xxh128'
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$from | string | Original source value. |
$identifier | string | Identifier to verify. |
$length | int | Requested identifier length (default: 23). |
$group | int | Group size (default: 5). |
$algo | string | Hash algorithm (default: 'xxh128'). |
Return:
bool - Whether the identifier matches.
Throws:
- Luminova\Exceptions\InvalidArgumentException if regeneration receives an invalid identifier length or an unsupported hash algorithm.
Examples:
use Luminova\Utility\Random;
use Luminova\Utility\Validator;
$id = Random::identifier('order-1001', algo: 'sha256');
var_dump(Validator::isIdentifier('order-1001', $id, algo: 'sha256')); // bool(true)isEmail
Checks if string is a valid email address, with optional support for internationalized domains.
public static function isEmail(
mixed $email,
array $rejectDomains = [],
bool $allowIdn = false
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$email | mixed | Email address to validate. |
$rejectDomains | array<int\|string,mixed> | List of domains to reject (e.g. ['example.com']) (default: []). |
$allowIdn | bool | Allow internationalized domains (default: false). |
Return:
bool - Returns true if valid email address, false otherwise.
isUrl
Checks if the string is a valid URL, with optional support for internationalized domains.
public static function isUrl(mixed $url, bool $allowIdn = false, bool $httpOnly = false): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$url | mixed | The URL to validate. |
$allowIdn | bool | Whether to allow internationalized domain names (default: false). |
$httpOnly | bool | Restrict to http/https schemes only (default: false). |
Return:
bool - True if valid URL, otherwise false.
isPhone
Validates if the input is a valid phone number.
public static function isPhone(mixed $phone, int $min = 10, int $max = 15): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$phone | mixed | The phone number to validate. |
$min | int | The minimum allowed length (default: 10). |
$max | int | The maximum allowed length (default: 15). |
Return:
bool - Returns true if valid phone number, false otherwise.
isBinary
Determines if the content string is likely a binary based on the presence of non-printable characters.
public static function isBinary(mixed $data): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$data | mixed | The string or resource to check for binary. |
Return:
bool - Return true if it's a binary, false otherwise.
isValidCheckDigit
Check the final digit of a barcode or the trailing two characters of a GMN. The barcode check uses the same weighting as Random, so it can differ from standard EAN-13 or UPC-A validation.
public static function isValidCheckDigit(string $code, ?string $type = null): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | string | Code including its check digit or characters. |
$type | string\|null | Type such as ean, ean-13, upc, upc-a, barcode, or gmn. Pass null for a generic barcode (default: null). |
Return:
bool - Whether the format and computed check value match.
isBigInteger
Check a decimal integer against inclusive string bounds. With no bounds, the comparison uses the unsigned 64-bit range. Pass a string for values larger than PHP’s integer range.
public static function isBigInteger(
mixed $input,
?string $min = null,
?string $max = null
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$input | mixed | Candidate integer value. |
$min | string\|null | Lower bound. Uses zero when omitted (default: null). |
$max | string\|null | Upper bound. Uses the unsigned 64-bit maximum when omitted (default: null). |
Return:
bool - Whether the value passes format and range checks.
isLat
Check a latitude from −90 to 90 degrees.
public static function isLat(mixed $lat, bool $strict = false, ?int $precision = null): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$lat | mixed | Latitude value. |
$strict | bool | Whether to enforce decimal notation and precision (default: false). |
$precision | int\|null | Maximum decimal places when strict mode is enabled (default: null). |
Return:
bool - Whether the latitude passes the selected checks.
isLng
Check a longitude from −180 to 180 degrees.
public static function isLng(mixed $lng, bool $strict = false, ?int $precision = null): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$lng | mixed | Longitude value. |
$strict | bool | Whether to enforce decimal notation and precision (default: false). |
$precision | int\|null | Maximum decimal places when strict mode is enabled (default: null). |
Return:
bool - Whether the longitude passes the selected checks.
isLatLng
Run both coordinate checks with the same strictness and precision.
public static function isLatLng(
mixed $lat,
mixed $lng,
bool $strict = false,
?int $precision = null
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$lat | mixed | Latitude value. |
$lng | mixed | Longitude value. |
$strict | bool | Whether to enforce decimal notation and precision (default: false). |
$precision | int\|null | Maximum decimal places when strict mode is enabled (default: null). |
Return:
bool - Whether both coordinates pass.