~ubuntu-branches/ubuntu/maverick/mahara/maverick-updates

« back to all changes in this revision

Viewing changes to htdocs/lib/pieforms/pieform/rules/regex.php

  • Committer: Bazaar Package Importer
  • Author(s): Nigel McNie
  • Date: 2008-04-29 11:15:39 UTC
  • Revision ID: james.westby@ubuntu.com-20080429111539-b28eqkagavaub2zr
Tags: upstream-1.0.2
Import upstream version 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Pieforms: Advanced web forms made easy
 
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 * @package    pieform
 
20
 * @subpackage rule
 
21
 * @author     Nigel McNie <nigel@catalyst.net.nz>
 
22
 * @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
 * Returns whether the given field matches the specified regex.
 
29
 *
 
30
 * @param Pieform $form    The form the rule is being applied to
 
31
 * @param string  $value   The value to check
 
32
 * @param array   $element The element to check
 
33
 * @param string  $regex   The regular expression to use for the check
 
34
 * @return string        The error message, if there is something wrong with
 
35
 *                       the value.
 
36
 */
 
37
function pieform_rule_regex(Pieform $form, $value, $element, $regex) {/*{{{*/
 
38
    if (!preg_match($regex, $value)) {
 
39
        return $form->i18n('rule', 'regex', 'regex', $element);
 
40
    }
 
41
}/*}}}*/
 
42
 
 
43
function pieform_rule_regex_i18n() {/*{{{*/
 
44
    return array(
 
45
        'en.utf8' => array(
 
46
            'regex' => 'This field is not in valid form'
 
47
        ),
 
48
        'de.utf8' => array(
 
49
            'regex' => 'Das Feld hat keine zulässige Form'
 
50
        ),
 
51
        'fr.utf8' => array(
 
52
            'regex' => 'Ce champ n\'a pas une forme correcte'
 
53
        ),
 
54
    );
 
55
}/*}}}*/
 
56
 
 
57
?>