Skip to content

Commit eef45bc

Browse files
nschonnijzaefferer
authored andcommitted
Split out iban and bic
1 parent e1ba7f0 commit eef45bc

File tree

3 files changed

+138
-140
lines changed

3 files changed

+138
-140
lines changed

src/additional/additional.js

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -33,146 +33,6 @@
3333

3434
}());
3535

36-
/**
37-
* IBAN is the international bank account number.
38-
* It has a country - specific format, that is checked here too
39-
*/
40-
jQuery.validator.addMethod("iban", function(value, element) {
41-
// some quick simple tests to prevent needless work
42-
if (this.optional(element)) {
43-
return true;
44-
}
45-
if (!(/^([a-zA-Z0-9]{4} ){2,8}[a-zA-Z0-9]{1,4}|[a-zA-Z0-9]{12,34}$/.test(value))) {
46-
return false;
47-
}
48-
49-
// check the country code and find the country specific format
50-
var iban = value.replace(/ /g,'').toUpperCase(); // remove spaces and to upper case
51-
var countrycode = iban.substring(0,2);
52-
var bbancountrypatterns = {
53-
'AL': "\\d{8}[\\dA-Z]{16}",
54-
'AD': "\\d{8}[\\dA-Z]{12}",
55-
'AT': "\\d{16}",
56-
'AZ': "[\\dA-Z]{4}\\d{20}",
57-
'BE': "\\d{12}",
58-
'BH': "[A-Z]{4}[\\dA-Z]{14}",
59-
'BA': "\\d{16}",
60-
'BR': "\\d{23}[A-Z][\\dA-Z]",
61-
'BG': "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
62-
'CR': "\\d{17}",
63-
'HR': "\\d{17}",
64-
'CY': "\\d{8}[\\dA-Z]{16}",
65-
'CZ': "\\d{20}",
66-
'DK': "\\d{14}",
67-
'DO': "[A-Z]{4}\\d{20}",
68-
'EE': "\\d{16}",
69-
'FO': "\\d{14}",
70-
'FI': "\\d{14}",
71-
'FR': "\\d{10}[\\dA-Z]{11}\\d{2}",
72-
'GE': "[\\dA-Z]{2}\\d{16}",
73-
'DE': "\\d{18}",
74-
'GI': "[A-Z]{4}[\\dA-Z]{15}",
75-
'GR': "\\d{7}[\\dA-Z]{16}",
76-
'GL': "\\d{14}",
77-
'GT': "[\\dA-Z]{4}[\\dA-Z]{20}",
78-
'HU': "\\d{24}",
79-
'IS': "\\d{22}",
80-
'IE': "[\\dA-Z]{4}\\d{14}",
81-
'IL': "\\d{19}",
82-
'IT': "[A-Z]\\d{10}[\\dA-Z]{12}",
83-
'KZ': "\\d{3}[\\dA-Z]{13}",
84-
'KW': "[A-Z]{4}[\\dA-Z]{22}",
85-
'LV': "[A-Z]{4}[\\dA-Z]{13}",
86-
'LB': "\\d{4}[\\dA-Z]{20}",
87-
'LI': "\\d{5}[\\dA-Z]{12}",
88-
'LT': "\\d{16}",
89-
'LU': "\\d{3}[\\dA-Z]{13}",
90-
'MK': "\\d{3}[\\dA-Z]{10}\\d{2}",
91-
'MT': "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
92-
'MR': "\\d{23}",
93-
'MU': "[A-Z]{4}\\d{19}[A-Z]{3}",
94-
'MC': "\\d{10}[\\dA-Z]{11}\\d{2}",
95-
'MD': "[\\dA-Z]{2}\\d{18}",
96-
'ME': "\\d{18}",
97-
'NL': "[A-Z]{4}\\d{10}",
98-
'NO': "\\d{11}",
99-
'PK': "[\\dA-Z]{4}\\d{16}",
100-
'PS': "[\\dA-Z]{4}\\d{21}",
101-
'PL': "\\d{24}",
102-
'PT': "\\d{21}",
103-
'RO': "[A-Z]{4}[\\dA-Z]{16}",
104-
'SM': "[A-Z]\\d{10}[\\dA-Z]{12}",
105-
'SA': "\\d{2}[\\dA-Z]{18}",
106-
'RS': "\\d{18}",
107-
'SK': "\\d{20}",
108-
'SI': "\\d{15}",
109-
'ES': "\\d{20}",
110-
'SE': "\\d{20}",
111-
'CH': "\\d{5}[\\dA-Z]{12}",
112-
'TN': "\\d{20}",
113-
'TR': "\\d{5}[\\dA-Z]{17}",
114-
'AE': "\\d{3}\\d{16}",
115-
'GB': "[A-Z]{4}\\d{14}",
116-
'VG': "[\\dA-Z]{4}\\d{16}"
117-
};
118-
var bbanpattern = bbancountrypatterns[countrycode];
119-
// As new countries will start using IBAN in the
120-
// future, we only check if the countrycode is known.
121-
// This prevents false negatives, while almost all
122-
// false positives introduced by this, will be caught
123-
// by the checksum validation below anyway.
124-
// Strict checking should return FALSE for unknown
125-
// countries.
126-
if (typeof bbanpattern !== 'undefined') {
127-
var ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", "");
128-
if (!(ibanregexp.test(iban))) {
129-
return false; // invalid country specific format
130-
}
131-
}
132-
133-
// now check the checksum, first convert to digits
134-
var ibancheck = iban.substring(4,iban.length) + iban.substring(0,4);
135-
var ibancheckdigits = "";
136-
var leadingZeroes = true;
137-
var charAt;
138-
for (var i =0; i<ibancheck.length; i++) {
139-
charAt = ibancheck.charAt(i);
140-
if (charAt !== "0") {
141-
leadingZeroes = false;
142-
}
143-
if (!leadingZeroes) {
144-
ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(charAt);
145-
}
146-
}
147-
148-
// calculate the result of: ibancheckdigits % 97
149-
var cRest = '';
150-
var cOperator = '';
151-
for (var p=0; p<ibancheckdigits.length; p++) {
152-
var cChar = ibancheckdigits.charAt(p);
153-
cOperator = '' + cRest + '' + cChar;
154-
cRest = cOperator % 97;
155-
}
156-
return cRest === 1;
157-
}, "Please specify a valid IBAN");
158-
159-
/**
160-
* BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
161-
*
162-
* BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
163-
*
164-
* BIC definition in detail:
165-
* - First 4 characters - bank code (only letters)
166-
* - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
167-
* - Next 2 characters - location code (letters and digits)
168-
* a. shall not start with '0' or '1'
169-
* b. second character must be a letter ('O' is not allowed) or one of the following digits ('0' for test (therefore not allowed), '1' for passive participant and '2' for active participant)
170-
* - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
171-
*/
172-
jQuery.validator.addMethod("bic", function(value, element) {
173-
return this.optional( element ) || /^([A-Z]{6}[A-Z2-9][A-NP-Z1-2])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test( value );
174-
}, "Please specify a valid BIC code");
175-
17636
jQuery.validator.addMethod("dateNL", function(value, element) {
17737
return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);
17838
}, "Please enter a correct date");

