== see: http://en.wikipedia.org/wiki/Interna...Account_Number
-- Rule process of IBAN validation is:
-- 1. Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid.
-- 2. Move the four initial characters to the end of the string.
-- 3. Replace each letter in the string with two digits, thereby expanding the string,
-- where A=10, B=11, ..., Z=35.
-- 4. Interpret the string as a decimal integer and compute the remainder of that number on division by 97.
-- If the remainder is 1, the checks digits test is passed and the IBAN may be valid.
Code:Function Validate_IBAN(ByVal IBAN As String) As Boolean Dim i As Long Dim n As Long IBAN = Replace(IBAN, " ", "") '-- space separator accepted, remove it before processsing If IBAN Like "*[!0-9A-Z]*" Then Exit Function '-- contains invalid character '-- step 1. (simplified) If Len(IBAN) < 5 Or Len(IBAN) > 31 Then Exit Function '-- step 2. IBAN = Mid$(IBAN, 5) & Left$(IBAN, 4) '-- step 3. For i = 65 To 90 If InStr(IBAN, Chr$(i)) Then IBAN = Replace(IBAN, Chr$(i), CStr(i - 55)) Next '-- step 4. n = CLng(Left$(IBAN, 9)) Mod 97 For i = 10 To Len(IBAN) n = (n * 10 + CLng(Mid$(IBAN, i, 1))) Mod 97 Next '-- n can be calculated by using function BigMod: n = BigMod(IBAN, 97) Validate_IBAN = (n = 1) End FunctionCode:Sub TryIt() Dim i As Long Dim IBAN(4) As String IBAN(0) = "GR16 0110 1250 0000 0001 2300 695" '-- Greece IBAN(1) = "GB29 NWBK 6016 1331 9268 19" '-- Great Britain IBAN(2) = "SA03 8000 0000 6080 1016 7519" '-- Saudi Arabia IBAN(3) = "CH93 0076 2011 6238 5295 7" '-- Switzerland IBAN(4) = "IL62 0108 0000 0009 9999 999" '-- Israel For i = 0 To 4 Debug.Print i; Validate_IBAN(IBAN(i)) Next Debug.Print End SubCode:Function BigMod(BigInt As String, k As Long) As Long '-- pre: BigInt contains only digits, k > 0 Dim i As Long BigMod = CLng(Left$(BigInt, 9)) Mod k For i = 10 To Len(BigInt) BigMod = (BigMod * 10 + CLng(Mid$(BigInt, i, 1))) Mod k Next End Function




Reply With Quote