Browse Source

fix ctrl-a ctrl-x + fix for determineMaskset

Robin Herbots 12 years ago
parent
commit
2aa280d5d8

+ 1 - 1
build.properties

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

BIN
dist/jQuery.InputMask.2.2.17.nupkg


BIN
dist/jQuery.InputMask.2.2.18.nupkg


+ 34 - 27
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 2.2.17
+* Version: 2.2.18
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -413,7 +413,7 @@
                 return getActiveMaskSet()['_buffer'];
                 return getActiveMaskSet()['_buffer'];
             }
             }
 
 
-            function isValid(pos, c, buffer, strict, isRTL) { //strict true ~ no correction or autofill
+            function isValid(pos, c, buffer, strict, isRTL, checkVal) { //strict true ~ no correction or autofill
                 function _isValid(position, activeMaskset) {
                 function _isValid(position, activeMaskset) {
                     var testPos = determineTestPosition(position), loopend = c ? 1 : 0, chrs = '';
                     var testPos = determineTestPosition(position), loopend = c ? 1 : 0, chrs = '';
                     for (var i = activeMaskset['tests'][testPos].cardinality; i > loopend; i--) {
                     for (var i = activeMaskset['tests'][testPos].cardinality; i > loopend; i--) {
@@ -428,7 +428,7 @@
                     return activeMaskset['tests'][testPos].fn != null ? activeMaskset['tests'][testPos].fn.test(chrs, buffer, position, strict, opts) : false;
                     return activeMaskset['tests'][testPos].fn != null ? activeMaskset['tests'][testPos].fn.test(chrs, buffer, position, strict, opts) : false;
                 }
                 }
 
 
-                if (strict) {
+                if (strict || checkVal) {
                     var rslt = _isValid(pos, getActiveMaskSet()); //only check validity in current mask when validating strict
                     var rslt = _isValid(pos, getActiveMaskSet()); //only check validity in current mask when validating strict
 
 
                     if (rslt !== false) {
                     if (rslt !== false) {
@@ -479,19 +479,21 @@
                     }
                     }
                 });
                 });
                 activeMasksetIndex = currentActiveMasksetIndex; //reset activeMasksetIndex
                 activeMasksetIndex = currentActiveMasksetIndex; //reset activeMasksetIndex
-                determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL);
+                determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL, c);
                 result = results[activeMasksetIndex] || result;
                 result = results[activeMasksetIndex] || result;
                 setTimeout(function () { opts.onKeyValidation.call(this, result, opts); }, 0); //extra stuff to execute on keydown
                 setTimeout(function () { opts.onKeyValidation.call(this, result, opts); }, 0); //extra stuff to execute on keydown
                 return result;
                 return result;
             }
             }
 
 
-            function determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL) {
+            function determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL, c) {
                 $.each(masksets, function (index, value) {
                 $.each(masksets, function (index, value) {
                     var activeMaskset = this;
                     var activeMaskset = this;
-                    if (activeMaskset['lastValidPosition'] && (isRTL || opts.numericInput) ? activeMaskset['lastValidPosition'] <= pos : activeMaskset['lastValidPosition'] >= pos) {
+                    if (activeMaskset['lastValidPosition'] != undefined
+                        //&& index != currentActiveMasksetIndex
+                        && ((isRTL || opts.numericInput) ? activeMaskset['lastValidPosition'] <= pos : activeMaskset['lastValidPosition'] >= pos)) {
                         activeMasksetIndex = index;
                         activeMasksetIndex = index;
                         //reset to correct masktemplate
                         //reset to correct masktemplate
-                        checkVal(undefined, buffer, false, false, buffer.join(''), isRTL);
+                        checkVal(undefined, buffer, false, true, false, buffer.join(''), isRTL);
                         return false; //breaks
                         return false; //breaks
                     }
                     }
                 });
                 });
@@ -597,10 +599,12 @@
             }
             }
 
 
             //inputData can be used to override the value used to check
             //inputData can be used to override the value used to check
