function validateIban($value) {
$iban = false;
$value= strtoupper(trim($value));
// Preg Match -- Country US (change for other countries)
if(preg_match('/^US\d{7}0[A-Z0-9]{16}$/', $value)) {
$number = substr($value,4,22).'2927'.substr($value,2,2);
$number = str_replace(
// Arrays
array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'),
array(10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35),
$number
);
$iban = (1 == bcmod($number,97)) ? true:false;
}
return $iban;
}
Refactorings
No refactoring yet !
fain182.myopenid.com
May 1, 2010, May 01, 2010 10:12, permalink
i haven't tested it...
<?php
function validateIban($value) {
$value= strtoupper(trim($value));
// Preg Match -- Country US (change for other countries)
if(preg_match('/^US\d{7}0[A-Z0-9]{16}$/', $value)) {
$number = substr($value,4,22).'2927'.substr($value,2,2);
for ($i = 0; $i < strlen($number); $i++)
if ( ctype_alpha($number{$i})
$number{$i} = ord($number{$i}) -56;
return (1 == bcmod($number,97));
}
return false;
}
?>
Here's the Php code block that you can validate an IBAN number.
[Play Truck Games](http://www.playtruckgames.org)
[Truck Games](http://www.playtruckgames.org)
<a href="http://www.playtruckgames.org"> Truck Games </a>
<a href="http://www.playtruckgames.org"> Play Truck Games </a>