IsoCodes\Bsn::validate PHP Method

validate() public static method

public static validate ( string $value ) : boolean
$value string
return boolean
    public static function validate($value)
    {
        if (!is_numeric($value)) {
            return false;
        }
        $stringLength = strlen($value);
        if ($stringLength !== 9 && $stringLength !== 8) {
            return false;
        }
        $sum = 0;
        $multiplier = $stringLength;
        for ($counter = 0; $counter < $stringLength; $counter++, $multiplier--) {
            if ($multiplier == 1) {
                $multiplier = -1;
            }
            $sum += substr($value, $counter, 1) * $multiplier;
        }
        return $sum % 11 === 0;
    }