Nel tutorial di oggi imparerete come creare una funzione che valida l'IBAN in PHP.
Per fare quanto detto faremo uso delle espressioni regolari e di alcune funzioni sulle stringhe.
< ?php function ValidIban($value) { $iban = false; $value= strtoupper(trim($value)); if(preg_match('/^IT\d{7}0[A-Z0-9]{16}$/', $value)) { $number= substr($value,4,22).'2927'.substr($value,2,2); $number= str_replace( 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 var - $iban = (1 == bcmod($number,97)) ? true:false; } // Return to print return $iban; }



Leave Your Response