Validator
in package
Permite validar distintos tipos de datos.
Table of Contents
Methods
- alphaNumeric() : bool
- Devuelve true si $text contiene solamente números, letras y los caracteres $extra.
- date() : bool
- Valída una fecha en formato ESTRICTO 'd-m-Y' o 'Y-m-d' Ejemplos válidos: "31-12-2023", "01-01-2024", "2023-12-31", "2024-01-01"
- datetime() : bool
- Valída fecha y hora con: - Fecha ESTRICTA en formato 'd-m-Y' o 'Y-m-d' - Tiempo en formato 'H:i:s' O 'H:i' - Separador: espacio o T (ISO 8601)
- email() : bool
- Devuelve true si el email es válido
- hour() : bool
- Valída un tiempo en formato 'H:i:s' o 'H:i'
- string() : bool
- Devuelve true si la cadena tiene entre $min y $max caracteres
- url() : bool
- Devuelve true si la $url es válida.
Methods
alphaNumeric()
Devuelve true si $text contiene solamente números, letras y los caracteres $extra.
public
static alphaNumeric(string $text[, string $extra = '' ][, int $min = 1 ][, int $max = 99 ]) : bool
También comprueba si la longitud de $text está entre $min y $max.
Parameters
- $text : string
- $extra : string = ''
- $min : int = 1
- $max : int = 99
Return values
booldate()
Valída una fecha en formato ESTRICTO 'd-m-Y' o 'Y-m-d' Ejemplos válidos: "31-12-2023", "01-01-2024", "2023-12-31", "2024-01-01"
public
static date(string $date) : bool
Parameters
- $date : string
-
Fecha a validar (formatos: 'd-m-Y' o 'Y-m-d')
Return values
bool —True si es válida y tiene el formato correcto
datetime()
Valída fecha y hora con: - Fecha ESTRICTA en formato 'd-m-Y' o 'Y-m-d' - Tiempo en formato 'H:i:s' O 'H:i' - Separador: espacio o T (ISO 8601)
public
static datetime(string $datetime) : bool
Ejemplos válidos: "31-12-2023 23:59:59", "01-01-2024 00:00", "15-06-2023 14:30" "2023-12-31 23:59:59", "2024-01-01 00:00", "2023-06-15 14:30" "2023-12-31T23:59:59", "2024-01-01T00:00", "2023-06-15T14:30"
Parameters
- $datetime : string
-
Fecha y hora a validar
Return values
bool —True si es válido y tiene el formato correcto
email()
Devuelve true si el email es válido
public
static email(string $email) : bool
Parameters
- $email : string
Return values
boolhour()
Valída un tiempo en formato 'H:i:s' o 'H:i'
public
static hour(string $time) : bool
Parameters
- $time : string
-
Tiempo a validar
Return values
bool —True si es válido
string()
Devuelve true si la cadena tiene entre $min y $max caracteres
public
static string(string $text[, int $min = 1 ][, int $max = 99 ]) : bool
Parameters
- $text : string
- $min : int = 1
- $max : int = 99
Return values
boolurl()
Devuelve true si la $url es válida.
public
static url(string $url[, bool $strict = false ]) : bool
Si $strict es true, entonces la url debe comenzar por http, https o cualquier otro protocolo válido.
Parameters
- $url : string
- $strict : bool = false