-            function checkVal(input, buffer, clearInvalid, skipRadixHandling, inputData, rtl) {
+            function checkVal(input, buffer, writeOut, strict, skipRadixHandling, inputData, rtl) {
                 var isRTL = rtl != undefined ? rtl : $(input).data('inputmask')['isRTL'],
                 var isRTL = rtl != undefined ? rtl : $(input).data('inputmask')['isRTL'],
                     inputValue = truncateInput(inputData != undefined ? inputData : input._valueGet(), isRTL).split('');
                     inputValue = truncateInput(inputData != undefined ? inputData : input._valueGet(), isRTL).split('');
 
 
+                strict = strict != undefined ? strict : true;
+
                 var maskL = getMaskLength(buffer);
                 var maskL = getMaskLength(buffer);
                 if (isRTL) { //align inputValue for RTL/numeric input
                 if (isRTL) { //align inputValue for RTL/numeric input
                     var inputValueRev = inputValue.reverse(); inputValueRev.length = maskL;
                     var inputValueRev = inputValue.reverse(); inputValueRev.length = maskL;
@@ -623,7 +627,7 @@
                     for (var pos = checkPosition + 1; pos < maskL; pos++) {
                     for (var pos = checkPosition + 1; pos < maskL; pos++) {
                         if (isMask(pos)) {
                         if (isMask(pos)) {
                             var c = inputValue[i];
                             var c = inputValue[i];
-                            if ((np = isValid(pos, c, buffer, !clearInvalid, isRTL)) !== false) {
+                            if ((np = isValid(pos, c, buffer, strict, isRTL, true)) !== false) {
                                 if (np !== true) {
                                 if (np !== true) {
                                     pos = np.pos != undefined ? np.pos : pos; //set new position from isValid
                                     pos = np.pos != undefined ? np.pos : pos; //set new position from isValid
                                     c = np.c != undefined ? np.c : c; //set new char from isValid
                                     c = np.c != undefined ? np.c : c; //set new char from isValid
@@ -657,7 +661,7 @@
                     buffer.length = newBuffer.length;
                     buffer.length = newBuffer.length;
                 }
                 }
 
 
-                if (clearInvalid) {
+                if (writeOut) {
                     writeBuffer(input, buffer);
                     writeBuffer(input, buffer);
                 }
                 }
                 return isRTL ? (opts.numericInput ? (opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1 && skipRadixHandling !== true ? $.inArray(opts.radixPoint, buffer) : seekNext(buffer, maskL)) : seekNext(buffer, rtlMatch)) : seekNext(buffer, lastMatch);
                 return isRTL ? (opts.numericInput ? (opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1 && skipRadixHandling !== true ? $.inArray(opts.radixPoint, buffer) : seekNext(buffer, maskL)) : seekNext(buffer, rtlMatch)) : seekNext(buffer, lastMatch);
@@ -701,7 +705,7 @@
                 var input = $input[0];
                 var input = $input[0];
                 if (getActiveTests() && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                 if (getActiveTests() && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                     var buffer = getActiveBuffer().slice();
                     var buffer = getActiveBuffer().slice();
-                    checkVal(input, buffer);
+                    checkVal(input, buffer, false);
                     return $.map(buffer, function (element, index) {
                     return $.map(buffer, function (element, index) {
                         return isMask(index) && isValid(index, element, buffer, true) ? element : null;
                         return isMask(index) && isValid(index, element, buffer, true) ? element : null;
                     }).join('');
                     }).join('');
@@ -916,14 +920,14 @@
                 ).bind(pasteEvent + ".inputmask dragdrop.inputmask drop.inputmask", function () {
                 ).bind(pasteEvent + ".inputmask dragdrop.inputmask drop.inputmask", function () {
                     var input = this;
                     var input = this;
                     setTimeout(function () {
                     setTimeout(function () {
-                        caret(input, checkVal(input, buffer, true));
+                        caret(input, checkVal(input, buffer, true, false));
                         if (isComplete(buffer))
                         if (isComplete(buffer))
                             $input.trigger("complete");
                             $input.trigger("complete");
                     }, 0);
                     }, 0);
                 }).bind('setvalue.inputmask', function () {
                 }).bind('setvalue.inputmask', function () {
                     var input = this;
                     var input = this;
                     undoBuffer = input._valueGet();
                     undoBuffer = input._valueGet();
-                    checkVal(input, buffer, true);
+                    checkVal(input, buffer, true, false);
                     if (input._valueGet() == getActiveBuffer().join(''))
                     if (input._valueGet() == getActiveBuffer().join(''))
                         input._valueSet('');
                         input._valueSet('');
                 }).bind('complete.inputmask', opts.oncomplete)
                 }).bind('complete.inputmask', opts.oncomplete)
@@ -1185,7 +1189,7 @@
                         e.preventDefault(); //stop default action but allow propagation
                         e.preventDefault(); //stop default action but allow propagation
                     } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
                     } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
                         setTimeout(function () {
                         setTimeout(function () {
-                            var caretPos = checkVal(input, buffer, false, true);
+                            var caretPos = checkVal(input, buffer, false);
                             if (!opts.insertMode && caretPos == getMaskLength(buffer) && !e.shiftKey) caretPos--;
                             if (!opts.insertMode && caretPos == getMaskLength(buffer) && !e.shiftKey) caretPos--;
                             caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
                             caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
                         }, 0);
                         }, 0);
@@ -1194,7 +1198,7 @@
                     }
                     }
                     else if (k == opts.keyCode.ESCAPE) {//escape
                     else if (k == opts.keyCode.ESCAPE) {//escape
                         input._valueSet(undoBuffer);
                         input._valueSet(undoBuffer);
-                        caret(input, 0, checkVal(input, buffer));
+                        caret(input, 0, checkVal(input, buffer, false));
                     } else if (k == opts.keyCode.INSERT) {//insert
                     } else if (k == opts.keyCode.INSERT) {//insert
                         opts.insertMode = !opts.insertMode;
                         opts.insertMode = !opts.insertMode;
                         caret(input, !opts.insertMode && pos.begin == getMaskLength(buffer) ? pos.begin - 1 : pos.begin);
                         caret(input, !opts.insertMode && pos.begin == getMaskLength(buffer) ? pos.begin - 1 : pos.begin);
@@ -1235,14 +1239,14 @@
                         caret(input, seekNext(buffer, radixPosition != -1 ? radixPosition : getMaskLength(buffer)));
                         caret(input, seekNext(buffer, radixPosition != -1 ? radixPosition : getMaskLength(buffer)));
                     }
                     }
 
 
-                    if (e.metaKey || ignorable) {
+                    if (e.ctrlKey || e.metaKey || ignorable) {
                         return true;
                         return true;
                     } else {
                     } else {
                         if (k) {
                         if (k) {
                             //$input.trigger('input');
                             //$input.trigger('input');
 
 
                             var pos = caret(input), maskL = getMaskLength(buffer), writeOutBuffer = true;
                             var pos = caret(input), maskL = getMaskLength(buffer), writeOutBuffer = true;
-                            clearBuffer(buffer, pos.begin, pos.end);
+                            if ((pos.end - pos.begin) > 1) clearBuffer(buffer, pos.begin, pos.end);
 
 
                             if (isRTL) {
                             if (isRTL) {
                                 var p = seekPrevious(buffer, pos.end), np;
                                 var p = seekPrevious(buffer, pos.end), np;
@@ -1348,7 +1352,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.17
+Version: 2.2.18
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -1445,7 +1449,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.17
+Version: 2.2.18
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -1938,7 +1942,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.17
+Version: 2.2.18
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2113,7 +2117,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.17
+Version: 2.2.18
 
 
 Regex extensions on the jquery.inputmask base
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 Allows for using regular expressions as a mask
@@ -2131,11 +2135,14 @@ Allows for using regular expressions as a mask
                     validator: function (chrs, buffer, pos, strict, opts) {
                     validator: function (chrs, buffer, pos, strict, opts) {
 
 
                         function analyseRegex() {  //ENHANCE ME
                         function analyseRegex() {  //ENHANCE ME
-                            opts.regexSplit = [];
-                            if (opts.regex.indexOf("*") != (opts.regex.length - 1)) {
-                                opts.regex += "{1}";
-                            }
-                            opts.regexSplit.push(opts.regex);
+                            var regexSplitRegex = "\\[.*?\]\\*";
+
+                            opts.regexSplit = opts.regex.match(new RegExp(regexSplitRegex, "g"));
+
+                            //if (opts.regex.indexOf("*") != (opts.regex.length - 1)) {
+                            //    opts.regex += "{1}";
+                            //}
+                            //opts.regexSplit.push(opts.regex);
                         }
                         }
 
 
                         if (opts.regexSplit == null) {
                         if (opts.regexSplit == null) {
@@ -2149,7 +2156,7 @@ Allows for using regular expressions as a mask
                             regexPart += opts.regexSplit[i];
                             regexPart += opts.regexSplit[i];
                             var exp = new RegExp("^" + regexPart + "$");
                             var exp = new RegExp("^" + regexPart + "$");
                             isValid = exp.test(bufferStr);
                             isValid = exp.test(bufferStr);
-                            console.log(bufferStr + ' ' + isValid);
+                            console.log(bufferStr + ' ' + isValid + ' ' + regexPart);
                             if (isValid) break;
                             if (isValid) break;
                         }
                         }
 
 

File diff suppressed because it is too large
+ 59 - 59
dist/jquery.inputmask.bundle.min.js


File diff suppressed because it is too large
+ 38 - 38
dist/min/jquery.inputmask.js


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

@@ -1 +1 @@
-(function(b){b.extend(b.inputmask.defaults.aliases,{Regex:{mask:"r",greedy:!1,repeat:10,regex:null,regexSplit:null,definitions:{r:{validator:function(f,c,d,e,a){null==a.regexSplit&&(a.regexSplit=[],a.regex.indexOf("*")!=a.regex.length-1&&(a.regex+="{1}"),a.regexSplit.push(a.regex));var b=c.slice(),c="",e=!1;b.splice(d,0,f);f=b.join("");for(d=0;d<a.regexSplit.length&&!(c+=a.regexSplit[d],e=RegExp("^"+c+"$").test(f),console.log(f+" "+e),e);d++);return e},cardinality:1}}}})})(jQuery);
+(function(b){b.extend(b.inputmask.defaults.aliases,{Regex:{mask:"r",greedy:!1,repeat:10,regex:null,regexSplit:null,definitions:{r:{validator:function(f,a,c,d,e){null==e.regexSplit&&(e.regexSplit=e.regex.match(RegExp("\\[.*?]\\*","g")));var b=a.slice(),a="",d=!1;b.splice(c,0,f);f=b.join("");for(c=0;c<e.regexSplit.length&&!(a+=e.regexSplit[c],d=RegExp("^"+a+"$").test(f),console.log(f+" "+d+" "+a),d);c++);return d},cardinality:1}}}})})(jQuery);

+ 1 - 1
jquery.inputmask.jquery.json

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

+ 20 - 16
js/jquery.inputmask.js

@@ -413,7 +413,7 @@
                 return getActiveMaskSet()['_buffer'];
                 return getActiveMaskSet()['_buffer'];
             }
             }
 
 
-            function isValid(pos, c, buffer, strict, isRTL) { //strict true ~ no correction or autofill
+            function isValid(pos, c, buffer, strict, isRTL, checkVal) { //strict true ~ no correction or autofill
                 function _isValid(position, activeMaskset) {
                 function _isValid(position, activeMaskset) {
                     var testPos = determineTestPosition(position), loopend = c ? 1 : 0, chrs = '';
                     var testPos = determineTestPosition(position), loopend = c ? 1 : 0, chrs = '';
                     for (var i = activeMaskset['tests'][testPos].cardinality; i > loopend; i--) {
                     for (var i = activeMaskset['tests'][testPos].cardinality; i > loopend; i--) {
@@ -428,7 +428,7 @@
                     return activeMaskset['tests'][testPos].fn != null ? activeMaskset['tests'][testPos].fn.test(chrs, buffer, position, strict, opts) : false;
                     return activeMaskset['tests'][testPos].fn != null ? activeMaskset['tests'][testPos].fn.test(chrs, buffer, position, strict, opts) : false;
                 }
                 }
 
 
-                if (strict) {
+                if (strict || checkVal) {
                     var rslt = _isValid(pos, getActiveMaskSet()); //only check validity in current mask when validating strict
                     var rslt = _isValid(pos, getActiveMaskSet()); //only check validity in current mask when validating strict
 
 
                     if (rslt !== false) {
                     if (rslt !== false) {
@@ -479,19 +479,21 @@
                     }
                     }
                 });
                 });
                 activeMasksetIndex = currentActiveMasksetIndex; //reset activeMasksetIndex
                 activeMasksetIndex = currentActiveMasksetIndex; //reset activeMasksetIndex
-                determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL);
+                determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL, c);
                 result = results[activeMasksetIndex] || result;
                 result = results[activeMasksetIndex] || result;
                 setTimeout(function () { opts.onKeyValidation.call(this, result, opts); }, 0); //extra stuff to execute on keydown
                 setTimeout(function () { opts.onKeyValidation.call(this, result, opts); }, 0); //extra stuff to execute on keydown
                 return result;
                 return result;
             }
             }
 
 
-            function determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL) {
+            function determineActiveMasksetIndex(buffer, pos, currentActiveMasksetIndex, isRTL, c) {
                 $.each(masksets, function (index, value) {
                 $.each(masksets, function (index, value) {
                     var activeMaskset = this;
                     var activeMaskset = this;
-                    if (activeMaskset['lastValidPosition'] && (isRTL || opts.numericInput) ? activeMaskset['lastValidPosition'] <= pos : activeMaskset['lastValidPosition'] >= pos) {
+                    if (activeMaskset['lastValidPosition'] != undefined
+                        //&& index != currentActiveMasksetIndex
+                        && ((isRTL || opts.numericInput) ? activeMaskset['lastValidPosition'] <= pos : activeMaskset['lastValidPosition'] >= pos)) {
                         activeMasksetIndex = index;
                         activeMasksetIndex = index;
                         //reset to correct masktemplate
                         //reset to correct masktemplate
-                        checkVal(undefined, buffer, false, false, buffer.join(''), isRTL);
+                        checkVal(undefined, buffer, false, true, false, buffer.join(''), isRTL);
                         return false; //breaks
                         return false; //breaks
                     }
                     }
                 });
                 });
@@ -597,10 +599,12 @@
             }
             }
 
 
             //inputData can be used to override the value used to check
             //inputData can be used to override the value used to check
-            function checkVal(input, buffer, clearInvalid, skipRadixHandling, inputData, rtl) {
+            function checkVal(input, buffer, writeOut, strict, skipRadixHandling, inputData, rtl) {
                 var isRTL = rtl != undefined ? rtl : $(input).data('inputmask')['isRTL'],
                 var isRTL = rtl != undefined ? rtl : $(input).data('inputmask')['isRTL'],
                     inputValue = truncateInput(inputData != undefined ? inputData : input._valueGet(), isRTL).split('');
                     inputValue = truncateInput(inputData != undefined ? inputData : input._valueGet(), isRTL).split('');
 
 
+                strict = strict != undefined ? strict : true;
+
                 var maskL = getMaskLength(buffer);
                 var maskL = getMaskLength(buffer);
                 if (isRTL) { //align inputValue for RTL/numeric input
                 if (isRTL) { //align inputValue for RTL/numeric input
                     var inputValueRev = inputValue.reverse(); inputValueRev.length = maskL;
                     var inputValueRev = inputValue.reverse(); inputValueRev.length = maskL;
@@ -623,7 +627,7 @@
                     for (var pos = checkPosition + 1; pos < maskL; pos++) {
                     for (var pos = checkPosition + 1; pos < maskL; pos++) {
                         if (isMask(pos)) {
                         if (isMask(pos)) {
                             var c = inputValue[i];
                             var c = inputValue[i];
-                            if ((np = isValid(pos, c, buffer, !clearInvalid, isRTL)) !== false) {
+                            if ((np = isValid(pos, c, buffer, strict, isRTL, true)) !== false) {
                                 if (np !== true) {
                                 if (np !== true) {
                                     pos = np.pos != undefined ? np.pos : pos; //set new position from isValid
                                     pos = np.pos != undefined ? np.pos : pos; //set new position from isValid
                                     c = np.c != undefined ? np.c : c; //set new char from isValid
                                     c = np.c != undefined ? np.c : c; //set new char from isValid
@@ -657,7 +661,7 @@
                     buffer.length = newBuffer.length;
                     buffer.length = newBuffer.length;
                 }
                 }
 
 
-                if (clearInvalid) {
+                if (writeOut) {
                     writeBuffer(input, buffer);
                     writeBuffer(input, buffer);
                 }
                 }
                 return isRTL ? (opts.numericInput ? (opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1 && skipRadixHandling !== true ? $.inArray(opts.radixPoint, buffer) : seekNext(buffer, maskL)) : seekNext(buffer, rtlMatch)) : seekNext(buffer, lastMatch);
                 return isRTL ? (opts.numericInput ? (opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1 && skipRadixHandling !== true ? $.inArray(opts.radixPoint, buffer) : seekNext(buffer, maskL)) : seekNext(buffer, rtlMatch)) : seekNext(buffer, lastMatch);
@@ -701,7 +705,7 @@
                 var input = $input[0];
                 var input = $input[0];
                 if (getActiveTests() && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                 if (getActiveTests() && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                     var buffer = getActiveBuffer().slice();
                     var buffer = getActiveBuffer().slice();
-                    checkVal(input, buffer);
+                    checkVal(input, buffer, false);
                     return $.map(buffer, function (element, index) {
                     return $.map(buffer, function (element, index) {
                         return isMask(index) && isValid(index, element, buffer, true) ? element : null;
                         return isMask(index) && isValid(index, element, buffer, true) ? element : null;
                     }).join('');
                     }).join('');
@@ -916,14 +920,14 @@
                 ).bind(pasteEvent + ".inputmask dragdrop.inputmask drop.inputmask", function () {
                 ).bind(pasteEvent + ".inputmask dragdrop.inputmask drop.inputmask", function () {
                     var input = this;
                     var input = this;
                     setTimeout(function () {
                     setTimeout(function () {
-                        caret(input, checkVal(input, buffer, true));
+                        caret(input, checkVal(input, buffer, true, false));
                         if (isComplete(buffer))
                         if (isComplete(buffer))
                             $input.trigger("complete");
                             $input.trigger("complete");
                     }, 0);
                     }, 0);
                 }).bind('setvalue.inputmask', function () {
                 }).bind('setvalue.inputmask', function () {
                     var input = this;
                     var input = this;
                     undoBuffer = input._valueGet();
                     undoBuffer = input._valueGet();
-                    checkVal(input, buffer, true);
+                    checkVal(input, buffer, true, false);
                     if (input._valueGet() == getActiveBuffer().join(''))
                     if (input._valueGet() == getActiveBuffer().join(''))
                         input._valueSet('');
                         input._valueSet('');
                 }).bind('complete.inputmask', opts.oncomplete)
                 }).bind('complete.inputmask', opts.oncomplete)
@@ -1185,7 +1189,7 @@
                         e.preventDefault(); //stop default action but allow propagation
                         e.preventDefault(); //stop default action but allow propagation
                     } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
                     } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
                         setTimeout(function () {
                         setTimeout(function () {
-                            var caretPos = checkVal(input, buffer, false, true);
+                            var caretPos = checkVal(input, buffer, false);
                             if (!opts.insertMode && caretPos == getMaskLength(buffer) && !e.shiftKey) caretPos--;
                             if (!opts.insertMode && caretPos == getMaskLength(buffer) && !e.shiftKey) caretPos--;
                             caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
                             caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
                         }, 0);
                         }, 0);
@@ -1194,7 +1198,7 @@
                     }
                     }
                     else if (k == opts.keyCode.ESCAPE) {//escape
                     else if (k == opts.keyCode.ESCAPE) {//escape
                         input._valueSet(undoBuffer);
                         input._valueSet(undoBuffer);
-                        caret(input, 0, checkVal(input, buffer));
+                        caret(input, 0, checkVal(input, buffer, false));
                     } else if (k == opts.keyCode.INSERT) {//insert
                     } else if (k == opts.keyCode.INSERT) {//insert
                         opts.insertMode = !opts.insertMode;
                         opts.insertMode = !opts.insertMode;
                         caret(input, !opts.insertMode && pos.begin == getMaskLength(buffer) ? pos.begin - 1 : pos.begin);
                         caret(input, !opts.insertMode && pos.begin == getMaskLength(buffer) ? pos.begin - 1 : pos.begin);
@@ -1235,14 +1239,14 @@
                         caret(input, seekNext(buffer, radixPosition != -1 ? radixPosition : getMaskLength(buffer)));
                         caret(input, seekNext(buffer, radixPosition != -1 ? radixPosition : getMaskLength(buffer)));
                     }
                     }
 
 
-                    if (e.metaKey || ignorable) {
+                    if (e.ctrlKey || e.metaKey || ignorable) {
                         return true;
                         return true;
                     } else {
                     } else {
                         if (k) {
                         if (k) {
                             //$input.trigger('input');
                             //$input.trigger('input');
 
 
                             var pos = caret(input), maskL = getMaskLength(buffer), writeOutBuffer = true;
                             var pos = caret(input), maskL = getMaskLength(buffer), writeOutBuffer = true;
-                            clearBuffer(buffer, pos.begin, pos.end);
+                            if ((pos.end - pos.begin) > 1) clearBuffer(buffer, pos.begin, pos.end);
 
 
                             if (isRTL) {
                             if (isRTL) {
                                 var p = seekPrevious(buffer, pos.end), np;
                                 var p = seekPrevious(buffer, pos.end), np;