2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
24 * Règle de validation d'expression régulière.
26 * @author Benjamin Renard <brenard@easter-eggs.com>
28 class LSformRule_regex extends LSformRule {
31 * Vérification de la valeur.
33 * @param string $values Valeur à vérifier
34 * @param array $options Options de validation :
35 * - Regex : $option['params']['regex'] ou $option
36 * @param object $formElement L'objet formElement attaché
38 * @return boolean true si la valeur est valide, false sinon
40 function validate($value,$option,$formElement) {
41 if (is_array($option)) {
42 if (isset($option['params']['regex'])) {
43 $regex=$option['params']['regex'];
46 LSerror :: addErrorCode('LSformRule_regex_01');
53 if (!preg_match($regex, $value)) {
64 LSerror :: defineError('LSformRule_regex_01',
65 _("LSformRule_regex : Regex has not been configured to validate data.")