Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions lib/iban-tools/rules.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Data from http://www.tbg5-finance.org/?ibandocs.shtml/
# and from https://wise.com/gb/iban/example?all=true

'AD':
# Andorra
Expand All @@ -23,7 +24,7 @@
'AZ':
# Azerbaijan, Republic of
length: 28
bban_pattern: '\d[0-9]{2}[A-Z]{4}[A-Z0-9]{20}'
bban_pattern: '[A-Z]{4}[A-Z0-9]{20}'

'BA':
# Bosnia
Expand All @@ -48,7 +49,7 @@
'BR':
# Brazil
length: 29
bban_pattern: '\d[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}'
bban_pattern: '[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}'

'CH':
# Switzerland
Expand All @@ -57,8 +58,8 @@

'CR':
# Costa Rica
length: 21
bban_pattern: '\d[0-9]{2}[0-9]{3}[0-9]{14}'
length: 22
bban_pattern: '[0-9]{4}[0-9]{14}'

'CY':
# Cyprus
Expand Down Expand Up @@ -90,6 +91,11 @@
length: 20
bban_pattern: '\d{16}'

'EG':
# Egypt
length: 29
bban_pattern: '\d{25}'

'ES':
# Spain
length: 24
Expand Down Expand Up @@ -138,7 +144,7 @@
'GT':
# Guatemala
length: 28
bban_pattern: '\d[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}'
bban_pattern: '[A-Z0-9]{4}[A-Z0-9]{20}'

'HR':
# Croatia
Expand Down Expand Up @@ -170,6 +176,11 @@
length: 27
bban_pattern: '[A-Z]\d{10}[A-Z0-9]{12}'

'JO':
# Jordan
length: 30
bban_pattern: '[A-Z]{4}\d{22}'

'KW':
# Kuwait
length: 30
Expand Down Expand Up @@ -213,7 +224,7 @@
'MD':
# Moldova
length: 24
bban_pattern: '\d[0-9]{2}[A-Z0-9]{20}'
bban_pattern: '[A-Z0-9]{20}'

'ME':
# Montenegro
Expand Down Expand Up @@ -253,7 +264,7 @@
'PK':
# Pakistan
length: 24
bban_pattern: '\d[0-9]{2}[A-Z]{4}[A-Z0-9]{16}'
bban_pattern: '[A-Z]{4}[A-Z0-9]{16}'

'PL':
# Poland
Expand All @@ -263,7 +274,7 @@
'PS':
# Palestinian Territory, Occupied
length: 29
bban_pattern: '\d[0-9]{2}[A-Z]{4}[A-Z0-9]{21}'
bban_pattern: '[A-Z]{4}[A-Z0-9]{21}'

'PT':
# Portugal
Expand All @@ -273,7 +284,7 @@
'QA':
# Qatar
length: 29
bban_pattern: '\d[0-9]{2}[A-Z]{4}[A-Z0-9]{21}'
bban_pattern: '[A-Z]{4}[A-Z0-9]{21}'

'RO':
# Romania
Expand Down Expand Up @@ -310,10 +321,15 @@
length: 27
bban_pattern: '[A-Z]\d{10}[A-Z0-9]{12}'

'SV':
# El Salvador
length: 28
bban_pattern: '[A-Z]{4}\d{20}'

'TL':
# Timor-Leste
length: 23
bban_pattern: '\d[0-9]{2}[0-9]{3}[0-9]{14}[0-9]{2}'
bban_pattern: '[0-9]{3}[0-9]{14}[0-9]{2}'

'TN':
# Tunisia
Expand All @@ -330,12 +346,17 @@
length: 29
bban_pattern: '\d{25}'

'VA':
# Vatican City State
length: 22
bban_pattern: '\d{18}'

'VG':
# Virgin Islands, British
length: 24
bban_pattern: '\d[0-9]{2}[A-Z]{4}[0-9]{16}'
bban_pattern: '[A-Z]{4}[0-9]{16}'

'XK':
# Kosovo, Republic of
length: 20
bban_pattern: '\d[0-9]{2}[0-9]{4}[A-Z0-9]{12}'
bban_pattern: '[0-9]{4}[A-Z0-9]{12}'
99 changes: 83 additions & 16 deletions spec/iban-tools/iban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

