Commit b890ee4e authored by Penny Leach's avatar Penny Leach
Browse files

form: added integer validation rule

parent 21c8227c
......@@ -209,7 +209,8 @@ class Form {
'email' => 'E-mail address is invalid',
'maxlength' => 'This field must be at most %d characters long',
'minlength' => 'This field must be at least %d characters long',
'validateoptions' => 'The option "%s" is invalid'
'validateoptions' => 'The option "%s" is invalid',
'integer' => 'This field must be an integer',
)
);
......
<?php
/**
* This program is part of Mahara
*
* 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 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form-rule
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
/**
* Returns whether the given field is an integer
*
* @param Form $form The form the rule is being applied to
* @param string $value The value to check
* @return string The error message, if there is something wrong with
* the address.
*/
function form_rule_integer(Form $form, $value) {
if (!is_numeric($value) || $value != (int)$value) {
return $form->i18n('integer');
}
}
?>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment