00001 <?php
00002
00007 class oxSepaValidator
00008 {
00022 public function isValidBIC($sBIC)
00023 {
00024 return (bool)getStr()->preg_match("([a-zA-Z]{4}[a-zA-Z]{2}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?)", $sBIC);
00025 }
00026
00037 public function isValidIBAN($sIBAN)
00038 {
00039 $blValid = true;
00040
00041 $oStr = getStr();
00042 $sIBAN = strtoupper( trim($sIBAN) );
00043 $aIBANRegistry = $this->getIBANRegistry();
00044
00045
00046 $sLangAbbr = $oStr->substr($sIBAN, 0, 2);
00047 $iLength = $aIBANRegistry[$sLangAbbr];
00048 if ( !is_null($iLength) && $oStr->strlen($sIBAN) != $iLength ) {
00049 $blValid = false;
00050 }
00051
00052
00053 $sInitialChars = $oStr->substr($sIBAN, 0, 4);
00054 $sIBAN = substr_replace($sIBAN, '', 0, 4);
00055 $sIBAN = $sIBAN . $sInitialChars;
00056
00057
00058 $sIBAN= str_replace(
00059 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'),
00060 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),
00061 $sIBAN
00062 );
00063
00064
00065 $sModulus = bcmod($sIBAN, 97);
00066 if ( (int)$sModulus != 1 ) {
00067 $blValid = false;
00068 }
00069
00070
00071 return $blValid;
00072 }
00073
00081 public function isValidIBANRegistry($aIBANRegistry = null)
00082 {
00083 $blValid = true;
00084
00085
00086 if ( is_null($aIBANRegistry) ) {
00087 $aIBANRegistry = $this->getIBANRegistry();
00088 }
00089
00090 if ( !is_array($aIBANRegistry) || empty($aIBANRegistry) ) {
00091 $blValid = false;
00092 }
00093
00094 foreach ($aIBANRegistry as $sCountryAbbr => $iLength) {
00095 if ( (int)preg_match("/^[A-Z]{2}$/", $sCountryAbbr) === 0 ) {
00096 $blValid = false;
00097 break;
00098 }
00099 if ( !is_numeric($iLength) || (int)preg_match("/\./", $iLength) === 1 ) {
00100 $blValid = false;
00101 break;
00102 }
00103
00104 }
00105
00106 return $blValid;
00107 }
00108
00116 public function setIBANRegistry($aIBANRegistry)
00117 {
00118 if ( $this->isValidIBANRegistry($aIBANRegistry) ) {
00119 $this->_aIBANRegistry = $aIBANRegistry;
00120 return true;
00121 } else {
00122 return false;
00123 }
00124
00125 }
00126
00132 public function getIBANRegistry()
00133 {
00134 return $this->_aIBANRegistry;
00135 }
00136
00140 protected $_aIBANRegistry = array(
00141 'AL' => 28,
00142 'AD' => 24,
00143 'AT' => 20,
00144 'AZ' => 28,
00145 'BH' => 22,
00146 'BE' => 16,
00147 'BA' => 20,
00148 'BR' => 29,
00149 'BG' => 22,
00150 'CR' => 21,
00151 'HR' => 21,
00152 'CY' => 28,
00153 'CZ' => 24,
00154 'DK' => 18,
00155 'FO' => 18,
00156 'GL' => 18,
00157 'DO' => 28,
00158 'EE' => 20,
00159 'FI' => 18,
00160 'FR' => 27,
00161 'GE' => 22,
00162 'DE' => 22,
00163 'GI' => 23,
00164 'GR' => 27,
00165 'GT' => 28,
00166 'HU' => 28,
00167 'IS' => 26,
00168 'IE' => 22,
00169 'IL' => 23,
00170 'IT' => 27,
00171 'KZ' => 20,
00172 'KW' => 30,
00173 'LV' => 21,
00174 'LB' => 28,
00175 'LI' => 21,
00176 'LT' => 20,
00177 'LU' => 20,
00178 'MK' => 19,
00179 'MT' => 31,
00180 'MR' => 27,
00181 'MU' => 30,
00182 'MD' => 24,
00183 'MC' => 27,
00184 'ME' => 22,
00185 'NL' => 18,
00186 'NO' => 15,
00187 'PK' => 24,
00188 'PS' => 29,
00189 'PL' => 28,
00190 'PL' => 28,
00191 'PT' => 25,
00192 'RO' => 24,
00193 'SM' => 27,
00194 'SA' => 24,
00195 'RS' => 22,
00196 'SK' => 24,
00197 'SI' => 19,
00198 'ES' => 24,
00199 'SE' => 24,
00200 'CH' => 21,
00201 'TN' => 24,
00202 'TR' => 26,
00203 'AE' => 23,
00204 'GB' => 22,
00205 'VG' => 24
00206 );
00207 }