ソースを参照

fix for decimal extension + greedy with quantifiers fix

Robin Herbots 11 年 前
コミット
02c9dfdfa4

+ 1 - 1
dist/inputmask/jquery.inputmask.date.extensions.js

@@ -1,7 +1,7 @@
 /*!
 * jquery.inputmask.date.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
-* Copyright (c) 2010 - 2014 Robin Herbots
+* Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Version: 3.1.49
 */

+ 1 - 1
dist/inputmask/jquery.inputmask.extensions.js

@@ -1,7 +1,7 @@
 /*!
 * jquery.inputmask.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
-* Copyright (c) 2010 - 2014 Robin Herbots
+* Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Version: 3.1.49
 */

+ 27 - 32
dist/inputmask/jquery.inputmask.js

@@ -1,7 +1,7 @@
 /*!
 * jquery.inputmask.js
 * http://github.com/RobinHerbots/jquery.inputmask
-* Copyright (c) 2010 - 2014 Robin Herbots
+* Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Version: 3.1.49
 */
@@ -252,11 +252,13 @@
             } else getMaskSet().validPositions[pos] = validTest;
             return !0;
         }
-        function stripValidPositions(start, end) {
+        function stripValidPositions(start, end, nocheck) {
             var i, startPos = start;
-            for (void 0 != getMaskSet().validPositions[start] && getMaskSet().validPositions[start].input == opts.radixPoint && (end++, 
-            startPos++), i = startPos; end > i; i++) void 0 != getMaskSet().validPositions[i] && 0 != opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), opts) && delete getMaskSet().validPositions[i];
-            for (i = end; i <= getLastValidPosition(); ) {
+            void 0 != getMaskSet().validPositions[start] && getMaskSet().validPositions[start].input == opts.radixPoint && (end++, 
+            startPos++);
+            var endPos = end;
+            for (i = startPos; end > i; i++) void 0 != getMaskSet().validPositions[i] && (0 != opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), opts) || nocheck === !0 ? delete getMaskSet().validPositions[i] : endPos--);
+            for (i = endPos; i <= getLastValidPosition(); ) {
                 var t = getMaskSet().validPositions[i], s = getMaskSet().validPositions[startPos];
                 void 0 != t && void 0 == s ? (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t.input, !0) !== !1 && (delete getMaskSet().validPositions[i], 
                 i++), startPos++) : i++;
@@ -267,7 +269,7 @@
         }
         function getTestTemplate(pos, ndxIntlzr, tstPs) {
             for (var testPos, testPositions = getTests(pos, ndxIntlzr, tstPs), lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0], lvTestAltArr = void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx], 
-            !(opts.greedy || testPos.match && (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0 && (void 0 == lvTest.alternation || void 0 != testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr)))); ndx++) ;
+            !(testPos.match && (opts.greedy && testPos.match.optionalQuantifier !== !0 || (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0) && (void 0 == lvTest.alternation || void 0 != testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr)))); ndx++) ;
             return testPos;
         }
         function getTest(pos) {
@@ -329,24 +331,20 @@
                                 })), matches = currentMatches.concat(malternateMatches), insertStop = !0;
                             } else match = handleMatch(alternateToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse);
                             if (match) return !0;
-                        } else if (match.isQuantifier && quantifierRecurse !== !0) {
-                            var qt = match;
-                            opts.greedy = opts.greedy && isFinite(qt.quantifier.max);
-                            for (var qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) {
-                                var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
-                                if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), !0)) {
-                                    var latestMatch = matches[matches.length - 1].match;
-                                    latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
-                                    var isFirstMatch = 0 == $.inArray(latestMatch, tokenGroup.matches);
-                                    if (isFirstMatch) {
-                                        if (qndx > qt.quantifier.min - 1) {
-                                            insertStop = !0, testPos = pos;
-                                            break;
-                                        }
-                                        return !0;
+                        } else if (match.isQuantifier && quantifierRecurse !== !0) for (var qt = match, qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) {
+                            var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
+                            if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), !0)) {
+                                var latestMatch = matches[matches.length - 1].match;
+                                latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
+                                var isFirstMatch = 0 == $.inArray(latestMatch, tokenGroup.matches);
+                                if (isFirstMatch) {
+                                    if (qndx > qt.quantifier.min - 1) {
+                                        insertStop = !0, testPos = pos;
+                                        break;
                                     }
                                     return !0;
                                 }
+                                return !0;
                             }
                         } else if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) return !0;
                     } else testPos++;
