You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.3 KiB
108 lines
3.3 KiB
<?php
|
|
|
|
namespace Config;
|
|
|
|
class Validate
|
|
{
|
|
/**
|
|
* Valide une adresse e-mail en utilisant la fonction filter_var() de PHP et une
|
|
* longueur maximale définie globalement.
|
|
*
|
|
* @param string $email L'adresse e-mail à valider.
|
|
* @return bool Vrai si l'adresse e-mail est valide et respecte la longueur maximale définie, faux sinon.
|
|
*/
|
|
|
|
public static function email(String $email): bool
|
|
{
|
|
global $emailMaxLength;
|
|
return (filter_var($email, FILTER_VALIDATE_EMAIL) && strlen($email) <= $emailMaxLength);
|
|
}
|
|
|
|
/**
|
|
* Valide un pseudo en vérifiant que la longueur est suffisante, qu'il contient uniquement des
|
|
* caractères alphanumériques, et qu'il respecte la longueur maximale définie globalement.
|
|
*
|
|
* @param string $pseudo Le pseudo à valider.
|
|
* @return bool Vrai si le pseudo est valide, faux sinon.
|
|
*/
|
|
|
|
public static function login(string $login) : bool
|
|
{
|
|
global $loginMaxLength;
|
|
return (strlen($login) >= 3 && preg_match("#[a-zA-Z0-9]+#", $login) && strlen($login) <= $loginMaxLength);
|
|
}
|
|
|
|
/**
|
|
* Valide un mot de passe en vérifiant que la longueur est suffisante, qu'il contient au moins un chiffre
|
|
* et une lettre, et qu'il respecte la longueur maximale définie globalement.
|
|
*
|
|
* @param string $password Le mot de passe à valider.
|
|
* @return bool Vrai si le mot de passe est valide, faux sinon.
|
|
*/
|
|
|
|
public static function password(string $password) : bool
|
|
{
|
|
global $passwordMaxLength;
|
|
return (strlen($password) >= 8 && strlen($password) <=$passwordMaxLength &&
|
|
preg_match("/\d/", $password) && preg_match("#[a-zA-Z]+#", $password));
|
|
}
|
|
|
|
/**
|
|
* Vérifie si le mot-clé est valide.
|
|
*
|
|
* @param string $keyword Le mot-clé a vérifié.
|
|
* @return bool Vrai si le mot-clé est valide, faux sinon.
|
|
*/
|
|
|
|
public static function keyWord(string $keyword) : bool
|
|
{
|
|
global $keyWordMaxLength;
|
|
return (strlen($keyword) <= $keyWordMaxLength && strlen($keyword) >= 3);
|
|
}
|
|
|
|
/**
|
|
* Vérifie si le titre est valide.
|
|
*
|
|
* @param string $title Le titre a vérifié.
|
|
* @return bool Vrai si le titre est valide, faux sinon.
|
|
*/
|
|
|
|
public static function title(string $title) : bool
|
|
{
|
|
global $titleMaxLength;
|
|
return (strlen($title) <= $titleMaxLength && strlen($title) >= 3);
|
|
}
|
|
|
|
/**
|
|
* Vérifie si le type est valide.
|
|
*
|
|
* @param string $type Le type a vérifié.
|
|
* @return bool Vrai si le type est valide, faux sinon.
|
|
*/
|
|
|
|
public static function type(string $type) : bool
|
|
{
|
|
global $typeMaxLength;
|
|
return (strlen($type) <= $typeMaxLength && strlen($type) >=3);
|
|
}
|
|
|
|
/**
|
|
* Vérifie si la réponse est valide.
|
|
*
|
|
* @param string $response La réponse a vérifié.
|
|
* @return bool Vrai si la réponse est valide, faux sinon.
|
|
*/
|
|
|
|
public static function response(string $response) : bool
|
|
{
|
|
global $responseMaxLength;
|
|
return (strlen($response) <= $responseMaxLength);
|
|
}
|
|
public static function username(string $username): bool
|
|
{
|
|
global $usernameMaxLength;
|
|
return (strlen($username) >= 3 && preg_match("#[a-zA-Z0-9]+#", $username) && strlen($username) <= $usernameMaxLength);
|
|
}
|
|
|
|
}
|