Permalink
Browse files

Moved ABA validator and CC validator functions to enrol_form.php

  • Loading branch information...
1 parent a66ddf1 commit dfe254ceab310c644d171405324e178a64346771 ethem committed Nov 17, 2006
Showing with 100 additions and 101 deletions.
  1. +100 −0 enrol/authorize/enrol_form.php
  2. +0 −101 enrol/authorize/localfuncs.php
@@ -243,4 +243,104 @@ function other_method($currentmethod)
return '';
}
}
+
+function ABAVal($aba)
+{
+ if (ereg("^[0-9]{9}$", $aba)) {
+ $n = 0;
+ for($i = 0; $i < 9; $i += 3) {
+ $n += (substr($aba, $i, 1) * 3) + (substr($aba, $i + 1, 1) * 7) + (substr($aba, $i + 2, 1));
+ }
+ if ($n != 0 and $n % 10 == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+function CCVal($Num, $Name = "n/a", $Exp = "")
+{
+ // Check the expiration date first
+ if (strlen($Exp))
+ {
+ $Month = substr($Exp, 0, 2);
+ $Year = substr($Exp, -2);
+ $WorkDate = "$Month/01/$Year";
+ $WorkDate = strtotime($WorkDate);
+ $LastDay = date("t", $WorkDate);
+ $Expires = strtotime("$Month/$LastDay/$Year 11:59:59");
+ if ($Expires < time()) return 0;
+ }
+
+ // Innocent until proven guilty
+ $GoodCard = true;
+
+ // Get rid of any non-digits
+ $Num = ereg_replace("[^0-9]", "", $Num);
+
+ // Perform card-specific checks, if applicable
+ switch ($Name)
+ {
+ case "mcd" :
+ $GoodCard = ereg("^5[1-5].{14}$", $Num);
+ break;
+
+ case "vis" :
+ $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
+ break;
+
+ case "amx" :
+ $GoodCard = ereg("^3[47].{13}$", $Num);
+ break;
+
+ case "dsc" :
+ $GoodCard = ereg("^6011.{12}$", $Num);
+ break;
+
+ case "dnc" :
+ $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
+ break;
+
+ case "jcb" :
+ $GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
+ break;
+
+ case "dlt" :
+ $GoodCard = ereg("^4.{15}$", $Num);
+ break;
+
+ case "swi" :
+ $GoodCard = ereg("^[456].{15}$|^[456].{17,18}$", $Num);
+ break;
+
+ case "enr" :
+ $GoodCard = ereg("^2014.{11}$|^2149.{11}$", $Num);
+ break;
+ }
+
+ // The Luhn formula works right to left, so reverse the number.
+ $Num = strrev($Num);
+ $Total = 0;
+
+ for ($x=0; $x < strlen($Num); $x++)
+ {
+ $digit = substr($Num, $x, 1);
+
+ // If it's an odd digit, double it
+ if ($x/2 != floor($x/2)) {
+ $digit *= 2;
+
+ // If the result is two digits, add them
+ if (strlen($digit) == 2)
+ $digit = substr($digit, 0, 1) + substr($digit, 1, 1);
+ }
+ // Add the current digit, doubled and added if applicable, to the Total
+ $Total += $digit;
+ }
+
+ // If it passed (or bypassed) the card-specific check and the Total is
+ // evenly divisible by 10, it's cool!
+ return ($GoodCard && $Total % 10 == 0);
+}
+
?>
@@ -108,107 +108,6 @@ function get_list_of_bank_account_types($getall = false)
}
}
-function ABAVal($aba)
-{
- if (ereg("^[0-9]{9}$", $aba)) {
- $n = 0;
- for($i = 0; $i < 9; $i += 3) {
- $n += (substr($aba, $i, 1) * 3) +
- (substr($aba, $i + 1, 1) * 7) +
- (substr($aba, $i + 2, 1));
- }
- if ($n != 0 and $n % 10 == 0) {
- return true;
- }
- }
- return false;
-}
-
-function CCVal($Num, $Name = "n/a", $Exp = "")
-{
- // Check the expiration date first
- if (strlen($Exp))
- {
- $Month = substr($Exp, 0, 2);
- $Year = substr($Exp, -2);
- $WorkDate = "$Month/01/$Year";
- $WorkDate = strtotime($WorkDate);
- $LastDay = date("t", $WorkDate);
- $Expires = strtotime("$Month/$LastDay/$Year 11:59:59");
- if ($Expires < time()) return 0;
- }
-
- // Innocent until proven guilty
- $GoodCard = true;
-
- // Get rid of any non-digits
- $Num = ereg_replace("[^0-9]", "", $Num);
-
- // Perform card-specific checks, if applicable
- switch ($Name)
- {
- case "mcd" :
- $GoodCard = ereg("^5[1-5].{14}$", $Num);
- break;
-
- case "vis" :
- $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
- break;
-
- case "amx" :
- $GoodCard = ereg("^3[47].{13}$", $Num);
- break;
-
- case "dsc" :
- $GoodCard = ereg("^6011.{12}$", $Num);
- break;
-
- case "dnc" :
- $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
- break;
-
- case "jcb" :
- $GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
- break;
-
- case "dlt" :
- $GoodCard = ereg("^4.{15}$", $Num);
- break;
-
- case "swi" :
- $GoodCard = ereg("^[456].{15}$|^[456].{17,18}$", $Num);
- break;
-
- case "enr" :
- $GoodCard = ereg("^2014.{11}$|^2149.{11}$", $Num);
- break;
- }
-
- // The Luhn formula works right to left, so reverse the number.
- $Num = strrev($Num);
- $Total = 0;
-
- for ($x=0; $x < strlen($Num); $x++)
- {
- $digit = substr($Num, $x, 1);
-
- // If it's an odd digit, double it
- if ($x/2 != floor($x/2)) {
- $digit *= 2;
-
- // If the result is two digits, add them
- if (strlen($digit) == 2)
- $digit = substr($digit, 0, 1) + substr($digit, 1, 1);
- }
- // Add the current digit, doubled and added if applicable, to the Total
- $Total += $digit;
- }
-
- // If it passed (or bypassed) the card-specific check and the Total is
- // evenly divisible by 10, it's cool!
- return ($GoodCard && $Total % 10 == 0);
-}
-
function email_to_admin($subject, $data)
{
global $SITE;

0 comments on commit dfe254c

Please sign in to comment.