@@ -424,7 +422,7 @@
                         var elem = void 0 != rslt.c ? rslt.c : c;
                         elem = elem == opts.skipOptionalPartCharacter && null === test.fn ? test.def : elem;
                         var validatedPos = position;
-                        if (void 0 != rslt.remove && stripValidPositions(rslt.remove, rslt.remove + 1), 
+                        if (void 0 != rslt.remove && stripValidPositions(rslt.remove, rslt.remove + 1, !0), 
                         rslt.refreshFromBuffer) {
                             var refresh = rslt.refreshFromBuffer;
                             if (strict = !0, refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end), 
@@ -509,14 +507,11 @@
         }
         function getMaskLength() {
             var maskLength;
-            if (maxLength = $el.prop("maxLength"), -1 == maxLength && (maxLength = void 0), 
-            0 == opts.greedy) {
-                var pos, lvp = getLastValidPosition(), testPos = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != testPos ? testPos.locator.slice() : void 0;
-                for (pos = lvp + 1; void 0 == testPos || null != testPos.match.fn || null == testPos.match.fn && "" != testPos.match.def; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), 
-                ndxIntlzr = testPos.locator.slice();
-                maskLength = pos;
-            } else maskLength = getBuffer().length;
-            return void 0 == maxLength || maxLength > maskLength ? maskLength : maxLength;
+            maxLength = $el.prop("maxLength"), -1 == maxLength && (maxLength = void 0);
+            var pos, lvp = getLastValidPosition(), testPos = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != testPos ? testPos.locator.slice() : void 0;
+            for (pos = lvp + 1; void 0 == testPos || null != testPos.match.fn || null == testPos.match.fn && "" != testPos.match.def; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), 
+            ndxIntlzr = testPos.locator.slice();
+            return maskLength = pos, void 0 == maxLength || maxLength > maskLength ? maskLength : maxLength;
         }
         function seekNext(pos) {
             var maskL = getMaskLength();
@@ -777,8 +772,8 @@
             }
             k == $.inputmask.keyCode.BACKSPACE && pos.end - pos.begin <= 1 ? pos.begin = seekPrevious(pos.begin) : k == $.inputmask.keyCode.DELETE && pos.begin == pos.end && pos.end++, 
             stripValidPositions(pos.begin, pos.end), generalize();
-            var firstMaskedPos = getLastValidPosition(pos.begin);
-            firstMaskedPos < pos.begin ? (-1 == firstMaskedPos && resetMaskSet(), getMaskSet().p = seekNext(firstMaskedPos)) : getMaskSet().p = pos.begin;
+            var lvp = getLastValidPosition(pos.begin);
+            lvp < pos.begin ? (-1 == lvp && resetMaskSet(), getMaskSet().p = seekNext(lvp)) : getMaskSet().p = pos.begin;
         }
         function keydownEvent(e) {
             var input = this, $input = $(input), k = e.keyCode, pos = caret(input);

+ 13 - 8
dist/inputmask/jquery.inputmask.numeric.extensions.js

@@ -1,7 +1,7 @@
 /*!
 * jquery.inputmask.numeric.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
-* Copyright (c) 2010 - 2014 Robin Herbots
+* Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Version: 3.1.49
 */
@@ -53,7 +53,7 @@
                 var cbuf = buffer.slice();
                 charAtPos == opts.groupSeparator && (cbuf.splice(pos--, 1), charAtPos = cbuf[pos]), 
                 reformatOnly ? cbuf[pos] = "?" : cbuf.splice(pos, 0, "?");
-                var bufVal = cbuf.join("");
+                var bufVal = cbuf.join(""), bufValOrigin = bufVal;
                 if (bufVal.length > 0 && opts.autoGroup || reformatOnly && -1 != bufVal.indexOf(opts.groupSeparator)) {
                     var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
                     needsRefresh = 0 == bufVal.indexOf(opts.groupSeparator), bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), "");
@@ -62,7 +62,7 @@
                     bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
                     "" != opts.radixPoint && radixSplit.length > 1 && (bufVal += opts.radixPoint + radixSplit[1]);
                 }
