Documentation

Validation
in package

Validation Class

The Validation class provides functions for common data validation tasks.

Table of Contents

Methods

isCustom()  : bool
Custom validation function.
isDate()  : bool
Validate a date.
isEmail()  : bool
Validate an email address.
isEmpty()  : bool
isEmpty Validation Function
isFileExtension()  : bool
Validate file extension.
isName()  : bool
Validate a name.
isNumeric()  : bool
Validate a numeric value.
isPhoneNumber()  : bool
Validate a phone number.
isStrongPassword()  : bool
Validate password strength.
isUrl()  : bool
Validate a URL.

Methods

isCustom()

Custom validation function.

public static isCustom(mixed $value, callable $customFunction) : bool
Parameters
$value : mixed

The value to validate.

$customFunction : callable

The custom validation function.

Return values
bool

True if the custom validation passes; otherwise, false.

isDate()

Validate a date.

public static isDate(string $date[, string $format = 'Y-m-d' ]) : bool
Parameters
$date : string

The date to validate.

$format : string = 'Y-m-d'

(Optional) Date format to check against.

Return values
bool

True if the date is valid; otherwise, false.

isEmail()

Validate an email address.

public static isEmail(string $email) : bool
Parameters
$email : string

The email address to validate.

Return values
bool

True if the email is valid; otherwise, false.

isEmpty()

isEmpty Validation Function

public static isEmpty(mixed $value) : bool

This function checks if a given value is empty. An empty value is considered:

  • An empty string ('')
  • A string containing only whitespace characters (e.g., ' ', '\t', '\n')
  • null
  • An empty array ([])
Parameters
$value : mixed

The value to validate.

Return values
bool

True if the value is empty, false otherwise.

isFileExtension()

Validate file extension.

public static isFileExtension(string $fileName, array<string|int, mixed> $allowedExtensions) : bool
Parameters
$fileName : string

The name of the file to validate.

$allowedExtensions : array<string|int, mixed>

An array of allowed file extensions.

Return values
bool

True if the file extension is valid; otherwise, false.

isName()

Validate a name.

public static isName(string $name[, int $minLength = 2 ][, int $maxLength = 50 ]) : bool
Parameters
$name : string

The name to validate.

$minLength : int = 2

(Optional) Minimum name length.

$maxLength : int = 50

(Optional) Maximum name length.

Return values
bool

True if the name is valid; otherwise, false.

isNumeric()

Validate a numeric value.

public static isNumeric(mixed $number) : bool
Parameters
$number : mixed

The value to validate.

Return values
bool

True if the value is numeric; otherwise, false.

isPhoneNumber()

Validate a phone number.

public static isPhoneNumber(string $phoneNumber) : bool
Parameters
$phoneNumber : string

The phone number to validate.

Return values
bool

True if the phone number is valid; otherwise, false.

isStrongPassword()

Validate password strength.

public static isStrongPassword(string $password) : bool
Parameters
$password : string

The password to validate.

Return values
bool

True if the password is strong; otherwise, false.

isUrl()

Validate a URL.

public static isUrl(string $url) : bool
Parameters
$url : string

The URL to validate.

Return values
bool

True if the URL is valid; otherwise, false.


        
On this page

Search results