Email
in package
implements
ValidationRule
Class Email
This class implements the ValidationRule interface to provide validation logic for email addresses.
Table of Contents
Interfaces
- ValidationRule
- Interface ValidationRule
Methods
- message() : string
- Returns the validation error message.
- validate() : bool
- Validates an email address based on its structure.
- hasCorrectParts() : array<string|int, mixed>
- Splits a string by a specified separator and checks if the resulting parts meet the required count.
Methods
message()
Returns the validation error message.
public
message() : string
Tags
Return values
string —The error message indicating the field must be a number.
validate()
Validates an email address based on its structure.
public
validate(string $field, array<string|int, mixed> $data) : bool
This method checks if the provided email address exists in the given data array and validates its format by ensuring it has the correct parts (username, domain, and top-level domain). The email is first trimmed and converted to lowercase before validation.
Parameters
- $field : string
-
The key in the data array that contains the email address.
- $data : array<string|int, mixed>
-
The array of data containing the email address to validate.
Return values
bool —Returns true if the email address is valid, otherwise false.
hasCorrectParts()
Splits a string by a specified separator and checks if the resulting parts meet the required count.
private
hasCorrectParts(string $separator, string $value[, int $length = 2 ]) : array<string|int, mixed>
Parameters
- $separator : string
-
The character used to split the string.
- $value : string
-
The string to be split.
- $length : int = 2
-
The minimum number of parts required after splitting. Default is 2.
Return values
array<string|int, mixed> —Returns an array where the first element is a boolean indicating whether the number of parts is greater than or equal to the required length, and the second element is the array of split parts.