-                needsRefresh = buffer.join("") != bufVal, buffer.length = bufVal.length;
+                needsRefresh = bufValOrigin != bufVal, buffer.length = bufVal.length;
                 for (var i = 0, l = bufVal.length; l > i; i++) buffer[i] = bufVal.charAt(i);
                 var newPos = $.inArray("?", buffer);
                 return reformatOnly ? buffer[newPos] = charAtPos : buffer.splice(newPos, 1), {
@@ -224,11 +224,16 @@
                 initialValue;
             },
             canClearPosition: function(maskset, position, lvp, opts) {
-                var canClear = maskset.validPositions[position].input != opts.radixPoint || position == lvp;
-                if (canClear) {
-                    var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
-                    matchRslt && (-1 == radixPosition || radixPosition >= position) && (0 == matchRslt[0].indexOf("0") ? canClear = matchRslt.index != position : -1 != radixPosition && 1 == matchRslt[0].length && matchRslt.index == position && (maskset.validPositions[position].input = "0", 
-                    canClear = !1));
+                var positionInput = maskset.validPositions[position].input, canClear = positionInput != opts.radixPoint || position == lvp;
+                if (canClear && isFinite(positionInput)) {
+                    var buffer = [];
+                    for (var vp in maskset.validPositions) buffer.push(maskset.validPositions[vp].input);
+                    var matchRslt = buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
+                    if (matchRslt && (-1 == radixPosition || radixPosition >= position)) if (0 == matchRslt[0].indexOf("0")) canClear = matchRslt.index != position || -1 == radixPosition; else {
+                        var intPart = parseInt(matchRslt[0].replace(new RegExp($.inputmask.escapeRegex.call(this, opts.groupSeparator), "g"), ""));
+                        -1 != radixPosition && 10 > intPart && (maskset.validPositions[position].input = "0", 
+                        canClear = !1);
+                    }
                 }
                 return canClear && maskset.validPositions[position + 1] && maskset.validPositions[position + 1].input == opts.groupSeparator && delete maskset.validPositions[position + 1], 
                 canClear;

+ 1 - 1
dist/inputmask/jquery.inputmask.phone.extensions.js

@@ -1,7 +1,7 @@
 /*!
 * jquery.inputmask.phone.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
-* Copyright (c) 2010 - 2014 Robin Herbots
+* Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Version: 3.1.49
 */

+ 1 - 1
dist/inputmask/jquery.inputmask.regex.extensions.js

@@ -1,7 +1,7 @@
 /*!
 * jquery.inputmask.regex.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
-* Copyright (c) 2010 - 2014 Robin Herbots
+* Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Version: 3.1.49
 */

+ 39 - 39
dist/jquery.inputmask.bundle.js

@@ -1,7 +1,7 @@
 /*!
 * jquery.inputmask.bundle
 * http://github.com/RobinHerbots/jquery.inputmask
-* Copyright (c) 2010 - 2014 Robin Herbots
+* Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Version: 3.1.49
 */
@@ -250,11 +250,13 @@
             } else getMaskSet().validPositions[pos] = validTest;
             return !0;
         }
-        function stripValidPositions(start, end) {
+        function stripValidPositions(start, end, nocheck) {
             var i, startPos = start;
-            for (void 0 != getMaskSet().validPositions[start] && getMaskSet().validPositions[start].input == opts.radixPoint && (end++, 
-            startPos++), i = startPos; end > i; i++) void 0 != getMaskSet().validPositions[i] && 0 != opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), opts) && delete getMaskSet().validPositions[i];
-            for (i = end; i <= getLastValidPosition(); ) {
+            void 0 != getMaskSet().validPositions[start] && getMaskSet().validPositions[start].input == opts.radixPoint && (end++, 
+            startPos++);
+            var endPos = end;
+            for (i = startPos; end > i; i++) void 0 != getMaskSet().validPositions[i] && (0 != opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), opts) || nocheck === !0 ? delete getMaskSet().validPositions[i] : endPos--);
+            for (i = endPos; i <= getLastValidPosition(); ) {
                 var t = getMaskSet().validPositions[i], s = getMaskSet().validPositions[startPos];
                 void 0 != t && void 0 == s ? (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t.input, !0) !== !1 && (delete getMaskSet().validPositions[i], 
                 i++), startPos++) : i++;