module IBANTools
describe IBAN do

describe "with test rules" do

before(:each) do
@rules = IBANRules.new({ "GB" => {"length" => 22, "bban_pattern" => /[A-Z]{4}.*/} })
end
Expand Down Expand Up @@ -81,11 +79,10 @@ module IBANTools
end

describe "with default rules" do

# Rules are loaded from lib/iban-tools/rules.yml
# Samples from http://www.tbg5-finance.org/?ibandocs.shtml/

[ "AD1200012030200359100100",
[
# Samples from http://www.tbg5-finance.org/?ibandocs.shtml/
"AD1200012030200359100100",
"AE070331234567890123456",
"AL47212110090000000235698741",
"AT611904300234573201",
Expand All @@ -96,7 +93,7 @@ module IBANTools
"BH67BMAG00001299123456",
"BR7724891749412660603618210F3",
"CH9300762011623852957",
"CR0515202001026284066",
"CR05015202001026284066",
"CY17002001280000001200527600",
"CZ6508000000192000145399",
"DE89370400440532013000",
Expand Down Expand Up @@ -151,22 +148,92 @@ module IBANTools
"TN5914207207100707129648",
"TR330006100519786457841326",
"VG96VPVG0000012345678901",
"XK051212012345678906"
].each do |iban_code|
describe iban_code do
it "should be valid" do
IBAN.new(iban_code).validation_errors.should == []
end
end
"XK051212012345678906",

# Samples taken from https://wise.com/gb/iban/example?all=true
"AL47212110090000000235698741",
"AD1200012030200359100100",
"AT611904300234573201",
"AZ21NABZ00000000137010001944",
"BH67BMAG00001299123456",
"BE68539007547034",
"BA391290079401028494",
"BR1800360305000010009795493C1",
"BG80BNBG96611020345678",
"CR05015202001026284066",
"HR1210010051863000160",
"CY17002001280000001200527600",
"CZ6508000000192000145399",
"DK5000400440116243",
"DO28BAGR00000001212453611324",
"EG380019000500000000263180002",
"SV62CENR00000000000000700025",
"EE382200221020145685",
"FO6264600001631634",
"FI2112345600000785",
"FR1420041010050500013M02606",
"GE29NB0000000101904917",
"DE89370400440532013000",
"GI75NWBK000000007099453",
"GR1601101250000000012300695",
"GL8964710001000206",
"GT82TRAJ01020000001210029690",
"HU42117730161111101800000000",
"IS140159260076545510730339",
"IE29AIBK93115212345678",
"IL620108000000099999999",
"IT60X0542811101000000123456",
"JO94CBJO0010000000000131000302",
"KZ86125KZT5004100100",
"XK051212012345678906",
"KW81CBKU0000000000001234560101",
"LV80BANK0000435195001",
"LB62099900000001001901229114",
"LI21088100002324013AA",
"LT121000011101001000",
"LU280019400644750000",
"MK07250120000058984",
"MT84MALT011000012345MTLCAST001S",
"MR1300020001010000123456753",
"MC5811222000010123456789030",
"ME25505000012345678951",
"NL91ABNA0417164300",
"NO9386011117947",
"PK36SCBL0000001123456702",
"PS92PALS000000000400123456702",
"PL61109010140000071219812874",
"PT50000201231234567890154",
"QA58DOHB00001234567890ABCDEFG",
"MD24AG000225100013104168",
"RO49AAAA1B31007593840000",
"SM86U0322509800000000270100",
"SA0380000000608010167519",
"RS35260005601001611379",
"SK3112000000198742637541",
"SI56263300012039086",
"ES9121000418450200051332",
"SE4550000000058398257466",
"CH9300762011623852957",
"TL380080012345678910157",
"TR330006100519786457841326",
"UA213223130000026007233566001",
"AE070331234567890123456",
"GB29NWBK60161331926819",
"VA59001123000012345678",
"VG96VPVG0000012345678901",
].each do |iban_code|
describe iban_code do
it "should be valid" do
IBAN.new(iban_code).validation_errors.should == []
end
end
end

it "should fail known pattern violations" do
# This IBAN has valid check digits
# but should fail because of pattern violation
IBAN.valid?("RO7999991B31007593840000").should be_false
end

end

end
end