ソースを参照

fix nl phone codes

Robin Herbots 11 年 前
コミット
816ae94588
2 ファイル変更19 行追加11 行削除
  1. 18 10
      js/jquery.inputmask.phone.extensions.js
  2. 1 1
      js/phone-codes/phone-nl.js

+ 18 - 10
js/jquery.inputmask.phone.extensions.js

@@ -22,6 +22,7 @@ When using this extension make sure you specify the correct url to get the masks
         'phone': {
             url: "phone-codes/phone-codes.js",
             maskInit: "+pp(pp)pppppppp",
+            countrycode: "",
             mask: function (opts) {
                 opts.definitions = {
                     'p': {
@@ -40,31 +41,38 @@ When using this extension make sure you specify the correct url to get the masks
                     dataType: 'json',
                     success: function (response) {
                         maskList = response;
+                    },
+                    error: function (xhr, ajaxOptions, thrownError) {
+                        alert(thrownError + " - " + opts.url);
                     }
                 });
 
                 maskList = maskList.sort(function (a, b) {
                     return (a["mask"] || a) < (b["mask"] || b) ? -1 : 1;
                 });
+
+                if (opts.countrycode != "") {
+                    opts.maskInit = "+" + opts.countrycode + opts.maskInit.substring(3);
+                }
                 maskList.splice(0, 0, opts.maskInit);
                 return maskList;
             },
             nojumps: true,
-            nojumpsThreshold: 1
-        },
-        'phonebe': {
-            alias: "phone",
-            url: "phone-codes/phone-be.js",
-            maskInit: "+32(pp)pppppppp",
-            nojumpsThreshold: 4,
-            onBeforeMask: function(value, opts) {
+            nojumpsThreshold: 1,
+            onBeforeMask: function (value, opts) {
                 var processedValue = value.replace(/^0/g, "");
-                if (processedValue.indexOf("32") > 1 || processedValue.indexOf("32") == -1) {
-                    processedValue = "32" + processedValue;
+                if (processedValue.indexOf(opts.countrycode) > 1 || processedValue.indexOf(opts.countrycode) == -1) {
+                    processedValue = opts.countrycode + processedValue;
                 }
 
                 return processedValue;
             }
+        },
+        'phonebe': {
+            alias: "phone",
+            url: "phone-codes/phone-be.js",
+            countrycode: "32",
+            nojumpsThreshold: 4
         }
     });
     return $.fn.inputmask;

+ 1 - 1
js/phone-codes/phone-nl.js

@@ -158,7 +158,7 @@
     { "mask": "+31-77-###-####", "cc": "NL", "cd": "Netherlands", "city": "Venlo" },
     { "mask": "+31-78-###-####", "cc": "NL", "cd": "Netherlands", "city": "Dordrecht" },
     { "mask": "+31-79-###-####", "cc": "NL", "cd": "Netherlands", "city": "Zoetermeer" },
-    /* Niet-geografische nummers */
+
     { "mask": "+31-61-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers" },
     { "mask": "+31-62-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers" },
     { "mask": "+31-63-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers" },