Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1371 lars 1
<?php
2
 
3
/**
4
 * Project:     SmartyValidate: Form Validator for the Smarty Template Engine
5
 * File:        validate_criteria.isCCNum.php
6
 * Author:      Monte Ohrt <monte at newdigitalgroup dot com>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 *
22
 * @link http://www.phpinsider.com/php/code/SmartyValidate/
23
 * @copyright 2001-2005 New Digital Group, Inc.
24
 * @author Monte Ohrt <monte at newdigitalgroup dot com>
25
 * @package SmartyValidate
26
 */
27
 
28
 /**
29
 * test if a value is a valid credit card checksum
30
 *
31
 * @param string $value the value being tested
32
 * @param boolean $empty if field can be empty
33
 * @param array params validate parameter values
34
 * @param array formvars form var values
35
 */
36
function smarty_validate_criteria_isCCNum($value, $empty, &$params, &$formvars) {
37
    if(strlen($value) == 0)
38
        return $empty;
39
 
40
	// strip everything but digits
41
	$value = preg_replace('!\D+!', '', $value);
42
 
43
	if (empty($value))
44
		return false;
45
 
46
	$_c_digits = preg_split('//', $value, -1, PREG_SPLIT_NO_EMPTY);
47
 
48
	$_max_digit   = count($_c_digits)-1;
49
	$_even_odd    = $_max_digit % 2;
50
 
51
	$_sum = 0;
52
	for ($_count=0; $_count <= $_max_digit; $_count++) {
53
		$_digit = $_c_digits[$_count];
54
		if ($_even_odd) {
55
			$_digit = $_digit * 2;
56
			if ($_digit > 9) {
57
				$_digit = substr($_digit, 1, 1) + 1;
58
			}
59
		}
60
		$_even_odd = 1 - $_even_odd;
61
		$_sum += $_digit;
62
	}
63
	$_sum = $_sum % 10;
64
	if($_sum)
65
		return false;
66
	return true;
67
 
68
}
69
 
70
?>