@@ -265,7 +267,7 @@
         }
         function getTestTemplate(pos, ndxIntlzr, tstPs) {
             for (var testPos, testPositions = getTests(pos, ndxIntlzr, tstPs), lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0], lvTestAltArr = void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx], 
-            !(opts.greedy || testPos.match && (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0 && (void 0 == lvTest.alternation || void 0 != testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr)))); ndx++) ;
+            !(testPos.match && (opts.greedy && testPos.match.optionalQuantifier !== !0 || (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0) && (void 0 == lvTest.alternation || void 0 != testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr)))); ndx++) ;
             return testPos;
         }
         function getTest(pos) {
@@ -327,24 +329,20 @@
                                 })), matches = currentMatches.concat(malternateMatches), insertStop = !0;
                             } else match = handleMatch(alternateToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse);
                             if (match) return !0;
-                        } else if (match.isQuantifier && quantifierRecurse !== !0) {
-                            var qt = match;
-                            opts.greedy = opts.greedy && isFinite(qt.quantifier.max);
-                            for (var qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) {
-                                var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
-                                if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), !0)) {
-                                    var latestMatch = matches[matches.length - 1].match;
-                                    latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
-                                    var isFirstMatch = 0 == $.inArray(latestMatch, tokenGroup.matches);
-                                    if (isFirstMatch) {
-                                        if (qndx > qt.quantifier.min - 1) {
-                                            insertStop = !0, testPos = pos;
-                                            break;
-                                        }
-                                        return !0;
+                        } else if (match.isQuantifier && quantifierRecurse !== !0) for (var qt = match, qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) {
+                            var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
+                            if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), !0)) {
+                                var latestMatch = matches[matches.length - 1].match;
+                                latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
+                                var isFirstMatch = 0 == $.inArray(latestMatch, tokenGroup.matches);
+                                if (isFirstMatch) {
+                                    if (qndx > qt.quantifier.min - 1) {
+                                        insertStop = !0, testPos = pos;
+                                        break;
                                     }
                                     return !0;
                                 }
+                                return !0;
                             }
                         } else if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) return !0;
                     } else testPos++;
@@ -422,7 +420,7 @@
                         var elem = void 0 != rslt.c ? rslt.c : c;
                         elem = elem == opts.skipOptionalPartCharacter && null === test.fn ? test.def : elem;
                         var validatedPos = position;
-                        if (void 0 != rslt.remove && stripValidPositions(rslt.remove, rslt.remove + 1), 
+                        if (void 0 != rslt.remove && stripValidPositions(rslt.remove, rslt.remove + 1, !0), 
                         rslt.refreshFromBuffer) {
                             var refresh = rslt.refreshFromBuffer;
                             if (strict = !0, refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end), 
@@ -507,14 +505,11 @@
         }
         function getMaskLength() {
             var maskLength;
-            if (maxLength = $el.prop("maxLength"), -1 == maxLength && (maxLength = void 0), 
-            0 == opts.greedy) {
-                var pos, lvp = getLastValidPosition(), testPos = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != testPos ? testPos.locator.slice() : void 0;
-                for (pos = lvp + 1; void 0 == testPos || null != testPos.match.fn || null == testPos.match.fn && "" != testPos.match.def; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), 
-                ndxIntlzr = testPos.locator.slice();
-                maskLength = pos;
-            } else maskLength = getBuffer().length;
-            return void 0 == maxLength || maxLength > maskLength ? maskLength : maxLength;
+            maxLength = $el.prop("maxLength"), -1 == maxLength && (maxLength = void 0);
+            var pos, lvp = getLastValidPosition(), testPos = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != testPos ? testPos.locator.slice() : void 0;
+            for (pos = lvp + 1; void 0 == testPos || null != testPos.match.fn || null == testPos.match.fn && "" != testPos.match.def; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), 
+            ndxIntlzr = testPos.locator.slice();
+            return maskLength = pos, void 0 == maxLength || maxLength > maskLength ? maskLength : maxLength;
         }
         function seekNext(pos) {
             var maskL = getMaskLength();
@@ -775,8 +770,8 @@
             }
             k == $.inputmask.keyCode.BACKSPACE && pos.end - pos.begin <= 1 ? pos.begin = seekPrevious(pos.begin) : k == $.inputmask.keyCode.DELETE && pos.begin == pos.end && pos.end++, 
             stripValidPositions(pos.begin, pos.end), generalize();
-            var firstMaskedPos = getLastValidPosition(pos.begin);
-            firstMaskedPos < pos.begin ? (-1 == firstMaskedPos && resetMaskSet(), getMaskSet().p = seekNext(firstMaskedPos)) : getMaskSet().p = pos.begin;
+            var lvp = getLastValidPosition(pos.begin);
+            lvp < pos.begin ? (-1 == lvp && resetMaskSet(), getMaskSet().p = seekNext(lvp)) : getMaskSet().p = pos.begin;
         }
         function keydownEvent(e) {
             var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
@@ -1849,7 +1844,7 @@
                 var cbuf = buffer.slice();
                 charAtPos == opts.groupSeparator && (cbuf.splice(pos--, 1), charAtPos = cbuf[pos]), 
                 reformatOnly ? cbuf[pos] = "?" : cbuf.splice(pos, 0, "?");
-                var bufVal = cbuf.join("");
+                var bufVal = cbuf.join(""), bufValOrigin = bufVal;
                 if (bufVal.length > 0 && opts.autoGroup || reformatOnly && -1 != bufVal.indexOf(opts.groupSeparator)) {
                     var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
                     needsRefresh = 0 == bufVal.indexOf(opts.groupSeparator), bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), "");
