Intervention\Validation\Validator::isIban PHP Method

isIban() public static method

Checks if given value is valid International Bank Account Number (IBAN).
public static isIban ( mixed $value ) : boolean
$value mixed
return boolean
    public static function isIban($value)
    {
        // build replacement arrays
        $iban_replace_chars = range('A', 'Z');
        foreach (range(10, 35) as $tempvalue) {
            $iban_replace_values[] = strval($tempvalue);
        }
        // prepare string
        $tempiban = strtoupper($value);
        $tempiban = str_replace(' ', '', $tempiban);
        // check iban length
        if (self::getIbanLength($tempiban) != strlen($tempiban)) {
            return false;
        }
        // build checksum
        $tempiban = substr($tempiban, 4) . substr($tempiban, 0, 4);
        $tempiban = str_replace($iban_replace_chars, $iban_replace_values, $tempiban);
        $tempcheckvalue = intval(substr($tempiban, 0, 1));
        for ($strcounter = 1; $strcounter < strlen($tempiban); $strcounter++) {
            $tempcheckvalue *= 10;
            $tempcheckvalue += intval(substr($tempiban, $strcounter, 1));
            $tempcheckvalue %= 97;
        }
        // only modulo 1 is iban
        return $tempcheckvalue == 1;
    }

Usage Example

Example #1
0
 public function testValidateIban()
 {
     $iban = 'DE12500105170648489890';
     $no_iban = 'DE21340155170648089890';
     $this->assertTrue(Validator::isIban($iban));
     $this->assertFalse(Validator::isIban($no_iban));
 }
All Usage Examples Of Intervention\Validation\Validator::isIban