Added missing Smarty plugins
This commit is contained in:
parent
d841588901
commit
59ece2fd41
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.dummyValid.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* always return valid
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_dummyValid($value, $empty, &$params, &$formvars) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isCCExpDate.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid credit card expiration date
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isCCExpDate($value, $empty, &$params, &$formvars) {
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!preg_match('!^(\d+)\D+(\d+)$!', $value, $_match))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$_month = $_match[1];
|
||||||
|
$_year = $_match[2];
|
||||||
|
|
||||||
|
if(strlen($_year) == 2)
|
||||||
|
$_year = substr(date('Y', time()),0,2) . $_year;
|
||||||
|
|
||||||
|
$_month = (int) $_month;
|
||||||
|
$_year = (int) $_year;
|
||||||
|
|
||||||
|
if($_month < 1 || $_month > 12)
|
||||||
|
return false;
|
||||||
|
if(date('Y',time()) > $_year)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(date('Y',time()) == $_year && date('m', time()) > $_month)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isCCNum.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid credit card checksum
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isCCNum($value, $empty, &$params, &$formvars) {
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
// strip everything but digits
|
||||||
|
$value = preg_replace('!\D+!', '', $value);
|
||||||
|
|
||||||
|
if (empty($value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$_c_digits = preg_split('//', $value, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
|
||||||
|
$_max_digit = count($_c_digits)-1;
|
||||||
|
$_even_odd = $_max_digit % 2;
|
||||||
|
|
||||||
|
$_sum = 0;
|
||||||
|
for ($_count=0; $_count <= $_max_digit; $_count++) {
|
||||||
|
$_digit = $_c_digits[$_count];
|
||||||
|
if ($_even_odd) {
|
||||||
|
$_digit = $_digit * 2;
|
||||||
|
if ($_digit > 9) {
|
||||||
|
$_digit = substr($_digit, 1, 1) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$_even_odd = 1 - $_even_odd;
|
||||||
|
$_sum += $_digit;
|
||||||
|
}
|
||||||
|
$_sum = $_sum % 10;
|
||||||
|
if($_sum)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isDate.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid date (parsable by strtotime)
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isDate($value, $empty, &$params, &$formvars) {
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
$_ret = strtotime($value);
|
||||||
|
return $_ret != -1 && $_ret !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isDateAfter.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a date is later than another
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isDateAfter($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!isset($params['field2'])) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_date1 = strtotime($value);
|
||||||
|
$_date2 = strtotime($formvars[$params['field2']]);
|
||||||
|
|
||||||
|
if($_date1 == -1 || !$_date1) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($_date2 == -1 || !$_date2) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_date1 > $_date2;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isDateBefore.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a date is earlier than another
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isDateBefore($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!isset($params['field2'])) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_date1 = strtotime($value);
|
||||||
|
$_date2 = strtotime($formvars[$params['field2']]);
|
||||||
|
|
||||||
|
if($_date1 == -1 || !$_date1) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($_date2 == -1 || !$_date2) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_date1 < $_date2;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isDateEqual.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if two dates are equal
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isDateEqual($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!isset($params['field2'])) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_date1 = strtotime($value);
|
||||||
|
$_date2 = strtotime($formvars[$params['field2']]);
|
||||||
|
|
||||||
|
if($_date1 == -1 || !$_date1) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($_date2 == -1 || !$_date2) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_date1 == $_date2;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isDateOnOrAfter.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a date is equal or later than another
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isDateOnOrAfter($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!isset($params['field2'])) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_date1 = strtotime($value);
|
||||||
|
$_date2 = strtotime($formvars[$params['field2']]);
|
||||||
|
|
||||||
|
if($_date1 == -1 || !$_date1) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($_date2 == -1 || !$_date2) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_date1 >= $_date2;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isDateOnOrBefore.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a date is equal or earlier than another
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isDateOnOrBefore($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!isset($params['field2'])) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_date1 = strtotime($value);
|
||||||
|
$_date2 = strtotime($formvars[$params['field2']]);
|
||||||
|
|
||||||
|
if($_date1 == -1 || !$_date1) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($_date2 == -1 || !$_date2) {
|
||||||
|
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_date1 <= $_date2;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isEmail.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid e-mail address
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* the value being tested
|
||||||
|
* @param boolean $empty
|
||||||
|
* if field can be empty
|
||||||
|
* @param
|
||||||
|
* array params validate parameter values
|
||||||
|
* @param
|
||||||
|
* array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isEmail($value, $empty, &$params, &$formvars) {
|
||||||
|
if (strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
// in case value is several addresses separated by newlines
|
||||||
|
$_addresses = preg_split('![\n\r]+!', $value);
|
||||||
|
|
||||||
|
foreach ($_addresses as $_address) {
|
||||||
|
$_is_valid = !(preg_match('!@.*@|\.\.|\,|\;!', $_address) || !preg_match('!^.+\@(\[?)[a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,}|[0-9]{1,})(\]?)$!', $_address));
|
||||||
|
|
||||||
|
if (!$_is_valid)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isEqual.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid range
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isEqual($value, $empty, &$params, &$formvars) {
|
||||||
|
if(!isset($params['field2'])) {
|
||||||
|
trigger_error("SmartyValidate: [isEqual] parameter 'field2' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(strpos($params['field2'],'[') !== false && strpos($params['field2'],']') !== false) {
|
||||||
|
// pull apart array value
|
||||||
|
preg_match('!(\w+)\[(\w*)\]!',$params['field2'],$_match);
|
||||||
|
return $value == $formvars[$_match[1]][$_match[2]];
|
||||||
|
} else {
|
||||||
|
return $value == $formvars[$params['field2']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isFileSize.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid file size.
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isFileSize($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
$_field = $params['field'];
|
||||||
|
$_max = isset($params['field2']) ? $params['field2'] : trim($params['max']);
|
||||||
|
|
||||||
|
|
||||||
|
if(!isset($_FILES[$_field]))
|
||||||
|
// nothing in the form
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if($_FILES[$_field]['error'] == 4)
|
||||||
|
// no file uploaded
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!isset($_max)) {
|
||||||
|
trigger_error("SmartyValidate: [isFileSize] 'max' attribute is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!preg_match('!^(\d+)([bkmg](b)?)?$!i', $_max, $_match)) {
|
||||||
|
trigger_error("SmartyValidate: [isFileSize] 'max' attribute is invalid.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_size = $_match[1];
|
||||||
|
$_type = strtolower($_match[2]);
|
||||||
|
|
||||||
|
switch($_type) {
|
||||||
|
case 'k':
|
||||||
|
$_maxsize = $_size * 1024;
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
$_maxsize = $_size * 1024 * 1024;
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
$_maxsize = $_size * 1024 * 1024 * 1024;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
default:
|
||||||
|
$_maxsize = $_size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_FILES[$_field]['size'] <= $_maxsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isFileType.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid file type. This only checks the
|
||||||
|
* file extention, it does not test the actual file type.
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isFileType($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
$_field = $params['field'];
|
||||||
|
$_type = isset($params['field2']) ? $params['field2'] : $params['type'];
|
||||||
|
|
||||||
|
if(!isset($_FILES[$_field]))
|
||||||
|
// nothing in the form
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if($_FILES[$_field]['error'] == 4)
|
||||||
|
// no file uploaded
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
if(!preg_match('!\.(\w+)$!i', $_FILES[$_field]['name'], $_match))
|
||||||
|
// not valid filename
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$_file_ext = $_match[1];
|
||||||
|
$_types = preg_split('![\s,]+!', $_type, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
foreach($_types as $_key => $_val) {
|
||||||
|
$_types[$_key] = strtolower($_types[$_key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!in_array(strtolower($_file_ext),$_types))
|
||||||
|
// not valid file extention
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isFloat.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a float
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isFloat($value, $empty, &$params, &$formvars) {
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
return preg_match('!^\d+\.\d+?$!', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isInt.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is an integer
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isInt($value, $empty, &$params, &$formvars) {
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
return preg_match('!^\d+$!', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isLength.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid range
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isLength($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
if(isset($params['field2'])) {
|
||||||
|
$_min = $params['field2'];
|
||||||
|
} elseif(isset($params['min'])) {
|
||||||
|
$_min = $params['min'];
|
||||||
|
} else {
|
||||||
|
$_min = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($params['field3'])) {
|
||||||
|
$_max = $params['field3'];
|
||||||
|
} elseif(isset($params['max'])) {
|
||||||
|
$_max = $params['max'];
|
||||||
|
} else {
|
||||||
|
$_max = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_length = strlen($value);
|
||||||
|
|
||||||
|
if(($_min == -1 || $_length >= $_min) && ($_max == -1 || $_length <= $_max))
|
||||||
|
return true;
|
||||||
|
elseif($_length == 0)
|
||||||
|
return $empty;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isNumber.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid number (int of float)
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isNumber($value, $empty, &$params, &$formvars) {
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
return preg_match('!^-?\d+(\.\d+)?$!', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isPrice.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a price
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isPrice($value, $empty, &$params, &$formvars) {
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
return preg_match('/^\d+(\.\d{1,2})?$/', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isRange.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid range
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isRange($value, $empty, &$params, &$formvars) {
|
||||||
|
|
||||||
|
if(isset($params['field2'])) {
|
||||||
|
$_low = $params['field2'];
|
||||||
|
} elseif(isset($params['low'])) {
|
||||||
|
$_low = $params['low'];
|
||||||
|
} else {
|
||||||
|
trigger_error("SmartyValidate: [isRange] parameter 'low' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($params['field3'])) {
|
||||||
|
$_high = $params['field3'];
|
||||||
|
} elseif(isset($params['high'])) {
|
||||||
|
$_high = $params['high'];
|
||||||
|
} else {
|
||||||
|
trigger_error("SmartyValidate: [isRange] parameter 'high' is missing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
return ($value >= $_low && $value <= $_high);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.isRegExp.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is a valid regular expression match
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_isRegExp($value, $empty, &$params, &$formvars) {
|
||||||
|
if(isset($params['field2'])) {
|
||||||
|
$_exp = $params['field2'];
|
||||||
|
} elseif (isset($params['expression'])) {
|
||||||
|
$_exp = $params['expression'];
|
||||||
|
} else {
|
||||||
|
trigger_error("SmartyValidate: [isRegExp] parameter 'expression' is missing.");
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(strlen($value) == 0)
|
||||||
|
return $empty;
|
||||||
|
|
||||||
|
return (preg_match($_exp, $value));
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||||
|
* File: validate_criteria.notEmpty.php
|
||||||
|
* Author: Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* @link http://www.phpinsider.com/php/code/SmartyValidate/
|
||||||
|
* @copyright 2001-2005 New Digital Group, Inc.
|
||||||
|
* @author Monte Ohrt <monte at newdigitalgroup dot com>
|
||||||
|
* @package SmartyValidate
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a value is not empty
|
||||||
|
*
|
||||||
|
* @param string $value the value being tested
|
||||||
|
* @param boolean $empty if field can be empty
|
||||||
|
* @param array params validate parameter values
|
||||||
|
* @param array formvars form var values
|
||||||
|
*/
|
||||||
|
function smarty_validate_criteria_notEmpty($value, $empty, &$params, &$formvars) {
|
||||||
|
return strlen($value) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user