Skip to content

Commit

Permalink
simple new method added for validating sort codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenguest committed Jan 3, 2013
1 parent 35a918b commit 23da720
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Validate/IE.php
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/validate_IE_bankAC.phpt
Expand Up @@ -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";
}
Expand All @@ -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
Expand Down
42 changes: 42 additions & 0 deletions 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

0 comments on commit 23da720

Please sign in to comment.