Documentation

Validation
in package

FinalYes

Data validation utility class.

Provides validation methods for common data types including hostname, IP address, CIDR notation, email, port number, Unix username, and file paths.

Table of Contents

Methods

email()  : bool
Validate email address format.
hostname()  : bool
Validate hostname format.
hostname_or_ipaddress()  : bool
Validate hostname or IPv4 address format.
ipaddress()  : bool
Validate IPv4 address format.
ipaddress_or_cidr()  : bool
Validate IPv4 address or CIDR notation format.
is_path()  : bool
Validate Unix file or directory path format.
port()  : bool
Validate port number (0-65535).
unix_username()  : bool
Validate Unix username format.

Methods

email()

Validate email address format.

public static email(string $value) : bool

Uses the FormValidation.io library's regular expression for validation.

Parameters
$value : string

String to validate.

Return values
bool

True if valid email address.

hostname()

Validate hostname format.

public static hostname(string $value) : bool

Accepts standard domain names and "localhost".

Parameters
$value : string

String to validate.

Return values
bool

True if valid hostname.

hostname_or_ipaddress()

Validate hostname or IPv4 address format.

public static hostname_or_ipaddress(string $value) : bool
Parameters
$value : string

String to validate.

Return values
bool

True if valid hostname or IPv4 address.

ipaddress()

Validate IPv4 address format.

public static ipaddress(string $value) : bool
Parameters
$value : string

String to validate.

Return values
bool

True if valid IPv4 address.

ipaddress_or_cidr()

Validate IPv4 address or CIDR notation format.

public static ipaddress_or_cidr(string $value) : bool
Parameters
$value : string

String to validate (e.g., "192.168.1.0" or "192.168.1.0/24").

Return values
bool

True if valid IPv4 address or CIDR notation.

is_path()

Validate Unix file or directory path format.

public static is_path(string $value[, bool $denyLeadingSlash = false ]) : bool
Parameters
$value : string

String to validate.

$denyLeadingSlash : bool = false

Reject paths starting with "/". Default is false.

Return values
bool

True if valid path.

port()

Validate port number (0-65535).

public static port(string $value) : bool
Parameters
$value : string

String to validate.

Return values
bool

True if valid port number.

unix_username()

Validate Unix username format.

public static unix_username(string $value) : bool

Must start with lowercase letter or underscore, followed by up to 31 lowercase alphanumeric chars, hyphens, or underscores.

Parameters
$value : string

String to validate.

Return values
bool

True if valid Unix username.


        
On this page

Search results