4 if (!defined("_ECRIRE_INC_VERSION")) return;
7 * Vérifier une taille minimale/maximale, pour un mot de passe par exemple
9 * @param string $valeur
10 * La valeur à vérifier.
11 * @param array $options
12 * Les éléments à vérifier (min, max, egal).
14 * Retourne une chaine vide si c'est valide, sinon une chaine expliquant l'erreur.
17 function verifier_taille_dist($valeur, $options=array()){
19 if (!is_string($valeur))
20 return _T('erreur_inconnue_generique');
22 include_spip('inc/charsets');
24 $taille = spip_strlen($valeur);
26 if (isset($options['min']))
27 $ok = ($ok and ($taille >= $options['min']));
29 if (isset($options['max'])){
30 $ok = ($ok and ($taille <= $options['max']));
32 if (isset($options['egal'])){
33 $ok = ($ok and ($taille == $options['egal']));
37 // On ajoute la taille actuelle aux valeurs de remplacement
38 $options['nb'] = $taille;
39 if (isset($options['min']) and isset($options['max']))
40 $erreur = _T('verifier:erreur_taille_entre', $options);
41 elseif (isset($options['max']))
42 $erreur = _T('verifier:erreur_taille_max', $options);
43 elseif (isset($options['egal']))
44 $erreur = _T('verifier:erreur_taille_egal', $options);
46 $erreur = _T('verifier:erreur_taille_min', $options);