Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simple new method added for validating sort codes.

  • Loading branch information...
commit 23da7200ba2031e5b29c01b5844805460b714a01 1 parent 35a918b
@kenguest kenguest authored
View
17 Validate/IE.php
@@ -367,6 +367,23 @@ function licensePlate($number)
}
}
// }}}
+
+ // {{{ public function sortCode
+
+ /**
+ * Validate a sort code, no dashes or whitespace - just digits.
+ *
+ * @param string $sc The sort code.
+ *
+ * @access public
+ * @return bool
+ */
+ function sortCode($sc)
+ {
+ // 6 digits expected - starting with a '9'.
+ return (preg_match('/^9[0-9]{5}$/', $sc)) ? true : false;
+ }
+ // }}}
// {{{ public function bankAC
/**
* Validate a bank account number
View
8 tests/validate_IE_bankAC.phpt
@@ -23,11 +23,11 @@ $sort_codes = array(
'123456789', //NOK - too many digits
'1234567', //NOK - too few digits;
);
-echo "\nTest bank accounts\n";
+echo "\nTest bank accounts prefixed with sort codes\n";
foreach ($ACs as $AC) {
echo "{$AC}: ".$noYes[Validate_IE::bankAC($AC)]."\n";
}
-echo "\nTest sort codes\n";
+echo "\nTest bank accounts\n";
foreach ($sort_codes as $sort_code) {
echo "{$sort_code}: ".$noYes[Validate_IE::bankAC($sort_code, true)]."\n";
}
@@ -38,13 +38,13 @@ exit(0);
Test Validate_IE
****************
-Test bank accounts
+Test bank accounts prefixed with sort codes
12345678901234: YES
A2345678901234: NO
123456789012345: NO
12C4567890123: NO
-Test sort codes
+Test bank accounts
12345678: YES
A2345678: NO
123456789: NO
View
42 tests/validate_IE_sortCode.phpt
@@ -0,0 +1,42 @@
+--TEST--
+validate_IE_sortCode.phpt: Unit tests for sortCode method of 'Validate/IE.php'
+
+--FILE--
+<?php
+// Validate test script
+error_reporting(0);
+$noYes = array('NO', 'YES');
+require_once 'Validate/IE.php';
+
+echo "Test Validate_IE\n";
+echo "****************\n";
+
+//test bank account
+$sort_codes = array(
+'123456', //OK
+'A23456', //NOK - not numeric
+'123456789', //NOK - too many digits
+'1234567', //NOK - too many digits;
+'12345', //NOK - too many digits;
+'000000', // NOK - known to be invalid
+'999999', // NOK - known to be invalid
+);
+echo "\nTest sort codes\n";
+foreach ($sort_codes as $sort_code) {
+ echo "{$sort_code}: ".$noYes[Validate_IE::sortCode($sort_code)]."\n";
+}
+exit(0);
+?>
+
+--EXPECT--
+Test Validate_IE
+****************
+
+Test sort codes
+123456: YES
+A23456: NO
+123456789: NO
+1234567: NO
+12345: NO
+000000: NO
+999999: NO
Please sign in to comment.
Something went wrong with that request. Please try again.