ソースを参照

ip mask extension

Robin Herbots 12 年 前
コミット
e69fe709df

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 build.major = 2
 build.minor = 3
-build.revision = 67
+build.revision = 68
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

+ 1 - 1
component.json

@@ -1,6 +1,6 @@
 {
     "name": "jquery.inputmask",
-    "version": "2.3.67",
+    "version": "2.3.68",
     "main": "./dist/jquery.inputmask.bundle.js",
     "dependencies": {
         "jquery": ">=1.7"

BIN
dist/jQuery.InputMask.2.3.67.nupkg


+ 36 - 16
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 2.3.67
+* Version: 2.3.68
 */
 
 (function ($) {
@@ -1641,14 +1641,14 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.67
+Version: 2.3.68
 
 Optional extensions on the jquery.inputmask base
 */
 (function ($) {
     //extra definitions
     $.extend($.inputmask.defaults.definitions, {
-        'A': { 
+        'A': {
             validator: "[A-Za-z]",
             cardinality: 1,
             casing: "upper" //auto uppercasing
@@ -1723,16 +1723,36 @@ Optional extensions on the jquery.inputmask base
             insertMode: false,
             autoUnmask: false
         },
-        "ip": {
-            mask: "i.i.i.i",
+        "ip": { //ip-adress mask
+            mask: ["[[x]y]z.[[x]y]z.[[x]y]z.x[yz]", "[[x]y]z.[[x]y]z.[[x]y]z.[[x]y][z]"],
             definitions: {
-                'i': {
-                    validator: "25[0-5]|2[0-4][0-9]|[01][0-9][0-9]",
-                    cardinality: 3,
-                    prevalidator: [
-                                { validator: "[0-2]", cardinality: 1 },
-                                { validator: "2[0-5]|[01][0-9]", cardinality: 2 }
-                    ]
+                'x': {
+                    validator: "[012]",
+                    cardinality: 1,
+                    definitionSymbol: "i"
+                },
+                'y': {
+                    validator: function (chrs, buffer, pos, strict, opts) {
+                        if (pos - 1 > -1 && buffer[pos - 1] != ".")
+                            chrs = buffer[pos - 1] + chrs;
+                        else chrs = "0" + chrs;
+                        return new RegExp("2[0-5]|[01][0-9]").test(chrs);
+                    },
+                    cardinality: 1,
+                    definitionSymbol: "i"
+                },
+                'z': {
+                    validator: function (chrs, buffer, pos, strict, opts) {
+                        if (pos - 1 > -1 && buffer[pos - 1] != ".") {
+                            chrs = buffer[pos - 1] + chrs;
+                            if (pos - 2 > -1 && buffer[pos - 2] != ".") {
+                                chrs = buffer[pos - 2] + chrs;
+                            } else chrs = "0" + chrs;
+                        } else chrs = "00" + chrs;
+                        return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
+                    },
+                    cardinality: 1,
+                    definitionSymbol: "i"
                 }
             }
         }
@@ -1743,7 +1763,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.67
+Version: 2.3.68
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2227,7 +2247,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.67
+Version: 2.3.68
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2404,7 +2424,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.67
+Version: 2.3.68
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
@@ -2574,7 +2594,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.67
+Version: 2.3.68
 
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks

ファイルの差分が大きいため隠しています
+ 75 - 74
dist/jquery.inputmask.bundle.min.js


ファイルの差分が大きいため隠しています
+ 4 - 3
dist/min/jquery.inputmask.extensions.js


ファイルの差分が大きいため隠しています
+ 1 - 1
dist/min/jquery.inputmask.js


+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"mask"
     ],
-    "version": "2.3.67",
+    "version": "2.3.68",
     "author": {
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 30 - 10
js/jquery.inputmask.extensions.js

@@ -10,7 +10,7 @@ Optional extensions on the jquery.inputmask base
 (function ($) {
     //extra definitions
     $.extend($.inputmask.defaults.definitions, {
-        'A': { 
+        'A': {
             validator: "[A-Za-z]",
             cardinality: 1,
             casing: "upper" //auto uppercasing
@@ -85,16 +85,36 @@ Optional extensions on the jquery.inputmask base
             insertMode: false,
             autoUnmask: false
         },
-        "ip": {
-            mask: "i.i.i.i",
+        "ip": { //ip-adress mask
+            mask: ["[[x]y]z.[[x]y]z.[[x]y]z.x[yz]", "[[x]y]z.[[x]y]z.[[x]y]z.[[x]y][z]"],
             definitions: {
-                'i': {
-                    validator: "25[0-5]|2[0-4][0-9]|[01][0-9][0-9]",
-                    cardinality: 3,
-                    prevalidator: [
-                                { validator: "[0-2]", cardinality: 1 },
-                                { validator: "2[0-5]|[01][0-9]", cardinality: 2 }
-                    ]
+                'x': {
+                    validator: "[012]",
+                    cardinality: 1,
+                    definitionSymbol: "i"
+                },
+                'y': {
+                    validator: function (chrs, buffer, pos, strict, opts) {
+                        if (pos - 1 > -1 && buffer[pos - 1] != ".")
+                            chrs = buffer[pos - 1] + chrs;
+                        else chrs = "0" + chrs;
+                        return new RegExp("2[0-5]|[01][0-9]").test(chrs);
+                    },
+                    cardinality: 1,
+                    definitionSymbol: "i"
+                },
+                'z': {
+                    validator: function (chrs, buffer, pos, strict, opts) {
+                        if (pos - 1 > -1 && buffer[pos - 1] != ".") {
+                            chrs = buffer[pos - 1] + chrs;
+                            if (pos - 2 > -1 && buffer[pos - 2] != ".") {
+                                chrs = buffer[pos - 2] + chrs;
+                            } else chrs = "0" + chrs;
+                        } else chrs = "00" + chrs;
+                        return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
+                    },
+                    cardinality: 1,
+                    definitionSymbol: "i"
                 }
             }
         }

+ 57 - 0
qunit/tests.js

@@ -1608,6 +1608,63 @@ asyncTest("inputmask(\"phone\") - Brazil switch", 1, function () {
     }, 0);
 });
 
+module("IP - masks")
+test("inputmask(\"ip\" - 10.10.10.10", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $('body').append('<input type="text" id="testmask2" />');
+    $("#testmask").inputmask("ip")
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("10.10.10.10");
+    $("#testmask2")[0].focus();
+    equal($("#testmask").val(), "10.10.10.10", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+    $("#testmask2").remove();
+});
+
+test("inputmask(\"ip\" - 1.1.1.1", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $('body').append('<input type="text" id="testmask2" />');
+    $("#testmask").inputmask("ip")
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1.1.1.1");
+    $("#testmask2")[0].focus();
+    equal($("#testmask").val(), "1.1.1.1", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+    $("#testmask2").remove();
+});
+
+test("inputmask(\"ip\" - 255.255.255.255", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $('body').append('<input type="text" id="testmask2" />');
+    $("#testmask").inputmask("ip")
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("255.255.255.255");
+    $("#testmask2")[0].focus();
+    equal($("#testmask").val(), "255.255.255.255", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+    $("#testmask2").remove();
+});
+
+test("inputmask(\"ip\" - 192.168.1.100", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $('body').append('<input type="text" id="testmask2" />');
+    $("#testmask").inputmask("ip")
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("192.168.1.100");
+    $("#testmask2")[0].focus();
+    equal($("#testmask").val(), "192.168.1.100", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+    $("#testmask2").remove();
+});
+
 module("Dynamic Masks");
 test("inputmask(\"*{1,20}@*{1,20}.*{2,6}[.*{2}]\" - email mask", function () {
     $('body').append('<input type="text" id="testmask" />');