[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / verifier / verifier / taille.php
1 <?php
2
3 // Sécurité
4 if (!defined("_ECRIRE_INC_VERSION")) return;
5
6 /**
7 * Vérifier une taille minimale/maximale, pour un mot de passe par exemple
8 *
9 * @param string $valeur
10 * La valeur à vérifier.
11 * @param array $options
12 * Les éléments à vérifier (min, max, egal).
13 * @return string
14 * Retourne une chaine vide si c'est valide, sinon une chaine expliquant l'erreur.
15 */
16
17 function verifier_taille_dist($valeur, $options=array()){
18 $ok = true;
19 if (!is_string($valeur))
20 return _T('erreur_inconnue_generique');
21
22 $erreur = '';
23
24 if (isset($options['min']))
25 $ok = ($ok and (strlen($valeur) >= $options['min']));
26
27 if (isset($options['max'])){
28 $ok = ($ok and (strlen($valeur) <= $options['max']));
29 }
30 if (isset($options['egal'])){
31 $ok = ($ok and (strlen($valeur) == $options['egal']));
32 }
33
34 if (!$ok){
35 if (isset($options['min']) and isset($options['max']))
36 $erreur = _T('verifier:erreur_taille_entre', $options);
37 elseif (isset($options['max']))
38 $erreur = _T('verifier:erreur_taille_max', $options);
39 elseif (isset($options['egal']))
40 $erreur = _T('verifier:erreur_taille_egal', $options);
41 else
42 $erreur = _T('verifier:erreur_taille_min', $options);
43 }
44
45 return $erreur;
46 }