diff --git a/trunk/includes/class/class.LSformRule_password.php b/trunk/includes/class/class.LSformRule_password.php new file mode 100644 index 00000000..501792e6 --- /dev/null +++ b/trunk/includes/class/class.LSformRule_password.php @@ -0,0 +1,75 @@ + + */ +class LSformRule_password extends LSformRule { + + /** + * Vérification de la valeur. + * + * @param string $values Valeur à vérifier + * @param array $options Options de validation + * - 'minLength' : la longueur maximale + * - 'maxLength' : la longueur minimale + * - 'prohibitedValues' : Un tableau de valeurs interdites + * - 'regex' : une ou plusieurs expressions régulières + * devant matche + * @param object $formElement L'objet formElement attaché + * + * @return boolean true si la valeur est valide, false sinon + */ + function validate ($value,$options=array(),$formElement) { + if(isset($options['params']['maxLength'])) { + if (strlen($value)>$options['params']['maxLength']) + return; + } + + if(isset($options['params']['minLength'])) { + if (strlen($value)<$options['params']['minLength']) + return; + } + + if(isset($options['params']['regex'])) { + if (!is_array($options['params']['regex'])) { + $options['params']['regex']=array($options['params']['regex']); + } + foreach($options['params']['regex'] as $regex) { + if (!ereg($regex,$value)) + return; + } + } + + if(is_array($options['params']['prohibitedValues'])) { + if (in_array($value,$options['params']['prohibitedValues'])) + return; + } + + return true; + } + +} + +?>