ソースを参照

Merge branch '1.x' into 2.x

Robin Herbots 13 年 前
コミット
1a80b31170
2 ファイル変更46 行追加29 行削除
  1. 14 3
      README.md
  2. 32 26
      js/jquery.inputmask.js

+ 14 - 3
README.md

@@ -2,7 +2,7 @@
 
 jquery.inputmask is a jquery plugin which create an input mask.
 
-Copyright (c) 2010 - 2012 Robin Herbots
+Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 
 The plugin is based on the idea of the maskedinput plugin of Josh Bush (http://digitalbush.com/projects/masked-input-plugin), but has finer control over the 'mask-definitions'.
@@ -55,7 +55,7 @@ In the jquery.inputmask.extensions.js you find a full date input validation whic
 Also extra features like mask-repetitions (greedy and non-gready) and many other additions are included.  In the examples you will find more about them.
 
 
-Usage:
+## Usage:
 
 Include the js-files:
 
@@ -75,7 +75,7 @@ $(document).ready(function(){
 });
 ```
 
-## Extra options:
+## Options:
 
 ### change the placeholder
 
@@ -336,6 +336,17 @@ $(document).ready(function(){
 								} });
 });
 ```
+### isComplete
+
+Verify wheter the current value is complete or not.
+
+```javascript
+$(document).ready(function(){
+    if($("#ssn").inputmask("isComplete")){
+		//do something
+	}
+});
+```
 
 ## Supported markup options
 ### RTL attribute

+ 32 - 26
js/jquery.inputmask.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.0.7
+* Version: 2.0.7a
 */
 
 (function ($) {
@@ -142,6 +142,13 @@
                         else return "";
                     case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value 
                         return this.data('inputmask') ? !this.data('inputmask')['autoUnmask'] : false;
+					case "isComplete":
+						masksets = this.data('inputmask')['masksets'];
+                        activeMasksetIndex = this.data('inputmask')['activeMasksetIndex'];
+                        opts.greedy = this.data('inputmask')['greedy'];
+                        opts.repeat = this.data('inputmask')['repeat'];
+                        opts.definitions = this.data('inputmask')['definitions'];
+						return isComplete(this);
                     default:
                         //check if the fn is an alias
                         if (!resolveAlias(fn)) {
@@ -639,6 +646,30 @@
                     return caretpos;
                 }
             };
+			
+	       function isComplete(npt) {
+                    var complete = false, nptValue = npt._valueGet(), ml = nptValue.length
+                    currentActiveMasksetIndex = activeMasksetIndex, highestValidPosition = 0;
+                    $.each(masksets, function (ndx, ms) {
+                        activeMasksetIndex = ndx;
+                        var aml = getMaskLength();
+                        if (ms["lastValidPosition"] >= highestValidPosition && ms["lastValidPosition"] == (aml - 1)) {
+                            var msComplete = true;
+                            for (var i = 0; i < aml; i++) {
+                                if (isMask(i) && nptValue.charAt(i) == getPlaceHolder(i)) {
+                                    msComplete = false;
+                                    break;
+                                }
+                            }
+                            complete = complete || msComplete;
+                            if (complete) //break loop
+                                return false;
+                        }
+                        highestValidPosition = ms["lastValidPosition"];
+                    });
+                    activeMasksetIndex = currentActiveMasksetIndex; //reset activeMaskset
+                    return complete;
+            }
 
             function mask(el) {
                 var $input = $(el);
@@ -812,31 +843,6 @@
                 installEventRuler(el);
 
                 //private functions
-                function isComplete(npt) {
-                    var complete = false, nptValue = npt._valueGet(), ml = nptValue.length
-                    currentActiveMasksetIndex = activeMasksetIndex, highestValidPosition = 0;
-                    $.each(masksets, function (ndx, ms) {
-                        activeMasksetIndex = ndx;
-                        var aml = getMaskLength();
-                        if (ms["lastValidPosition"] >= highestValidPosition && ms["lastValidPosition"] == (aml - 1)) {
-                            var msComplete = true;
-                            for (var i = 0; i < aml; i++) {
-                                if (isMask(i) && nptValue.charAt(i) == getPlaceHolder(i)) {
-                                    msComplete = false;
-                                    break;
-                                }
-                            }
-                            complete = complete || msComplete;
-                            if (complete) //break loop
-                                return false;
-                        }
-                        highestValidPosition = ms["lastValidPosition"];
-                    });
-                    activeMasksetIndex = currentActiveMasksetIndex; //reset activeMaskset
-                    return complete;
-                }
-
-
                 function installEventRuler(npt) {
                     var events = $._data(npt).events;