@@ -1858,7 +1853,7 @@
                     bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
                     "" != opts.radixPoint && radixSplit.length > 1 && (bufVal += opts.radixPoint + radixSplit[1]);
                 }
-                needsRefresh = buffer.join("") != bufVal, buffer.length = bufVal.length;
+                needsRefresh = bufValOrigin != bufVal, buffer.length = bufVal.length;
                 for (var i = 0, l = bufVal.length; l > i; i++) buffer[i] = bufVal.charAt(i);
                 var newPos = $.inArray("?", buffer);
                 return reformatOnly ? buffer[newPos] = charAtPos : buffer.splice(newPos, 1), {
@@ -2020,11 +2015,16 @@
                 initialValue;
             },
             canClearPosition: function(maskset, position, lvp, opts) {
-                var canClear = maskset.validPositions[position].input != opts.radixPoint || position == lvp;
-                if (canClear) {
-                    var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
-                    matchRslt && (-1 == radixPosition || radixPosition >= position) && (0 == matchRslt[0].indexOf("0") ? canClear = matchRslt.index != position : -1 != radixPosition && 1 == matchRslt[0].length && matchRslt.index == position && (maskset.validPositions[position].input = "0", 
-                    canClear = !1));
+                var positionInput = maskset.validPositions[position].input, canClear = positionInput != opts.radixPoint || position == lvp;
+                if (canClear && isFinite(positionInput)) {
+                    var buffer = [];
+                    for (var vp in maskset.validPositions) buffer.push(maskset.validPositions[vp].input);
+                    var matchRslt = buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
+                    if (matchRslt && (-1 == radixPosition || radixPosition >= position)) if (0 == matchRslt[0].indexOf("0")) canClear = matchRslt.index != position || -1 == radixPosition; else {
+                        var intPart = parseInt(matchRslt[0].replace(new RegExp($.inputmask.escapeRegex.call(this, opts.groupSeparator), "g"), ""));
+                        -1 != radixPosition && 10 > intPart && (maskset.validPositions[position].input = "0", 
+                        canClear = !1);
+                    }
                 }
                 return canClear && maskset.validPositions[position + 1] && maskset.validPositions[position + 1].input == opts.groupSeparator && delete maskset.validPositions[position + 1], 
                 canClear;

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


+ 27 - 23
js/jquery.inputmask.js

@@ -422,18 +422,22 @@
 
                 return true;
             }
-            function stripValidPositions(start, end) {
+            function stripValidPositions(start, end, nocheck) {
                 var i, startPos = start;
                 if (getMaskSet()["validPositions"][start] != undefined && getMaskSet()["validPositions"][start].input == opts.radixPoint) {
                     end++;
                     startPos++;
                 }
+                var endPos = end;
                 for (i = startPos; i < end; i++) { //clear selection
-                    if (getMaskSet()["validPositions"][i] != undefined && opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), opts) != false)
-                        delete getMaskSet()["validPositions"][i];
+                    if (getMaskSet()["validPositions"][i] != undefined) {
+                        if (opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), opts) != false || nocheck === true)
+                            delete getMaskSet()["validPositions"][i];
+                        else endPos--;
+                    }
                 }
 
