simple_client_validation 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/simple_client_validation/version.rb +1 -1
- data/vendor/assets/javascripts/iban.js +417 -0
- data/vendor/assets/javascripts/simple_client_validation.js +36 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0476ff3f53cf60abad18a3948a9ab56814223211
|
4
|
+
data.tar.gz: 077fabd24323145aabc8724a4a677678b2fe7444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 572e68d787027a1406c2a31295fded5d5cbccb1a54c7663d1fc40297396825e2e3a53639304dc019446c2ef6853b3450cbc36ed5e1d926b5e9ef7b68ef5e202a
|
7
|
+
data.tar.gz: 7062563098866e8ea520a731078d38eb04ecd725b442e6ba39f5449a8571146eb27f97b225d7d1187fed661293c2221217614c2a280c7581ceb2e73698126e7e
|
data/README.md
CHANGED
@@ -35,9 +35,11 @@ and after that add the simple_client_validation styles
|
|
35
35
|
*= require simple_client_validation
|
36
36
|
*/
|
37
37
|
```
|
38
|
-
Require simple_client_validation Javascripts in `application.js`:
|
38
|
+
Require iban and simple_client_validation Javascripts in `application.js`:
|
39
|
+
(iban goes first)
|
39
40
|
|
40
41
|
```js
|
42
|
+
//= require iban
|
41
43
|
//= require simple_client_validation
|
42
44
|
```
|
43
45
|
Then restart your webserver if it was previously running.
|
@@ -0,0 +1,417 @@
|
|
1
|
+
(function (root, factory) {
|
2
|
+
if (typeof define === 'function' && define.amd) {
|
3
|
+
// AMD. Register as an anonymous module.
|
4
|
+
define(['exports'], factory);
|
5
|
+
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
|
6
|
+
// CommonJS
|
7
|
+
factory(exports);
|
8
|
+
} else {
|
9
|
+
// Browser globals
|
10
|
+
factory(root.IBAN = {});
|
11
|
+
}
|
12
|
+
}(this, function(exports){
|
13
|
+
|
14
|
+
// Array.prototype.map polyfill
|
15
|
+
// code from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map
|
16
|
+
if (!Array.prototype.map){
|
17
|
+
Array.prototype.map = function(fun /*, thisArg */){
|
18
|
+
"use strict";
|
19
|
+
|
20
|
+
if (this === void 0 || this === null)
|
21
|
+
throw new TypeError();
|
22
|
+
|
23
|
+
var t = Object(this);
|
24
|
+
var len = t.length >>> 0;
|
25
|
+
if (typeof fun !== "function")
|
26
|
+
throw new TypeError();
|
27
|
+
|
28
|
+
var res = new Array(len);
|
29
|
+
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
|
30
|
+
for (var i = 0; i < len; i++)
|
31
|
+
{
|
32
|
+
// NOTE: Absolute correctness would demand Object.defineProperty
|
33
|
+
// be used. But this method is fairly new, and failure is
|
34
|
+
// possible only if Object.prototype or Array.prototype
|
35
|
+
// has a property |i| (very unlikely), so use a less-correct
|
36
|
+
// but more portable alternative.
|
37
|
+
if (i in t)
|
38
|
+
res[i] = fun.call(thisArg, t[i], i, t);
|
39
|
+
}
|
40
|
+
|
41
|
+
return res;
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
var A = 'A'.charCodeAt(0),
|
46
|
+
Z = 'Z'.charCodeAt(0);
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
|
50
|
+
* numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
|
51
|
+
*
|
52
|
+
* @param {string} iban the IBAN
|
53
|
+
* @returns {string} the prepared IBAN
|
54
|
+
*/
|
55
|
+
function iso13616Prepare(iban) {
|
56
|
+
iban = iban.toUpperCase();
|
57
|
+
iban = iban.substr(4) + iban.substr(0,4);
|
58
|
+
|
59
|
+
return iban.split('').map(function(n){
|
60
|
+
var code = n.charCodeAt(0);
|
61
|
+
if (code >= A && code <= Z){
|
62
|
+
// A = 10, B = 11, ... Z = 35
|
63
|
+
return code - A + 10;
|
64
|
+
} else {
|
65
|
+
return n;
|
66
|
+
}
|
67
|
+
}).join('');
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
|
72
|
+
*
|
73
|
+
* @param iban
|
74
|
+
* @returns {number}
|
75
|
+
*/
|
76
|
+
function iso7064Mod97_10(iban) {
|
77
|
+
var remainder = iban,
|
78
|
+
block;
|
79
|
+
|
80
|
+
while (remainder.length > 2){
|
81
|
+
block = remainder.slice(0, 9);
|
82
|
+
remainder = parseInt(block, 10) % 97 + remainder.slice(block.length);
|
83
|
+
}
|
84
|
+
|
85
|
+
return parseInt(remainder, 10) % 97;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Parse the BBAN structure used to configure each IBAN Specification and returns a matching regular expression.
|
90
|
+
* A structure is composed of blocks of 3 characters (one letter and 2 digits). Each block represents
|
91
|
+
* a logical group in the typical representation of the BBAN. For each group, the letter indicates which characters
|
92
|
+
* are allowed in this group and the following 2-digits number tells the length of the group.
|
93
|
+
*
|
94
|
+
* @param {string} structure the structure to parse
|
95
|
+
* @returns {RegExp}
|
96
|
+
*/
|
97
|
+
function parseStructure(structure){
|
98
|
+
// split in blocks of 3 chars
|
99
|
+
var regex = structure.match(/(.{3})/g).map(function(block){
|
100
|
+
|
101
|
+
// parse each structure block (1-char + 2-digits)
|
102
|
+
var format,
|
103
|
+
pattern = block.slice(0, 1),
|
104
|
+
repeats = parseInt(block.slice(1), 10);
|
105
|
+
|
106
|
+
switch (pattern){
|
107
|
+
case "A": format = "0-9A-Za-z"; break;
|
108
|
+
case "B": format = "0-9A-Z"; break;
|
109
|
+
case "C": format = "A-Za-z"; break;
|
110
|
+
case "F": format = "0-9"; break;
|
111
|
+
case "L": format = "a-z"; break;
|
112
|
+
case "U": format = "A-Z"; break;
|
113
|
+
case "W": format = "0-9a-z"; break;
|
114
|
+
}
|
115
|
+
|
116
|
+
return '([' + format + ']{' + repeats + '})';
|
117
|
+
});
|
118
|
+
|
119
|
+
return new RegExp('^' + regex.join('') + '$');
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
*
|
124
|
+
* @param iban
|
125
|
+
* @returns {string}
|
126
|
+
*/
|
127
|
+
function electronicFormat(iban){
|
128
|
+
return iban.replace(NON_ALPHANUM, '').toUpperCase();
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Create a new Specification for a valid IBAN number.
|
134
|
+
*
|
135
|
+
* @param countryCode the code of the country
|
136
|
+
* @param length the length of the IBAN
|
137
|
+
* @param structure the structure of the underlying BBAN (for validation and formatting)
|
138
|
+
* @param example an example valid IBAN
|
139
|
+
* @constructor
|
140
|
+
*/
|
141
|
+
function Specification(countryCode, length, structure, example){
|
142
|
+
|
143
|
+
this.countryCode = countryCode;
|
144
|
+
this.length = length;
|
145
|
+
this.structure = structure;
|
146
|
+
this.example = example;
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Lazy-loaded regex (parse the structure and construct the regular expression the first time we need it for validation)
|
151
|
+
*/
|
152
|
+
Specification.prototype._regex = function(){
|
153
|
+
return this._cachedRegex || (this._cachedRegex = parseStructure(this.structure))
|
154
|
+
};
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Check if the passed iban is valid according to this specification.
|
158
|
+
*
|
159
|
+
* @param {String} iban the iban to validate
|
160
|
+
* @returns {boolean} true if valid, false otherwise
|
161
|
+
*/
|
162
|
+
Specification.prototype.isValid = function(iban){
|
163
|
+
return this.length == iban.length
|
164
|
+
&& this.countryCode === iban.slice(0,2)
|
165
|
+
&& this._regex().test(iban.slice(4))
|
166
|
+
&& iso7064Mod97_10(iso13616Prepare(iban)) == 1;
|
167
|
+
};
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Convert the passed IBAN to a country-specific BBAN.
|
171
|
+
*
|
172
|
+
* @param iban the IBAN to convert
|
173
|
+
* @param separator the separator to use between BBAN blocks
|
174
|
+
* @returns {string} the BBAN
|
175
|
+
*/
|
176
|
+
Specification.prototype.toBBAN = function(iban, separator) {
|
177
|
+
return this._regex().exec(iban.slice(4)).slice(1).join(separator);
|
178
|
+
};
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Convert the passed BBAN to an IBAN for this country specification.
|
182
|
+
* Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
|
183
|
+
* This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
|
184
|
+
*
|
185
|
+
* @param bban the BBAN to convert to IBAN
|
186
|
+
* @returns {string} the IBAN
|
187
|
+
*/
|
188
|
+
Specification.prototype.fromBBAN = function(bban) {
|
189
|
+
if (!this.isValidBBAN(bban)){
|
190
|
+
throw new Error('Invalid BBAN');
|
191
|
+
}
|
192
|
+
|
193
|
+
var remainder = iso7064Mod97_10(iso13616Prepare(this.countryCode + '00' + bban)),
|
194
|
+
checkDigit = ('0' + (98 - remainder)).slice(-2);
|
195
|
+
|
196
|
+
return this.countryCode + checkDigit + bban;
|
197
|
+
};
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Check of the passed BBAN is valid.
|
201
|
+
* This function only checks the format of the BBAN (length and matching the letetr/number specs) but does not
|
202
|
+
* verify the check digit.
|
203
|
+
*
|
204
|
+
* @param bban the BBAN to validate
|
205
|
+
* @returns {boolean} true if the passed bban is a valid BBAN according to this specification, false otherwise
|
206
|
+
*/
|
207
|
+
Specification.prototype.isValidBBAN = function(bban) {
|
208
|
+
return this.length - 4 == bban.length
|
209
|
+
&& this._regex().test(bban);
|
210
|
+
};
|
211
|
+
|
212
|
+
var countries = {};
|
213
|
+
|
214
|
+
function addSpecification(IBAN){
|
215
|
+
countries[IBAN.countryCode] = IBAN;
|
216
|
+
}
|
217
|
+
|
218
|
+
addSpecification(new Specification("AD", 24, "F04F04A12", "AD1200012030200359100100"));
|
219
|
+
addSpecification(new Specification("AE", 23, "F03F16", "AE070331234567890123456"));
|
220
|
+
addSpecification(new Specification("AL", 28, "F08A16", "AL47212110090000000235698741"));
|
221
|
+
addSpecification(new Specification("AT", 20, "F05F11", "AT611904300234573201"));
|
222
|
+
addSpecification(new Specification("AZ", 28, "U04A20", "AZ21NABZ00000000137010001944"));
|
223
|
+
addSpecification(new Specification("BA", 20, "F03F03F08F02", "BA391290079401028494"));
|
224
|
+
addSpecification(new Specification("BE", 16, "F03F07F02", "BE68539007547034"));
|
225
|
+
addSpecification(new Specification("BG", 22, "U04F04F02A08", "BG80BNBG96611020345678"));
|
226
|
+
addSpecification(new Specification("BH", 22, "U04A14", "BH67BMAG00001299123456"));
|
227
|
+
addSpecification(new Specification("BR", 29, "F08F05F10U01A01", "BR9700360305000010009795493P1"));
|
228
|
+
addSpecification(new Specification("CH", 21, "F05A12", "CH9300762011623852957"));
|
229
|
+
addSpecification(new Specification("CR", 22, "F04F14", "CR72012300000171549015"));
|
230
|
+
addSpecification(new Specification("CY", 28, "F03F05A16", "CY17002001280000001200527600"));
|
231
|
+
addSpecification(new Specification("CZ", 24, "F04F06F10", "CZ6508000000192000145399"));
|
232
|
+
addSpecification(new Specification("DE", 22, "F08F10", "DE89370400440532013000"));
|
233
|
+
addSpecification(new Specification("DK", 18, "F04F09F01", "DK5000400440116243"));
|
234
|
+
addSpecification(new Specification("DO", 28, "U04F20", "DO28BAGR00000001212453611324"));
|
235
|
+
addSpecification(new Specification("EE", 20, "F02F02F11F01", "EE382200221020145685"));
|
236
|
+
addSpecification(new Specification("ES", 24, "F04F04F01F01F10", "ES9121000418450200051332"));
|
237
|
+
addSpecification(new Specification("FI", 18, "F06F07F01", "FI2112345600000785"));
|
238
|
+
addSpecification(new Specification("FO", 18, "F04F09F01", "FO6264600001631634"));
|
239
|
+
addSpecification(new Specification("FR", 27, "F05F05A11F02", "FR1420041010050500013M02606"));
|
240
|
+
addSpecification(new Specification("GB", 22, "U04F06F08", "GB29NWBK60161331926819"));
|
241
|
+
addSpecification(new Specification("GE", 22, "U02F16", "GE29NB0000000101904917"));
|
242
|
+
addSpecification(new Specification("GI", 23, "U04A15", "GI75NWBK000000007099453"));
|
243
|
+
addSpecification(new Specification("GL", 18, "F04F09F01", "GL8964710001000206"));
|
244
|
+
addSpecification(new Specification("GR", 27, "F03F04A16", "GR1601101250000000012300695"));
|
245
|
+
addSpecification(new Specification("GT", 28, "A04A20", "GT82TRAJ01020000001210029690"));
|
246
|
+
addSpecification(new Specification("HR", 21, "F07F10", "HR1210010051863000160"));
|
247
|
+
addSpecification(new Specification("HU", 28, "F03F04F01F15F01", "HU42117730161111101800000000"));
|
248
|
+
addSpecification(new Specification("IE", 22, "U04F06F08", "IE29AIBK93115212345678"));
|
249
|
+
addSpecification(new Specification("IL", 23, "F03F03F13", "IL620108000000099999999"));
|
250
|
+
addSpecification(new Specification("IS", 26, "F04F02F06F10", "IS140159260076545510730339"));
|
251
|
+
addSpecification(new Specification("IT", 27, "U01F05F05A12", "IT60X0542811101000000123456"));
|
252
|
+
addSpecification(new Specification("KW", 30, "U04A22", "KW81CBKU0000000000001234560101"));
|
253
|
+
addSpecification(new Specification("KZ", 20, "F03A13", "KZ86125KZT5004100100"));
|
254
|
+
addSpecification(new Specification("LB", 28, "F04A20", "LB62099900000001001901229114"));
|
255
|
+
addSpecification(new Specification("LC", 32, "U04F24", "LC07HEMM000100010012001200013015"));
|
256
|
+
addSpecification(new Specification("LI", 21, "F05A12", "LI21088100002324013AA"));
|
257
|
+
addSpecification(new Specification("LT", 20, "F05F11", "LT121000011101001000"));
|
258
|
+
addSpecification(new Specification("LU", 20, "F03A13", "LU280019400644750000"));
|
259
|
+
addSpecification(new Specification("LV", 21, "U04A13", "LV80BANK0000435195001"));
|
260
|
+
addSpecification(new Specification("MC", 27, "F05F05A11F02", "MC5811222000010123456789030"));
|
261
|
+
addSpecification(new Specification("MD", 24, "U02A18", "MD24AG000225100013104168"));
|
262
|
+
addSpecification(new Specification("ME", 22, "F03F13F02", "ME25505000012345678951"));
|
263
|
+
addSpecification(new Specification("MK", 19, "F03A10F02", "MK07250120000058984"));
|
264
|
+
addSpecification(new Specification("MR", 27, "F05F05F11F02", "MR1300020001010000123456753"));
|
265
|
+
addSpecification(new Specification("MT", 31, "U04F05A18", "MT84MALT011000012345MTLCAST001S"));
|
266
|
+
addSpecification(new Specification("MU", 30, "U04F02F02F12F03U03", "MU17BOMM0101101030300200000MUR"));
|
267
|
+
addSpecification(new Specification("NL", 18, "U04F10", "NL91ABNA0417164300"));
|
268
|
+
addSpecification(new Specification("NO", 15, "F04F06F01", "NO9386011117947"));
|
269
|
+
addSpecification(new Specification("PK", 24, "U04A16", "PK36SCBL0000001123456702"));
|
270
|
+
addSpecification(new Specification("PL", 28, "F08F16", "PL61109010140000071219812874"));
|
271
|
+
addSpecification(new Specification("PS", 29, "U04A21", "PS92PALS000000000400123456702"));
|
272
|
+
addSpecification(new Specification("PT", 25, "F04F04F11F02", "PT50000201231234567890154"));
|
273
|
+
addSpecification(new Specification("RO", 24, "U04A16", "RO49AAAA1B31007593840000"));
|
274
|
+
addSpecification(new Specification("RS", 22, "F03F13F02", "RS35260005601001611379"));
|
275
|
+
addSpecification(new Specification("SA", 24, "F02A18", "SA0380000000608010167519"));
|
276
|
+
addSpecification(new Specification("SE", 24, "F03F16F01", "SE4550000000058398257466"));
|
277
|
+
addSpecification(new Specification("SI", 19, "F05F08F02", "SI56263300012039086"));
|
278
|
+
addSpecification(new Specification("SK", 24, "F04F06F10", "SK3112000000198742637541"));
|
279
|
+
addSpecification(new Specification("SM", 27, "U01F05F05A12", "SM86U0322509800000000270100"));
|
280
|
+
addSpecification(new Specification("ST", 25, "F08F11F02", "ST68000100010051845310112"));
|
281
|
+
addSpecification(new Specification("TL", 23, "F03F14F02", "TL380080012345678910157"));
|
282
|
+
addSpecification(new Specification("TN", 24, "F02F03F13F02", "TN5910006035183598478831"));
|
283
|
+
addSpecification(new Specification("TR", 26, "F05F01A16", "TR330006100519786457841326"));
|
284
|
+
addSpecification(new Specification("VG", 24, "U04F16", "VG96VPVG0000012345678901"));
|
285
|
+
addSpecification(new Specification("XK", 20, "F04F10F02", "XK051212012345678906"));
|
286
|
+
|
287
|
+
// Angola
|
288
|
+
addSpecification(new Specification("AO", 25, "F21", "AO69123456789012345678901"));
|
289
|
+
// Burkina
|
290
|
+
addSpecification(new Specification("BF", 27, "F23", "BF2312345678901234567890123"));
|
291
|
+
// Burundi
|
292
|
+
addSpecification(new Specification("BI", 16, "F12", "BI41123456789012"));
|
293
|
+
// Benin
|
294
|
+
addSpecification(new Specification("BJ", 28, "F24", "BJ39123456789012345678901234"));
|
295
|
+
// Ivory
|
296
|
+
addSpecification(new Specification("CI", 28, "U01F23", "CI17A12345678901234567890123"));
|
297
|
+
// Cameron
|
298
|
+
addSpecification(new Specification("CM", 27, "F23", "CM9012345678901234567890123"));
|
299
|
+
// Cape Verde
|
300
|
+
addSpecification(new Specification("CV", 25, "F21", "CV30123456789012345678901"));
|
301
|
+
// Algeria
|
302
|
+
addSpecification(new Specification("DZ", 24, "F20", "DZ8612345678901234567890"));
|
303
|
+
// Iran
|
304
|
+
addSpecification(new Specification("IR", 26, "F22", "IR861234568790123456789012"));
|
305
|
+
// Jordan
|
306
|
+
addSpecification(new Specification("JO", 30, "A04F22", "JO15AAAA1234567890123456789012"));
|
307
|
+
// Madagascar
|
308
|
+
addSpecification(new Specification("MG", 27, "F23", "MG1812345678901234567890123"));
|
309
|
+
// Mali
|
310
|
+
addSpecification(new Specification("ML", 28, "U01F23", "ML15A12345678901234567890123"));
|
311
|
+
// Mozambique
|
312
|
+
addSpecification(new Specification("MZ", 25, "F21", "MZ25123456789012345678901"));
|
313
|
+
// Quatar
|
314
|
+
addSpecification(new Specification("QA", 29, "U04A21", "QA30AAAA123456789012345678901"));
|
315
|
+
// Senegal
|
316
|
+
addSpecification(new Specification("SN", 28, "U01F23", "SN52A12345678901234567890123"));
|
317
|
+
// Ukraine
|
318
|
+
addSpecification(new Specification("UA", 29, "F25", "UA511234567890123456789012345"));
|
319
|
+
|
320
|
+
var NON_ALPHANUM = /[^a-zA-Z0-9]/g,
|
321
|
+
EVERY_FOUR_CHARS =/(.{4})(?!$)/g;
|
322
|
+
|
323
|
+
/**
|
324
|
+
* Utility function to check if a variable is a String.
|
325
|
+
*
|
326
|
+
* @param v
|
327
|
+
* @returns {boolean} true if the passed variable is a String, false otherwise.
|
328
|
+
*/
|
329
|
+
function isString(v){
|
330
|
+
return (typeof v == 'string' || v instanceof String);
|
331
|
+
}
|
332
|
+
|
333
|
+
/**
|
334
|
+
* Check if an IBAN is valid.
|
335
|
+
*
|
336
|
+
* @param {String} iban the IBAN to validate.
|
337
|
+
* @returns {boolean} true if the passed IBAN is valid, false otherwise
|
338
|
+
*/
|
339
|
+
exports.isValid = function(iban){
|
340
|
+
if (!isString(iban)){
|
341
|
+
return false;
|
342
|
+
}
|
343
|
+
iban = electronicFormat(iban);
|
344
|
+
var countryStructure = countries[iban.slice(0,2)];
|
345
|
+
return !!countryStructure && countryStructure.isValid(iban);
|
346
|
+
};
|
347
|
+
|
348
|
+
/**
|
349
|
+
* Convert an IBAN to a BBAN.
|
350
|
+
*
|
351
|
+
* @param iban
|
352
|
+
* @param {String} [separator] the separator to use between the blocks of the BBAN, defaults to ' '
|
353
|
+
* @returns {string|*}
|
354
|
+
*/
|
355
|
+
exports.toBBAN = function(iban, separator){
|
356
|
+
if (typeof separator == 'undefined'){
|
357
|
+
separator = ' ';
|
358
|
+
}
|
359
|
+
iban = electronicFormat(iban);
|
360
|
+
var countryStructure = countries[iban.slice(0,2)];
|
361
|
+
if (!countryStructure) {
|
362
|
+
throw new Error('No country with code ' + iban.slice(0,2));
|
363
|
+
}
|
364
|
+
return countryStructure.toBBAN(iban, separator);
|
365
|
+
};
|
366
|
+
|
367
|
+
/**
|
368
|
+
* Convert the passed BBAN to an IBAN for this country specification.
|
369
|
+
* Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
|
370
|
+
* This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
|
371
|
+
*
|
372
|
+
* @param countryCode the country of the BBAN
|
373
|
+
* @param bban the BBAN to convert to IBAN
|
374
|
+
* @returns {string} the IBAN
|
375
|
+
*/
|
376
|
+
exports.fromBBAN = function(countryCode, bban){
|
377
|
+
var countryStructure = countries[countryCode];
|
378
|
+
if (!countryStructure) {
|
379
|
+
throw new Error('No country with code ' + countryCode);
|
380
|
+
}
|
381
|
+
return countryStructure.fromBBAN(electronicFormat(bban));
|
382
|
+
};
|
383
|
+
|
384
|
+
/**
|
385
|
+
* Check the validity of the passed BBAN.
|
386
|
+
*
|
387
|
+
* @param countryCode the country of the BBAN
|
388
|
+
* @param bban the BBAN to check the validity of
|
389
|
+
*/
|
390
|
+
exports.isValidBBAN = function(countryCode, bban){
|
391
|
+
if (!isString(bban)){
|
392
|
+
return false;
|
393
|
+
}
|
394
|
+
var countryStructure = countries[countryCode];
|
395
|
+
return countryStructure && countryStructure.isValidBBAN(electronicFormat(bban));
|
396
|
+
};
|
397
|
+
|
398
|
+
/**
|
399
|
+
*
|
400
|
+
* @param iban
|
401
|
+
* @param separator
|
402
|
+
* @returns {string}
|
403
|
+
*/
|
404
|
+
exports.printFormat = function(iban, separator){
|
405
|
+
if (typeof separator == 'undefined'){
|
406
|
+
separator = ' ';
|
407
|
+
}
|
408
|
+
return electronicFormat(iban).replace(EVERY_FOUR_CHARS, "$1" + separator);
|
409
|
+
};
|
410
|
+
|
411
|
+
exports.electronicFormat = electronicFormat;
|
412
|
+
/**
|
413
|
+
* An object containing all the known IBAN specifications.
|
414
|
+
*/
|
415
|
+
exports.countries = countries;
|
416
|
+
|
417
|
+
}));
|
@@ -91,6 +91,42 @@ $(document).on("turbolinks:load", function(){
|
|
91
91
|
|
92
92
|
});
|
93
93
|
});
|
94
|
+
// Check for ONE IBAN input in the from
|
95
|
+
var ibanBox = $('*[name*=iban')[0];
|
96
|
+
if (ibanBox != null) {
|
97
|
+
ibanBox.onkeyup = function(){
|
98
|
+
if(IBAN.isValid(ibanBox.value)){
|
99
|
+
try {
|
100
|
+
var id_to_remove = "added-error" + ibanBox.id;
|
101
|
+
document.getElementById(id_to_remove).remove();
|
102
|
+
} catch (e) {
|
103
|
+
console.log("Continue ...");
|
104
|
+
}
|
105
|
+
var error_message = "Valid IBAN.";
|
106
|
+
var element_id = ibanBox.id;
|
107
|
+
var el = document.createElement("span");
|
108
|
+
el.innerHTML = error_message;
|
109
|
+
el.id = "added-error" + element_id;
|
110
|
+
var div = document.getElementById(element_id);
|
111
|
+
insertAfter(div, el);
|
112
|
+
}else{
|
113
|
+
try {
|
114
|
+
var id_to_remove = "added-error" + ibanBox.id;
|
115
|
+
document.getElementById(id_to_remove).remove();
|
116
|
+
} catch (e) {
|
117
|
+
console.log("Continue ...");
|
118
|
+
}
|
119
|
+
var error_message = "Not valid IBAN.";
|
120
|
+
var element_id = ibanBox.id;
|
121
|
+
var el = document.createElement("span");
|
122
|
+
el.innerHTML = '<i class="fa fa-times" aria-hidden="true"></i>' + " " + error_message;
|
123
|
+
el.id = "added-error" + element_id;
|
124
|
+
el.className += " scv-error-message";
|
125
|
+
var div = document.getElementById(element_id);
|
126
|
+
insertAfter(div, el);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
94
130
|
// add error message after input
|
95
131
|
function insertAfter(referenceNode, newNode) {
|
96
132
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_client_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petar Risteski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/simple_client_validation.rb
|
56
56
|
- lib/simple_client_validation/version.rb
|
57
57
|
- simple_client_validation.gemspec
|
58
|
+
- vendor/assets/javascripts/iban.js
|
58
59
|
- vendor/assets/javascripts/simple_client_validation.js
|
59
60
|
- vendor/assets/stylesheets/simple_client_validation.css
|
60
61
|
homepage: https://github.com/bobpetar/simple_client_validation
|