src/additional/bic.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
3+
*
4+
* BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
5+
*
6+
* BIC definition in detail:
7+
* - First 4 characters - bank code (only letters)
8+
* - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
9+
* - Next 2 characters - location code (letters and digits)
10+
* a. shall not start with '0' or '1'
11+
* b. second character must be a letter ('O' is not allowed) or one of the following digits ('0' for test (therefore not allowed), '1' for passive participant and '2' for active participant)
12+
* - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
13+
*/
14+
jQuery.validator.addMethod("bic", function(value, element) {
15+
return this.optional( element ) || /^([A-Z]{6}[A-Z2-9][A-NP-Z1-2])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test( value );
16+
}, "Please specify a valid BIC code");

src/additional/iban.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* IBAN is the international bank account number.
3+
* It has a country - specific format, that is checked here too
4+
*/
5+
jQuery.validator.addMethod("iban", function(value, element) {
6+
// some quick simple tests to prevent needless work
7+
if (this.optional(element)) {
8+
return true;
9+
}
10+
if (!(/^([a-zA-Z0-9]{4} ){2,8}[a-zA-Z0-9]{1,4}|[a-zA-Z0-9]{12,34}$/.test(value))) {
11+
return false;
12+
}
13+
14+
// check the country code and find the country specific format
15+
var iban = value.replace(/ /g,'').toUpperCase(); // remove spaces and to upper case
16+
var countrycode = iban.substring(0,2);
17+
var bbancountrypatterns = {
18+
'AL': "\\d{8}[\\dA-Z]{16}",
19+
'AD': "\\d{8}[\\dA-Z]{12}",
20+
'AT': "\\d{16}",
21+
'AZ': "[\\dA-Z]{4}\\d{20}",
22+
'BE': "\\d{12}",
23+
'BH': "[A-Z]{4}[\\dA-Z]{14}",
24+
'BA': "\\d{16}",
25+
'BR': "\\d{23}[A-Z][\\dA-Z]",
26+
'BG': "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
27+
'CR': "\\d{17}",
28+
'HR': "\\d{17}",
29+
'CY': "\\d{8}[\\dA-Z]{16}",
30+
'CZ': "\\d{20}",
31+
'DK': "\\d{14}",
32+
'DO': "[A-Z]{4}\\d{20}",
33+
'EE': "\\d{16}",
34+
'FO': "\\d{14}",
35+
'FI': "\\d{14}",
36+
'FR': "\\d{10}[\\dA-Z]{11}\\d{2}",
37+
'GE': "[\\dA-Z]{2}\\d{16}",
38+
'DE': "\\d{18}",
39+
'GI': "[A-Z]{4}[\\dA-Z]{15}",
40+
'GR': "\\d{7}[\\dA-Z]{16}",
41+
'GL': "\\d{14}",
42+
'GT': "[\\dA-Z]{4}[\\dA-Z]{20}",
43+
'HU': "\\d{24}",
44+
'IS': "\\d{22}",
45+
'IE': "[\\dA-Z]{4}\\d{14}",
46+
'IL': "\\d{19}",
47+
'IT': "[A-Z]\\d{10}[\\dA-Z]{12}",
48+
'KZ': "\\d{3}[\\dA-Z]{13}",
49+
'KW': "[A-Z]{4}[\\dA-Z]{22}",
50+
'LV': "[A-Z]{4}[\\dA-Z]{13}",
51+
'LB': "\\d{4}[\\dA-Z]{20}",
52+
'LI': "\\d{5}[\\dA-Z]{12}",
53+
'LT': "\\d{16}",
54+
'LU': "\\d{3}[\\dA-Z]{13}",
55+
'MK': "\\d{3}[\\dA-Z]{10}\\d{2}",
56+
'MT': "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
57+
'MR': "\\d{23}",
58+
'MU': "[A-Z]{4}\\d{19}[A-Z]{3}",
59+
'MC': "\\d{10}[\\dA-Z]{11}\\d{2}",
60+
'MD': "[\\dA-Z]{2}\\d{18}",
61+
'ME': "\\d{18}",
62+
'NL': "[A-Z]{4}\\d{10}",
63+
'NO': "\\d{11}",
64+
'PK': "[\\dA-Z]{4}\\d{16}",
65+
'PS': "[\\dA-Z]{4}\\d{21}",
66+
'PL': "\\d{24}",
67+
'PT': "\\d{21}",
68+
'RO': "[A-Z]{4}[\\dA-Z]{16}",
69+
'SM': "[A-Z]\\d{10}[\\dA-Z]{12}",
70+
'SA': "\\d{2}[\\dA-Z]{18}",
71+
'RS': "\\d{18}",
72+
'SK': "\\d{20}",
73+
'SI': "\\d{15}",
74+
'ES': "\\d{20}",
75+
'SE': "\\d{20}",
76+
'CH': "\\d{5}[\\dA-Z]{12}",
77+
'TN': "\\d{20}",
78+
'TR': "\\d{5}[\\dA-Z]{17}",
79+
'AE': "\\d{3}\\d{16}",
80+
'GB': "[A-Z]{4}\\d{14}",
81+
'VG': "[\\dA-Z]{4}\\d{16}"
82+
};
83+
var bbanpattern = bbancountrypatterns[countrycode];
84+
// As new countries will start using IBAN in the
85+
// future, we only check if the countrycode is known.
86+
// This prevents false negatives, while almost all
87+
// false positives introduced by this, will be caught
88+
// by the checksum validation below anyway.
89+
// Strict checking should return FALSE for unknown
90+
// countries.
91+
if (typeof bbanpattern !== 'undefined') {
92+
var ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", "");
93+
if (!(ibanregexp.test(iban))) {
94+
return false; // invalid country specific format
95+
}
96+
}
97+
98+
// now check the checksum, first convert to digits
99+
var ibancheck = iban.substring(4,iban.length) + iban.substring(0,4);
100+
var ibancheckdigits = "";
101+
var leadingZeroes = true;
102+
var charAt;
103+
for (var i =0; i<ibancheck.length; i++) {
104+
charAt = ibancheck.charAt(i);
105+
if (charAt !== "0") {
106+
leadingZeroes = false;
107+
}
108+
if (!leadingZeroes) {
109+
ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(charAt);
110+
}
111+
}
112+
113+
// calculate the result of: ibancheckdigits % 97
114+
var cRest = '';
115+
var cOperator = '';
116+
for (var p=0; p<ibancheckdigits.length; p++) {
117+
var cChar = ibancheckdigits.charAt(p);
118+
cOperator = '' + cRest + '' + cChar;
119+
cRest = cOperator % 97;
120+
}
121+
return cRest === 1;
122+
}, "Please specify a valid IBAN");

0 commit comments

Comments
 (0)