-                for (i = end ; i <= getLastValidPosition() ;) {
+                for (i = endPos ; i <= getLastValidPosition() ;) {
                     var t = getMaskSet()["validPositions"][i];
                     var s = getMaskSet()["validPositions"][startPos];
                     if (t != undefined && s == undefined) {
@@ -460,8 +464,9 @@
                 for (var ndx = 0; ndx < testPositions.length; ndx++) {
                     testPos = testPositions[ndx];
 
-                    if (opts.greedy ||
-                        ((testPos["match"] && (testPos["match"].optionality === false || testPos["match"].newBlockMarker === false) && testPos["match"].optionalQuantifier !== true) &&
+                    if (testPos["match"] &&
+                        (((opts.greedy && testPos["match"].optionalQuantifier !== true)
+                         || (testPos["match"].optionality === false || testPos["match"].newBlockMarker === false) && testPos["match"].optionalQuantifier !== true) &&
                         (lvTest.alternation == undefined ||
                         (testPos["locator"][lvTest.alternation] != undefined && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr))))) {
                         break;
@@ -508,7 +513,7 @@
                                     var latestMatch = matches[matches.length - 1]["match"];
                                     var isFirstMatch = $.inArray(latestMatch, optionalToken.matches) == 0;
                                     if (isFirstMatch) {
-                                        insertStop = true; //insert a stop for non greedy
+                                        insertStop = true; //insert a stop
                                     }
                                     testPos = pos; //match the position after the group
                                 }
@@ -578,7 +583,6 @@
                                 if (match) return true;
                             } else if (match.isQuantifier && quantifierRecurse !== true) {
                                 var qt = match;
-                                opts.greedy = opts.greedy && isFinite(qt.quantifier.max); //greedy must be off when * or + is used (always!!)
                                 for (var qndx = (ndxInitializer.length > 0 && quantifierRecurse !== true) ? ndxInitializer.shift() : 0; (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) {
                                     var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
                                     match = handleMatch(tokenGroup, [qndx].concat(loopNdx), true);
@@ -737,7 +741,7 @@
 
                             var validatedPos = position;
                             if (rslt["remove"] != undefined) { //remove position
-                                stripValidPositions(rslt["remove"], rslt["remove"] + 1);
+                                stripValidPositions(rslt["remove"], rslt["remove"] + 1, true);
                             }
 
                             if (rslt["refreshFromBuffer"]) {
@@ -921,16 +925,16 @@
                 var maskLength;
                 maxLength = $el.prop('maxLength');
                 if (maxLength == -1) maxLength = undefined; /* FF sets no defined max length to -1 */
-                if (opts.greedy == false) {
-                    var pos, lvp = getLastValidPosition(), testPos = getMaskSet()["validPositions"][lvp],
-                        ndxIntlzr = testPos != undefined ? testPos["locator"].slice() : undefined;
-                    for (pos = lvp + 1; testPos == undefined || (testPos["match"]["fn"] != null || (testPos["match"]["fn"] == null && testPos["match"]["def"] != "")) ; pos++) {
-                        testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
-                        ndxIntlzr = testPos["locator"].slice();
-                    }
-                    maskLength = pos;
-                } else
-                    maskLength = getBuffer().length;
+                //if (opts.greedy == false) { //FIXME TODO
+                var pos, lvp = getLastValidPosition(), testPos = getMaskSet()["validPositions"][lvp],
+                    ndxIntlzr = testPos != undefined ? testPos["locator"].slice() : undefined;
+                for (pos = lvp + 1; testPos == undefined || (testPos["match"]["fn"] != null || (testPos["match"]["fn"] == null && testPos["match"]["def"] != "")) ; pos++) {
+                    testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
+                    ndxIntlzr = testPos["locator"].slice();
+                }
+                maskLength = pos;
+                //} else
+                //    maskLength = getBuffer().length;
 
                 return (maxLength == undefined || maskLength < maxLength) ? maskLength : maxLength;
             }
@@ -1349,10 +1353,10 @@
                 stripValidPositions(pos.begin, pos.end);
                 generalize(); //revert the alternation
 
-                var firstMaskedPos = getLastValidPosition(pos.begin);
-                if (firstMaskedPos < pos.begin) {
-                    if (firstMaskedPos == -1) resetMaskSet();
-                    getMaskSet()["p"] = seekNext(firstMaskedPos);
+                var lvp = getLastValidPosition(pos.begin);
+                if (lvp < pos.begin) {
+                    if (lvp == -1) resetMaskSet();
+                    getMaskSet()["p"] = seekNext(lvp);
                 } else {
                     getMaskSet()["p"] = pos.begin;
                 }

+ 18 - 9
js/jquery.inputmask.numeric.extensions.js

@@ -90,7 +90,7 @@ Optional extensions on the jquery.inputmask base
                     charAtPos = cbuf[pos];
                 }
                 if (reformatOnly) cbuf[pos] = "?"; else cbuf.splice(pos, 0, "?"); //set position indicator
-                var bufVal = cbuf.join('');
+                var bufVal = cbuf.join(''), bufValOrigin = bufVal;
                 if (bufVal.length > 0 && opts.autoGroup || (reformatOnly && bufVal.indexOf(opts.groupSeparator) != -1)) {
                     var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
                     needsRefresh = bufVal.indexOf(opts.groupSeparator) == 0;
@@ -108,7 +108,7 @@ Optional extensions on the jquery.inputmask base
                     if (opts.radixPoint != "" && radixSplit.length > 1)
                         bufVal += opts.radixPoint + radixSplit[1];
                 }
-                needsRefresh = buffer.join('') != bufVal;
+                needsRefresh = bufValOrigin != bufVal;
                 buffer.length = bufVal.length; //align the length
                 for (var i = 0, l = bufVal.length; i < l; i++) {
                     buffer[i] = bufVal.charAt(i);
@@ -308,16 +308,25 @@ Optional extensions on the jquery.inputmask base
                 return initialValue;
             },
             canClearPosition: function (maskset, position, lvp, opts) {
-                var canClear = maskset["validPositions"][position].input != opts.radixPoint || position == lvp;
+                var positionInput = maskset["validPositions"][position].input, canClear = positionInput != opts.radixPoint || position == lvp,
+                    posOffset = 0;
 
-                if (canClear) {
-                    var matchRslt = maskset.buffer.join('').match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
+                if (canClear && isFinite(positionInput)) {
+                    var buffer = [];
+                    //build new buffer from validPositions
+                    for (var vp in maskset.validPositions) {
+                        buffer.push(maskset.validPositions[vp].input);
+                    }
+                    var matchRslt = buffer.join('').match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
                     if (matchRslt && (radixPosition == -1 || position <= radixPosition)) {
                         if (matchRslt["0"].indexOf("0") == 0) {
-                            canClear = matchRslt.index != position;
-                        } else if (radixPosition != -1 && matchRslt["0"].length == 1 && matchRslt.index == position) {
-                            maskset["validPositions"][position].input = "0";
-                            canClear = false;
+                            canClear = matchRslt.index != position || radixPosition == -1;
+                        } else {
+                            var intPart = parseInt(matchRslt["0"].replace(new RegExp($.inputmask.escapeRegex.call(this, opts.groupSeparator), "g"), ""));
+                            if (radixPosition != -1 && intPart < 10) {
+                                maskset["validPositions"][position].input = "0";
+                                canClear = false;
+                            }
                         }
                     }
                 }

+ 25 - 1
qunit/tests_dynamic.js

@@ -19,7 +19,7 @@ test("inputmask(\"9-a{1,3}9{1,3}\" - simple dynamic mask", function () {
     $("#testmask")[0].focus();
     $("#testmask").Type("1a1");
 
-    equal($("#testmask").val(), "1-a1__", "Result " + $("#testmask").val());
+    equal($("#testmask").val(), "1-a1", "Result " + $("#testmask").val());
 
     $("#testmask").remove();
 });
@@ -123,4 +123,28 @@ test("email mask - email@subdomain.domain.com - babupca", function () {
     equal($("#testmask").val(), "email@subdomain.domain.com", "Result " + $("#testmask").val());
 
     $("#testmask").remove();
+});
+
+test("quantifier mask greedy false - FairSite2C", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("9{0,4}", { greedy: false });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123");
+    equal($("#testmask").val(), "123", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
+test("quantifier mask greedy true - FairSite2C", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("9{0,4}", { greedy: true });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123");
+    equal($("#testmask").val(), "123", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
 });