From 2f7a364bbf9f75f4a6a8a09555d7a719e9ba648e Mon Sep 17 00:00:00 2001 From: Mark Manders Date: Wed, 17 Sep 2014 11:49:14 +0200 Subject: [PATCH] added country name to ngIbanCountries constant --- bower.json | 2 +- dist/ng-iban.js | 350 ++++++++++++++++++++++++++++++++++---------- dist/ng-iban.min.js | 2 +- package.json | 2 +- src/ng-iban.coffee | 284 +++++++++++++++++++++++++---------- 5 files changed, 485 insertions(+), 155 deletions(-) diff --git a/bower.json b/bower.json index e8b0e54..43e57b4 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ng-iban", - "version": "0.2.5", + "version": "0.2.6", "authors": [ "Mark Manders " ], diff --git a/dist/ng-iban.js b/dist/ng-iban.js index 1fdd61b..7749766 100644 --- a/dist/ng-iban.js +++ b/dist/ng-iban.js @@ -3,72 +3,270 @@ var __modulo = function(a, b) { return (a % b + +b) % b; }; angular.module('mm.iban', ['ng']).constant('ngIbanCountries', { - AL: /^AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}$/, - AD: /^AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}$/, - AT: /^AT[0-9]{2}[0-9]{5}[0-9]{11}$/, - AZ: /^AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}$/, - BH: /^BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}$/, - BE: /^BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}$/, - BA: /^BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}$/, - BR: /^BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}$/, - BG: /^BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}$/, - CR: /^CR[0-9]{2}[0-9]{3}[0-9]{14}$/, - HR: /^HR[0-9]{2}[0-9]{7}[0-9]{10}$/, - CY: /^CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z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$/, - SE: /^SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}$/, - CH: /^CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}$/, - TL: /^TL[0-9]{2}[0-9]{3}[0-9]{14}[0-9]{2}$/, - TN: /^TN[0-9]{2}[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/, - TR: /^TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}$/, - AE: /^AE[0-9]{2}[0-9]{3}[0-9]{16}$/, - GB: /^GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}$/, - VG: /^VG[0-9]{2}[A-Z]{4}[0-9]{16}$/ + AL: { + name: 'Albania', + regex: /^AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}$/ + }, + AD: { + name: 'Andorra', + regex: /^AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}$/ + }, + AT: { + name: 'Austria', + regex: /^AT[0-9]{2}[0-9]{5}[0-9]{11}$/ + }, + AZ: { + name: 'Azerbaijan, Republic of', + regex: /^AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}$/ + }, + BH: { + name: 'Bahrain', + regex: /^BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}$/ + }, + BE: { + name: 'Belgium', + regex: /^BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}$/ + }, + BA: { + name: 'Bosnia and Herzegovina', + regex: /^BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}$/ + }, + BR: { + name: 'Brazil', + regex: /^BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}$/ + }, + BG: { + name: 'Bulgaria', + regex: /^BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}$/ + }, + CR: { + name: 'Costa Rica', + regex: /^CR[0-9]{2}[0-9]{3}[0-9]{14}$/ + }, + HR: { + name: 'Croatia', + regex: /^HR[0-9]{2}[0-9]{7}[0-9]{10}$/ + }, + CY: { + name: 'Cyprus', + regex: /^CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}$/ + }, + CZ: { + name: 'Czech Republic', + regex: /^CZ[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}$/ + }, + DK: { + name: 'Denmark', + regex: /^DK[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/ + }, + DO: { + name: 'Dominican Republic', + regex: /^DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}$/ + }, + EE: { + name: 'Estonia', + regex: /^EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}$/ + }, + FO: { + name: 'Faroe Islands', + regex: /^FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/ + }, + FI: { + name: 'Finland', + regex: /^FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}$/ + }, + FR: { + name: 'France', + regex: /^FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}$/ + }, + GE: { + name: 'Georgia', + regex: /^GE[0-9]{2}[A-Z]{2}[0-9]{16}$/ + }, + DE: { + name: 'Germany', + regex: /^DE[0-9]{2}[0-9]{8}[0-9]{10}$/ + }, + GI: { + name: 'Gibraltar', + regex: /^GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}$/ + }, + GR: { + name: 'Greece', + regex: /^GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}$/ + }, + GL: { + name: 'Greenland', + regex: /^GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/ + }, + GT: { + name: 'Guatemala', + regex: /^GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}$/ + }, + HU: { + name: 'Hungary', + regex: /^HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}$/ + }, + IS: { + name: 'Iceland', + regex: /^IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}$/ + }, + IE: { + name: 'Ireland', + regex: /^IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}$/ + }, + IL: { + name: 'Israel', + regex: /^IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}$/ + }, + IT: { + name: 'Italy', + regex: /^IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}$/ + }, + KZ: { + name: 'Kazakhstan', + regex: /^KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}$/ + }, + KW: { + name: 'Kuwait', + regex: /^KW[0-9]{2}[A-Z]{4}[A-Z0-9]{22}$/ + }, + LV: { + name: 'Latvia', + regex: /^LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}$/ + }, + LB: { + name: 'Lebanon', + regex: /^LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}$/ + }, + LI: { + name: 'Liechtenstein (Principality of)', + regex: /^LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}$/ + }, + LT: { + name: 'Lithuania', + regex: /^LT[0-9]{2}[0-9]{5}[0-9]{11}$/ + }, + LU: { + name: 'Luxembourg', + regex: /^LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}$/ + }, + MK: { + name: 'Macedonia', + regex: /^MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}$/ + }, + MT: { + name: 'Malta', + regex: /^MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}$/ + }, + MR: { + name: 'Mauritania', + regex: /^MR[0-9]{2}[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}$/ + }, + MU: { + name: 'Mauritius', + regex: /^MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}$/ + }, + MD: { + name: 'Moldova, Republic of', + regex: /^MD[0-9]{2}[A-Z0-9]{20}$/ + }, + MC: { + name: 'Monaco', + regex: /^MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}$/ + }, + ME: { + name: 'Montenegro', + regex: /^ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/ + }, + NL: { + name: 'Netherlands', + regex: /^NL[0-9]{2}[A-Z]{4}[0-9]{10}$/ + }, + NO: { + name: 'Norway', + regex: /^NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}$/ + }, + PK: { + name: 'Pakistan', + regex: /^PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}$/ + }, + PL: { + name: 'Poland', + regex: /^PL[0-9]{2}[0-9]{8}[0-9]{16}$/ + }, + PS: { + name: 'Palestinian Territory, Occupied', + regex: /^PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}$/ + }, + PT: { + name: 'Portugal', + regex: /^PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}$/ + }, + QA: { + name: 'Qatar', + regex: /^QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}$/ + }, + RO: { + name: 'Romania', + regex: /^RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}$/ + }, + SM: { + name: 'San Marino', + regex: /^SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}$/ + }, + SA: { + name: 'Saudi Arabia', + regex: /^SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}$/ + }, + RS: { + name: 'Serbia', + regex: /^RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/ + }, + SK: { + name: 'Slovak Republic', + regex: /^SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}$/ + }, + SI: { + name: 'Slovenia', + regex: /^SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}$/ + }, + ES: { + name: 'Spain', + regex: /^ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}$/ + }, + SE: { + name: 'Sweden', + regex: /^SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}$/ + }, + CH: { + name: 'Switzerland', + regex: /^CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}$/ + }, + TL: { + name: 'Timor-Leste', + regex: /^TL[0-9]{2}[0-9]{3}[0-9]{14}[0-9]{2}$/ + }, + TN: { + name: 'Tunisia', + regex: /^TN[0-9]{2}[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/ + }, + TR: { + name: 'Turkey', + regex: /^TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}$/ + }, + AE: { + name: 'United Arab Emirates', + regex: /^AE[0-9]{2}[0-9]{3}[0-9]{16}$/ + }, + GB: { + name: 'United Kingdom', + regex: /^GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}$/ + }, + VG: { + name: 'Virgin Islands, British', + regex: /^VG[0-9]{2}[A-Z]{4}[0-9]{16}$/ + } }).directive('ngIban', ["ngIbanCountries", function(ngIbanCountries) { return { restrict: 'A', @@ -90,7 +288,7 @@ A = 'A'.charCodeAt(0); Z = 'Z'.charCodeAt(0); iban = parseIban(value); - if (attrs.ngIban !== '' && (!!!(attrs.ngIban in ngIbanCountries) || !ngIbanCountries[attrs.ngIban].test(iban))) { + if (attrs.ngIban !== '' && (!!!(attrs.ngIban in ngIbanCountries) || !ngIbanCountries[attrs.ngIban].regex.test(iban))) { return false; } iban = iban.substr(4) + iban.substr(0, 4); @@ -109,13 +307,13 @@ } return __modulo(parseInt(remainder, 10), 97) === 1; }; - ctrl.$parsers.unshift(function(value) { + ctrl.$parsers.unshift(function(viewValue) { var parsed, valid; - valid = isValidIban(value); + valid = isValidIban(viewValue); ctrl.$setValidity('iban', valid); if (valid) { - parsed = parseIban(value); - if (parsed !== value) { + parsed = parseIban(viewValue); + if (parsed !== viewValue) { ctrl.$setViewValue(parsed); ctrl.$render(); } @@ -124,18 +322,18 @@ return void 0; } }); - return ctrl.$formatters.unshift(function(value) { + return ctrl.$formatters.unshift(function(modelValue) { var parsed, valid; - valid = isValidIban(value); + valid = isValidIban(modelValue); ctrl.$setValidity('iban', valid); if (valid) { - parsed = parseIban(value); - if (parsed !== value) { + parsed = parseIban(modelValue); + if (parsed !== modelValue) { scope[attrs.ngModel] = parsed; } return parsed; } else { - return value; + return modelValue; } }); } diff --git a/dist/ng-iban.min.js b/dist/ng-iban.min.js index 83b8ee4..9eed5fb 100644 --- a/dist/ng-iban.min.js +++ b/dist/ng-iban.min.js @@ -1 +1 @@ -(function(){"use strict";var a=function(a,b){return(a%b+ +b)%b};angular.module("mm.iban",["ng"]).constant("ngIbanCountries",{AL:/^AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}$/,AD:/^AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}$/,AT:/^AT[0-9]{2}[0-9]{5}[0-9]{11}$/,AZ:/^AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}$/,BH:/^BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}$/,BE:/^BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}$/,BA:/^BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}$/,BR:/^BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}$/,BG:/^BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}$/,CR:/^CR[0-9]{2}[0-9]{3}[0-9]{14}$/,HR:/^HR[0-9]{2}[0-9]{7}[0-9]{10}$/,CY:/^CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}$/,CZ:/^CZ[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}$/,DK:/^DK[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/,DO:/^DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}$/,EE:/^EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}$/,FO:/^FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/,FI:/^FI[0-9]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0-9]{6}[0-9]{8}$/,VG:/^VG[0-9]{2}[A-Z]{4}[0-9]{16}$/}).directive("ngIban",["ngIbanCountries",function(b){return{restrict:"A",require:"ngModel",link:function(c,d,e,f){var g,h;return h=function(a){return null!=a?a.toUpperCase().replace(/\s/g,""):void 0},g=function(c){var d,f,g,i,j;if(null==c)return!0;if(d="A".charCodeAt(0),f="Z".charCodeAt(0),i=h(c),!(""===e.ngIban||e.ngIban in b&&b[e.ngIban].test(i)))return!1;for(i=i.substr(4)+i.substr(0,4),j=i.split("").map(function(a){var b;return b=a.charCodeAt(0),b>=d&&f>=b?b-d+10:a}).join("");j.length>2;)g=j.slice(0,9),j=a(parseInt(g,10),97)+j.slice(g.length);return 1===a(parseInt(j,10),97)},f.$parsers.unshift(function(a){var b,c;return c=g(a),f.$setValidity("iban",c),c?(b=h(a),b!==a&&(f.$setViewValue(b),f.$render()),b):void 0}),f.$formatters.unshift(function(a){var b,d;return d=g(a),f.$setValidity("iban",d),d?(b=h(a),b!==a&&(c[e.ngModel]=b),b):a})}}}])}).call(this); \ No newline at end of file +(function(){"use strict";var a=function(a,b){return(a%b+ +b)%b};angular.module("mm.iban",["ng"]).constant("ngIbanCountries",{AL:{name:"Albania",regex:/^AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}$/},AD:{name:"Andorra",regex:/^AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}$/},AT:{name:"Austria",regex:/^AT[0-9]{2}[0-9]{5}[0-9]{11}$/},AZ:{name:"Azerbaijan, Republic of",regex:/^AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}$/},BH:{name:"Bahrain",regex:/^BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}$/},BE:{name:"Belgium",regex:/^BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}$/},BA:{name:"Bosnia and Herzegovina",regex:/^BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}$/},BR:{name:"Brazil",regex:/^BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}$/},BG:{name:"Bulgaria",regex:/^BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}$/},CR:{name:"Costa Rica",regex:/^CR[0-9]{2}[0-9]{3}[0-9]{14}$/},HR:{name:"Croatia",regex:/^HR[0-9]{2}[0-9]{7}[0-9]{10}$/},CY:{name:"Cyprus",regex:/^CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}$/},CZ:{name:"Czech Republic",regex:/^CZ[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}$/},DK:{name:"Denmark",regex:/^DK[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/},DO:{name:"Dominican Republic",regex:/^DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}$/},EE:{name:"Estonia",regex:/^EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}$/},FO:{name:"Faroe Islands",regex:/^FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/},FI:{name:"Finland",regex:/^FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}$/},FR:{name:"France",regex:/^FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}$/},GE:{name:"Georgia",regex:/^GE[0-9]{2}[A-Z]{2}[0-9]{16}$/},DE:{name:"Germany",regex:/^DE[0-9]{2}[0-9]{8}[0-9]{10}$/},GI:{name:"Gibraltar",regex:/^GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}$/},GR:{name:"Greece",regex:/^GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}$/},GL:{name:"Greenland",regex:/^GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/},GT:{name:"Guatemala",regex:/^GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}$/},HU:{name:"Hungary",regex:/^HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}$/},IS:{name:"Iceland",regex:/^IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}$/},IE:{name:"Ireland",regex:/^IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}$/},IL:{name:"Israel",regex:/^IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}$/},IT:{name:"Italy",regex:/^IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}$/},KZ:{name:"Kazakhstan",regex:/^KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}$/},KW:{name:"Kuwait",regex:/^KW[0-9]{2}[A-Z]{4}[A-Z0-9]{22}$/},LV:{name:"Latvia",regex:/^LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}$/},LB:{name:"Lebanon",regex:/^LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}$/},LI:{name:"Liechtenstein (Principality of)",regex:/^LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}$/},LT:{name:"Lithuania",regex:/^LT[0-9]{2}[0-9]{5}[0-9]{11}$/},LU:{name:"Luxembourg",regex:/^LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}$/},MK:{name:"Macedonia",regex:/^MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}$/},MT:{name:"Malta",regex:/^MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}$/},MR:{name:"Mauritania",regex:/^MR[0-9]{2}[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}$/},MU:{name:"Mauritius",regex:/^MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}$/},MD:{name:"Moldova, Republic of",regex:/^MD[0-9]{2}[A-Z0-9]{20}$/},MC:{name:"Monaco",regex:/^MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}$/},ME:{name:"Montenegro",regex:/^ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/},NL:{name:"Netherlands",regex:/^NL[0-9]{2}[A-Z]{4}[0-9]{10}$/},NO:{name:"Norway",regex:/^NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}$/},PK:{name:"Pakistan",regex:/^PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}$/},PL:{name:"Poland",regex:/^PL[0-9]{2}[0-9]{8}[0-9]{16}$/},PS:{name:"Palestinian Territory, Occupied",regex:/^PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}$/},PT:{name:"Portugal",regex:/^PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}$/},QA:{name:"Qatar",regex:/^QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}$/},RO:{name:"Romania",regex:/^RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}$/},SM:{name:"San Marino",regex:/^SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}$/},SA:{name:"Saudi Arabia",regex:/^SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}$/},RS:{name:"Serbia",regex:/^RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/},SK:{name:"Slovak Republic",regex:/^SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}$/},SI:{name:"Slovenia",regex:/^SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}$/},ES:{name:"Spain",regex:/^ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}$/},SE:{name:"Sweden",regex:/^SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}$/},CH:{name:"Switzerland",regex:/^CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}$/},TL:{name:"Timor-Leste",regex:/^TL[0-9]{2}[0-9]{3}[0-9]{14}[0-9]{2}$/},TN:{name:"Tunisia",regex:/^TN[0-9]{2}[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/},TR:{name:"Turkey",regex:/^TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}$/},AE:{name:"United Arab Emirates",regex:/^AE[0-9]{2}[0-9]{3}[0-9]{16}$/},GB:{name:"United Kingdom",regex:/^GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}$/},VG:{name:"Virgin Islands, British",regex:/^VG[0-9]{2}[A-Z]{4}[0-9]{16}$/}}).directive("ngIban",["ngIbanCountries",function(b){return{restrict:"A",require:"ngModel",link:function(c,d,e,f){var g,h;return h=function(a){return null!=a?a.toUpperCase().replace(/\s/g,""):void 0},g=function(c){var d,f,g,i,j;if(null==c)return!0;if(d="A".charCodeAt(0),f="Z".charCodeAt(0),i=h(c),!(""===e.ngIban||e.ngIban in b&&b[e.ngIban].regex.test(i)))return!1;for(i=i.substr(4)+i.substr(0,4),j=i.split("").map(function(a){var b;return b=a.charCodeAt(0),b>=d&&f>=b?b-d+10:a}).join("");j.length>2;)g=j.slice(0,9),j=a(parseInt(g,10),97)+j.slice(g.length);return 1===a(parseInt(j,10),97)},f.$parsers.unshift(function(a){var b,c;return c=g(a),f.$setValidity("iban",c),c?(b=h(a),b!==a&&(f.$setViewValue(b),f.$render()),b):void 0}),f.$formatters.unshift(function(a){var b,d;return d=g(a),f.$setValidity("iban",d),d?(b=h(a),b!==a&&(c[e.ngModel]=b),b):a})}}}])}).call(this); \ No newline at end of file diff --git a/package.json b/package.json index 59339af..4c469a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng-iban", - "version": "0.2.5", + "version": "0.2.6", "description": "IBAN directive for AngularJS", "main": "./dist/ng-iban.js", "scripts": { diff --git a/src/ng-iban.coffee b/src/ng-iban.coffee index 63595c6..3ae036e 100644 --- a/src/ng-iban.coffee +++ b/src/ng-iban.coffee @@ -3,72 +3,204 @@ angular .module 'mm.iban', ['ng'] .constant 'ngIbanCountries', - AL: /^AL[0-9]{2}[0-9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aijan, Republic of' + regex: /^AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}$/ + BH: + name: 'Bahrain' + regex: /^BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}$/ + BE: + name: 'Belgium' + regex: /^BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}$/ + BA: + name: 'Bosnia and Herzegovina' + regex: /^BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}$/ + BR: + name: 'Brazil' + regex: /^BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}$/ + BG: + name: 'Bulgaria' + regex: /^BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}$/ + CR: + name: 'Costa Rica' + regex: /^CR[0-9]{2}[0-9]{3}[0-9]{14}$/ + HR: + name: 'Croatia' + regex: /^HR[0-9]{2}[0-9]{7}[0-9]{10}$/ + CY: + name: 'Cyprus' + regex: /^CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}$/ + CZ: + name: 'Czech Republic' + regex: /^CZ[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}$/ + DK: + name: 'Denmark' + regex: /^DK[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/ + DO: + name: 'Dominican Republic' + regex: /^DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}$/ + EE: + name: 'Estonia' + regex: /^EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}$/ + FO: + name: 'Faroe Islands' + regex: /^FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/ + FI: + name: 'Finland' + regex: /^FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}$/ + FR: + name: 'France' + regex: /^FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}$/ + GE: + name: 'Georgia' + regex: /^GE[0-9]{2}[A-Z]{2}[0-9]{16}$/ + DE: + name: 'Germany' + regex: /^DE[0-9]{2}[0-9]{8}[0-9]{10}$/ + GI: + name: 'Gibraltar' + regex: /^GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}$/ + GR: + name: 'Greece' + regex: /^GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}$/ + GL: + name: 'Greenland' + regex: /^GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}$/ + GT: + name: 'Guatemala' + regex: /^GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}$/ + HU: + name: 'Hungary' + regex: /^HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}$/ + IS: + name: 'Iceland' + regex: /^IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}$/ + IE: + name: 'Ireland' + regex: /^IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}$/ + IL: + name: 'Israel' + regex: /^IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}$/ + IT: + name: 'Italy' + regex: /^IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}$/ + KZ: + name: 'Kazakhstan' + regex: /^KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}$/ + KW: + name: 'Kuwait' + regex: /^KW[0-9]{2}[A-Z]{4}[A-Z0-9]{22}$/ + LV: + name: 'Latvia' + regex: /^LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}$/ + LB: + name: 'Lebanon' + regex: /^LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}$/ + LI: + name: 'Liechtenstein (Principality of)' + regex: /^LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}$/ + LT: + name: 'Lithuania' + regex: /^LT[0-9]{2}[0-9]{5}[0-9]{11}$/ + LU: + name: 'Luxembourg' + regex: /^LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}$/ + MK: + name: 'Macedonia' + regex: /^MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}$/ + MT: + name: 'Malta' + regex: /^MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}$/ + MR: + name: 'Mauritania' + regex: /^MR[0-9]{2}[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}$/ + MU: + name: 'Mauritius' + regex: /^MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}$/ + MD: + name: 'Moldova, Republic of' + regex: /^MD[0-9]{2}[A-Z0-9]{20}$/ + MC: + name: 'Monaco' + regex: /^MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}$/ + ME: + name: 'Montenegro' + regex: /^ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/ + NL: + name: 'Netherlands' + regex: /^NL[0-9]{2}[A-Z]{4}[0-9]{10}$/ + NO: + name: 'Norway' + regex: /^NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}$/ + PK: + name: 'Pakistan' + regex: /^PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}$/ + PL: + name: 'Poland' + regex: /^PL[0-9]{2}[0-9]{8}[0-9]{16}$/ + PS: + name: 'Palestinian Territory, Occupied' + regex: /^PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}$/ + PT: + name: 'Portugal' + regex: /^PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}$/ + QA: + name: 'Qatar' + regex: /^QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}$/ + RO: + name: 'Romania' + regex: /^RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}$/ + SM: + name: 'San Marino' + regex: /^SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}$/ + SA: + name: 'Saudi Arabia' + regex: /^SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}$/ + RS: + name: 'Serbia' + regex: /^RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/ + SK: + name: 'Slovak Republic' + regex: /^SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}$/ + SI: + name: 'Slovenia' + regex: /^SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}$/ + ES: + name: 'Spain' + regex: /^ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}$/ + SE: + name: 'Sweden' + regex: /^SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}$/ + CH: + name: 'Switzerland' + regex: /^CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}$/ + TL: + name: 'Timor-Leste' + regex: /^TL[0-9]{2}[0-9]{3}[0-9]{14}[0-9]{2}$/ + TN: + name: 'Tunisia' + regex: /^TN[0-9]{2}[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}$/ + TR: + name: 'Turkey' + regex: /^TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}$/ + AE: + name: 'United Arab Emirates' + regex: /^AE[0-9]{2}[0-9]{3}[0-9]{16}$/ + GB: + name: 'United Kingdom' + regex: /^GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}$/ + VG: + name: 'Virgin Islands, British' + regex: /^VG[0-9]{2}[A-Z]{4}[0-9]{16}$/ .directive 'ngIban', (ngIbanCountries) -> restrict: 'A' require: 'ngModel' @@ -83,7 +215,7 @@ angular Z = 'Z'.charCodeAt 0 iban = parseIban(value) - return false if attrs.ngIban isnt '' and (not !!(attrs.ngIban of ngIbanCountries) or not ngIbanCountries[attrs.ngIban].test iban) + return false if attrs.ngIban isnt '' and (not !!(attrs.ngIban of ngIbanCountries) or not ngIbanCountries[attrs.ngIban].regex.test iban) iban = iban.substr(4) + iban.substr 0, 4 @@ -98,23 +230,23 @@ angular parseInt(remainder, 10) %% 97 is 1 - ctrl.$parsers.unshift (value) -> - valid = isValidIban value + ctrl.$parsers.unshift (viewValue) -> + valid = isValidIban viewValue ctrl.$setValidity 'iban', valid if valid - parsed = parseIban value - if parsed isnt value + parsed = parseIban viewValue + if parsed isnt viewValue ctrl.$setViewValue parsed ctrl.$render() parsed else undefined - ctrl.$formatters.unshift (value) -> - valid = isValidIban value + ctrl.$formatters.unshift (modelValue) -> + valid = isValidIban modelValue ctrl.$setValidity 'iban', valid if valid - parsed = parseIban value - if parsed isnt value + parsed = parseIban modelValue + if parsed isnt modelValue scope[attrs.ngModel] = parsed parsed - else value + else modelValue