regex.php 2.45 KB
Newer Older
1
2
<?php
/**
3
4
 * Pieforms: Advanced web forms made easy
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
 *
6
7
8
9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
10
 *
11
12
13
14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
15
 *
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
21
22
 *
 * @package    pieform
 * @subpackage rule
 * @author     Nigel McNie <nigel@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
24
25
26
27
28
29
30
31
32
33
34
35
36
 *
 */

/**
 * Returns whether the given field matches the specified regex.
 *
 * @param Pieform $form    The form the rule is being applied to
 * @param string  $value   The value to check
 * @param array   $element The element to check
 * @param string  $regex   The regular expression to use for the check
 * @return string        The error message, if there is something wrong with
 *                       the value.
 */
37
function pieform_rule_regex(Pieform $form, $value, $element, $regex) {/*{{{*/
38
    if (!preg_match($regex, $value)) {
Nigel McNie's avatar
Nigel McNie committed
39
        return $form->i18n('rule', 'regex', 'regex', $element);
40
    }
41
}/*}}}*/
42

43
function pieform_rule_regex_i18n() {/*{{{*/
Nigel McNie's avatar
Nigel McNie committed
44
45
46
    return array(
        'en.utf8' => array(
            'regex' => 'This field is not in valid form'
47
        ),
48
        'de.utf8' => array(
49
50
            'regex' => 'Das Feld hat keine zulässige Form'
        ),
51
52
53
        'fr.utf8' => array(
            'regex' => 'Ce champ n\'a pas une forme correcte'
        ),
54
55
56
        'ja.utf8' => array(
            'regex' => 'このフィールドは正しい形式ではありません'
        ),
57
58
59
        'es.utf8' => array(
            'regex' => 'Este campo no tiene un formato válido'
        ),
60
61
62
        'sl.utf8' => array(
            'regex' => 'To polje ni v veljavni obliki'
        ),
63
64
65
        'nl.utf8' => array(
            'regex' => 'Dit veld is niet in een geldige vorm'
        ),
66
67
68
        'cs.utf8' => array(
            'regex' => 'Neplatný formát'
        ),
69

Nigel McNie's avatar
Nigel McNie committed
70
    );
71
}/*}}}*/
Nigel McNie's avatar
Nigel McNie committed
72

73
?>