Posted By

ha20 on 04/28/10


Tagged

php iban


Versions (?)

IBAN Validation with PHP


 / Published in: PHP
 

URL: http://www.playtruckgames.org

Here's the Php code block that you can validate an IBAN number.

  1. function validateIban($value) {
  2. $iban = false;
  3. $value= strtoupper(trim($value));
  4.  
  5. // Preg Match -- Country US (change for other countries)
  6. if(preg_match('/^US\d{7}0[A-Z0-9]{16}$/', $value)) {
  7. $number = substr($value,4,22).'2927'.substr($value,2,2);
  8. $number = str_replace(
  9.  
  10. // Arrays
  11. 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'),
  12.  
  13. 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),
  14. $number
  15. );
  16.  
  17. $iban = (1 == bcmod($number,97)) ? true:false;
  18. }
  19.  
  20. return $iban;
  21. }

Report this snippet  

You need to login to post a comment.