浏览代码

defaults etc

Robin Herbots 10 年之前
父节点
当前提交
cbce2ffeaa

+ 7 - 0
CHANGELOG.md

@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
 
 ## [Unreleased]
 
+### Added
+- inputmask class
+- setting defaults / definitions / aliases
+  - inputmask.extendDefaults
+  - inputmask.extendDefinitions
+  - inputmask.extendAliases
+
 ### Updates
 - separate jquery plugin code from the inputmask core (first step to remove jquery dependency from the inputmask core)
 - Update placeholder handling

文件差异内容过多而无法显示
+ 217 - 280
README.md


+ 11 - 0
js/inputmask.js

@@ -211,6 +211,17 @@
     }
   }
 
+  //aply defaults, definitions, aliases
+  inputmask.extendDefaults = function(options) {
+    $.extend(inputmask.prototype.defaults, options);
+  }
+  inputmask.extendDefinitions = function(definition) {
+    $.extend(inputmask.prototype.defaults.definitions, definition);
+  }
+  inputmask.extendAliases = function(alias) {
+    $.extend(inputmask.prototype.defaults.aliases, alias);
+  }
+
   //helper functions
   function isInputEventSupported(eventName) {
     var el = document.createElement('input'),

文件差异内容过多而无法显示
+ 576 - 576
js/jquery.inputmask.date.extensions.js


+ 118 - 118
js/jquery.inputmask.extensions.js

@@ -8,122 +8,122 @@ Version: 0.0.0-dev
 Optional extensions on the jquery.inputmask base
 */
 (function($) {
-	//extra definitions
-	$.extend($.inputmask.defaults.definitions, {
-		'A': {
-			validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
-			cardinality: 1,
-			casing: "upper" //auto uppercasing
-		},
-		'#': {
-			validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
-			cardinality: 1,
-			casing: "upper"
-		}
-	});
-	$.extend($.inputmask.defaults.aliases, {
-		'url': {
-			mask: "ir",
-			placeholder: "",
-			separator: "",
-			defaultPrefix: "http://",
-			regex: {
-				urlpre1: new RegExp("[fh]"),
-				urlpre2: new RegExp("(ft|ht)"),
-				urlpre3: new RegExp("(ftp|htt)"),
-				urlpre4: new RegExp("(ftp:|http|ftps)"),
-				urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"),
-				urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"),
-				urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"),
-				urlpre8: new RegExp("(ftp://|ftps://|http://|https://)")
-			},
-			definitions: {
-				'i': {
-					validator: function(chrs, maskset, pos, strict, opts) {
-						return true;
-					},
-					cardinality: 8,
-					prevalidator: (function() {
-						var result = [],
-							prefixLimit = 8;
-						for (var i = 0; i < prefixLimit; i++) {
-							result[i] = (function() {
-								var j = i;
-								return {
-									validator: function(chrs, maskset, pos, strict, opts) {
-										if (opts.regex["urlpre" + (j + 1)]) {
-											var tmp = chrs,
-												k;
-											if (((j + 1) - chrs.length) > 0) {
-												tmp = maskset.buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp;
-											}
-											var isValid = opts.regex["urlpre" + (j + 1)].test(tmp);
-											if (!strict && !isValid) {
-												pos = pos - j;
-												for (k = 0; k < opts.defaultPrefix.length; k++) {
-													maskset.buffer[pos] = opts.defaultPrefix[k];
-													pos++;
-												}
-												for (k = 0; k < tmp.length - 1; k++) {
-													maskset.buffer[pos] = tmp[k];
-													pos++;
-												}
-												return {
-													"pos": pos
-												};
-											}
-											return isValid;
-										} else {
-											return false;
-										}
-									},
-									cardinality: j
-								};
-							})();
-						}
-						return result;
-					})()
-				},
-				"r": {
-					validator: ".",
-					cardinality: 50
-				}
-			},
-			insertMode: false,
-			autoUnmask: false
-		},
-		"ip": { //ip-address mask
-			mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
-			definitions: {
-				'i': {
-					validator: function(chrs, maskset, pos, strict, opts) {
-						if (pos - 1 > -1 && maskset.buffer[pos - 1] != ".") {
-							chrs = maskset.buffer[pos - 1] + chrs;
-							if (pos - 2 > -1 && maskset.buffer[pos - 2] != ".") {
-								chrs = maskset.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
-				}
-			}
-		},
-		"email": {
-			mask: "*{1,64}[.*{1,64}][.*{1,64}][.*{1,64}]@*{1,64}[.*{2,64}][.*{2,6}][.*{1,2}]",
-			greedy: false,
-			onBeforePaste: function(pastedValue, opts) {
-				pastedValue = pastedValue.toLowerCase();
-				return pastedValue.replace("mailto:", "");
-			},
-			definitions: {
-				'*': {
-					validator: "[0-9A-Za-z!#$%&'*+/=?^_`{|}~\-]",
-					cardinality: 1,
-					casing: "lower"
-				}
-			}
-		}
-	});
-	return $.fn.inputmask;
+  //extra definitions
+  inputmask.extendDefinitions({
+    'A': {
+      validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
+      cardinality: 1,
+      casing: "upper" //auto uppercasing
+    },
+    '#': {
+      validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
+      cardinality: 1,
+      casing: "upper"
+    }
+  });
+  inputmask.extendAliases({
+    'url': {
+      mask: "ir",
+      placeholder: "",
+      separator: "",
+      defaultPrefix: "http://",
+      regex: {
+        urlpre1: new RegExp("[fh]"),
+        urlpre2: new RegExp("(ft|ht)"),
+        urlpre3: new RegExp("(ftp|htt)"),
+        urlpre4: new RegExp("(ftp:|http|ftps)"),
+        urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"),
+        urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"),
+        urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"),
+        urlpre8: new RegExp("(ftp://|ftps://|http://|https://)")
+      },
+      definitions: {
+        'i': {
+          validator: function(chrs, maskset, pos, strict, opts) {
+            return true;
+          },
+          cardinality: 8,
+          prevalidator: (function() {
+            var result = [],
+              prefixLimit = 8;
+            for (var i = 0; i < prefixLimit; i++) {
+              result[i] = (function() {
+                var j = i;
+                return {
+                  validator: function(chrs, maskset, pos, strict, opts) {
+                    if (opts.regex["urlpre" + (j + 1)]) {
+                      var tmp = chrs,
+                        k;
+                      if (((j + 1) - chrs.length) > 0) {
+                        tmp = maskset.buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp;
+                      }
+                      var isValid = opts.regex["urlpre" + (j + 1)].test(tmp);
+                      if (!strict && !isValid) {
+                        pos = pos - j;
+                        for (k = 0; k < opts.defaultPrefix.length; k++) {
+                          maskset.buffer[pos] = opts.defaultPrefix[k];
+                          pos++;
+                        }
+                        for (k = 0; k < tmp.length - 1; k++) {
+                          maskset.buffer[pos] = tmp[k];
+                          pos++;
+                        }
+                        return {
+                          "pos": pos
+                        };
+                      }
+                      return isValid;
+                    } else {
+                      return false;
+                    }
+                  },
+                  cardinality: j
+                };
+              })();
+            }
+            return result;
+          })()
+        },
+        "r": {
+          validator: ".",
+          cardinality: 50
+        }
+      },
+      insertMode: false,
+      autoUnmask: false
+    },
+    "ip": { //ip-address mask
+      mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
+      definitions: {
+        'i': {
+          validator: function(chrs, maskset, pos, strict, opts) {
+            if (pos - 1 > -1 && maskset.buffer[pos - 1] != ".") {
+              chrs = maskset.buffer[pos - 1] + chrs;
+              if (pos - 2 > -1 && maskset.buffer[pos - 2] != ".") {
+                chrs = maskset.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
+        }
+      }
+    },
+    "email": {
+      mask: "*{1,64}[.*{1,64}][.*{1,64}][.*{1,64}]@*{1,64}[.*{2,64}][.*{2,6}][.*{1,2}]",
+      greedy: false,
+      onBeforePaste: function(pastedValue, opts) {
+        pastedValue = pastedValue.toLowerCase();
+        return pastedValue.replace("mailto:", "");
+      },
+      definitions: {
+        '*': {
+          validator: "[0-9A-Za-z!#$%&'*+/=?^_`{|}~\-]",
+          cardinality: 1,
+          casing: "lower"
+        }
+      }
+    }
+  });
+  return $.fn.inputmask;
 })(jQuery);

文件差异内容过多而无法显示
+ 560 - 560
js/jquery.inputmask.numeric.extensions.js


+ 42 - 42
js/jquery.inputmask.phone.extensions.js

@@ -18,49 +18,49 @@ When using this extension make sure you specify the correct url to get the masks
 
 */
 (function($) {
-	$.extend($.inputmask.defaults.aliases, {
-		'phone': {
-			url: "phone-codes/phone-codes.js",
-			countrycode: "",
-			mask: function(opts) {
-				opts.definitions['#'] = opts.definitions['9'];
-				var maskList = [];
-				$.ajax({
-					url: opts.url,
-					async: false,
-					dataType: 'json',
-					success: function(response) {
-						maskList = response;
-					},
-					error: function(xhr, ajaxOptions, thrownError) {
-						alert(thrownError + " - " + opts.url);
-					}
-				});
+  inputmask.extendAliases({
+    'phone': {
+      url: "phone-codes/phone-codes.js",
+      countrycode: "",
+      mask: function(opts) {
+        opts.definitions['#'] = opts.definitions['9'];
+        var maskList = [];
+        $.ajax({
+          url: opts.url,
+          async: false,
+          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;
-				});
+        maskList = maskList.sort(function(a, b) {
+          return (a["mask"] || a) < (b["mask"] || b) ? -1 : 1;
+        });
 
-				return maskList;
-			},
-			keepStatic: false,
-			nojumps: true,
-			nojumpsThreshold: 1,
-			onBeforeMask: function(value, opts) {
-				var processedValue = value.replace(/^0/g, "");
-				if (processedValue.indexOf(opts.countrycode) > 1 || processedValue.indexOf(opts.countrycode) == -1) {
-					processedValue = "+" + opts.countrycode + processedValue;
-				}
+        return maskList;
+      },
+      keepStatic: false,
+      nojumps: true,
+      nojumpsThreshold: 1,
+      onBeforeMask: function(value, opts) {
+        var processedValue = value.replace(/^0/g, "");
+        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;
+        return processedValue;
+      }
+    },
+    'phonebe': {
+      alias: "phone",
+      url: "phone-codes/phone-be.js",
+      countrycode: "32",
+      nojumpsThreshold: 4
+    }
+  });
+  return $.fn.inputmask;
 })(jQuery);

+ 180 - 180
js/jquery.inputmask.regex.extensions.js

@@ -9,195 +9,195 @@ Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 */
 (function($) {
-	$.extend($.inputmask.defaults.aliases, { // $(selector).inputmask("Regex", { regex: "[0-9]*"}
-		'Regex': {
-			mask: "r",
-			greedy: false,
-			repeat: "*",
-			regex: null,
-			regexTokens: null,
-			//Thx to https://github.com/slevithan/regex-colorizer for the tokenizer regex
-			tokenizer: /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g,
-			quantifierFilter: /[0-9]+[^,]/,
-			isComplete: function(buffer, opts) {
-				return new RegExp(opts.regex).test(buffer.join(''));
-			},
-			definitions: {
-				'r': {
-					validator: function(chrs, maskset, pos, strict, opts) {
-						function regexToken(isGroup, isQuantifier) {
-							this.matches = [];
-							this.isGroup = isGroup || false;
-							this.isQuantifier = isQuantifier || false;
-							this.quantifier = {
-								min: 1,
-								max: 1
-							};
-							this.repeaterPart = undefined;
-						}
+  inputmask.extendAliases({ // $(selector).inputmask("Regex", { regex: "[0-9]*"}
+    'Regex': {
+      mask: "r",
+      greedy: false,
+      repeat: "*",
+      regex: null,
+      regexTokens: null,
+      //Thx to https://github.com/slevithan/regex-colorizer for the tokenizer regex
+      tokenizer: /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g,
+      quantifierFilter: /[0-9]+[^,]/,
+      isComplete: function(buffer, opts) {
+        return new RegExp(opts.regex).test(buffer.join(''));
+      },
+      definitions: {
+        'r': {
+          validator: function(chrs, maskset, pos, strict, opts) {
+            function regexToken(isGroup, isQuantifier) {
+              this.matches = [];
+              this.isGroup = isGroup || false;
+              this.isQuantifier = isQuantifier || false;
+              this.quantifier = {
+                min: 1,
+                max: 1
+              };
+              this.repeaterPart = undefined;
+            }
 
-						function analyseRegex() {
-							var currentToken = new regexToken(),
-								match, m, opengroups = [];
+            function analyseRegex() {
+              var currentToken = new regexToken(),
+                match, m, opengroups = [];
 
-							opts.regexTokens = [];
+              opts.regexTokens = [];
 
-							// The tokenizer regex does most of the tokenization grunt work
-							while (match = opts.tokenizer.exec(opts.regex)) {
-								m = match[0];
-								switch (m.charAt(0)) {
-									case "(": // Group opening
-										opengroups.push(new regexToken(true));
-										break;
-									case ")": // Group closing
-										var groupToken = opengroups.pop();
-										if (opengroups.length > 0) {
-											opengroups[opengroups.length - 1]["matches"].push(groupToken);
-										} else {
-											currentToken.matches.push(groupToken);
-										}
-										break;
-									case "{":
-									case "+":
-									case "*": //Quantifier
-										var quantifierToken = new regexToken(false, true);
-										m = m.replace(/[{}]/g, "");
-										var mq = m.split(","),
-											mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]),
-											mq1 = mq.length == 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
-										quantifierToken.quantifier = {
-											min: mq0,
-											max: mq1
-										};
-										if (opengroups.length > 0) {
-											var matches = opengroups[opengroups.length - 1]["matches"];
-											match = matches.pop();
-											if (!match["isGroup"]) {
-												var groupToken = new regexToken(true);
-												groupToken.matches.push(match);
-												match = groupToken;
-											}
-											matches.push(match);
-											matches.push(quantifierToken);
-										} else {
-											match = currentToken.matches.pop();
-											if (!match["isGroup"]) {
-												var groupToken = new regexToken(true);
-												groupToken.matches.push(match);
-												match = groupToken;
-											}
-											currentToken.matches.push(match);
-											currentToken.matches.push(quantifierToken);
-										}
-										break;
-									default:
-										if (opengroups.length > 0) {
-											opengroups[opengroups.length - 1]["matches"].push(m);
-										} else {
-											currentToken.matches.push(m);
-										}
-										break;
-								}
-							}
+              // The tokenizer regex does most of the tokenization grunt work
+              while (match = opts.tokenizer.exec(opts.regex)) {
+                m = match[0];
+                switch (m.charAt(0)) {
+                  case "(": // Group opening
+                    opengroups.push(new regexToken(true));
+                    break;
+                  case ")": // Group closing
+                    var groupToken = opengroups.pop();
+                    if (opengroups.length > 0) {
+                      opengroups[opengroups.length - 1]["matches"].push(groupToken);
+                    } else {
+                      currentToken.matches.push(groupToken);
+                    }
+                    break;
+                  case "{":
+                  case "+":
+                  case "*": //Quantifier
+                    var quantifierToken = new regexToken(false, true);
+                    m = m.replace(/[{}]/g, "");
+                    var mq = m.split(","),
+                      mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]),
+                      mq1 = mq.length == 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
+                    quantifierToken.quantifier = {
+                      min: mq0,
+                      max: mq1
+                    };
+                    if (opengroups.length > 0) {
+                      var matches = opengroups[opengroups.length - 1]["matches"];
+                      match = matches.pop();
+                      if (!match["isGroup"]) {
+                        var groupToken = new regexToken(true);
+                        groupToken.matches.push(match);
+                        match = groupToken;
+                      }
+                      matches.push(match);
+                      matches.push(quantifierToken);
+                    } else {
+                      match = currentToken.matches.pop();
+                      if (!match["isGroup"]) {
+                        var groupToken = new regexToken(true);
+                        groupToken.matches.push(match);
+                        match = groupToken;
+                      }
+                      currentToken.matches.push(match);
+                      currentToken.matches.push(quantifierToken);
+                    }
+                    break;
+                  default:
+                    if (opengroups.length > 0) {
+                      opengroups[opengroups.length - 1]["matches"].push(m);
+                    } else {
+                      currentToken.matches.push(m);
+                    }
+                    break;
+                }
+              }
 
-							if (currentToken.matches.length > 0)
-								opts.regexTokens.push(currentToken);
-						};
+              if (currentToken.matches.length > 0)
+                opts.regexTokens.push(currentToken);
+            };
 
-						function validateRegexToken(token, fromGroup) {
-							var isvalid = false;
-							if (fromGroup) {
-								regexPart += "(";
-								openGroupCount++;
-							}
-							for (var mndx = 0; mndx < token["matches"].length; mndx++) {
-								var matchToken = token["matches"][mndx];
-								if (matchToken["isGroup"] == true) {
-									isvalid = validateRegexToken(matchToken, true);
-								} else if (matchToken["isQuantifier"] == true) {
-									var crrntndx = $.inArray(matchToken, token["matches"]),
-										matchGroup = token["matches"][crrntndx - 1];
-									var regexPartBak = regexPart;
-									if (isNaN(matchToken.quantifier.max)) {
-										while (matchToken["repeaterPart"] && matchToken["repeaterPart"] != regexPart && matchToken["repeaterPart"].length > regexPart.length) {
-											isvalid = validateRegexToken(matchGroup, true);
-											if (isvalid) break;
-										}
-										isvalid = isvalid || validateRegexToken(matchGroup, true);
-										if (isvalid) matchToken["repeaterPart"] = regexPart;
-										regexPart = regexPartBak + matchToken.quantifier.max;
-									} else {
-										for (var i = 0, qm = matchToken.quantifier.max - 1; i < qm; i++) {
-											isvalid = validateRegexToken(matchGroup, true);
-											if (isvalid) break;
-										}
-										regexPart = regexPartBak + "{" + matchToken.quantifier.min + "," + matchToken.quantifier.max + "}";
-									}
-								} else if (matchToken["matches"] != undefined) {
-									for (var k = 0; k < matchToken.length; k++) {
-										isvalid = validateRegexToken(matchToken[k], fromGroup);
-										if (isvalid) break;
-									}
-								} else {
-									var testExp;
-									if (matchToken.charAt(0) == "[") {
-										testExp = regexPart;
-										testExp += matchToken;
-										for (var j = 0; j < openGroupCount; j++) {
-											testExp += ")";
-										}
-										var exp = new RegExp("^(" + testExp + ")$");
-										isvalid = exp.test(bufferStr);
-									} else {
-										for (var l = 0, tl = matchToken.length; l < tl; l++) {
-											if (matchToken.charAt(l) == "\\") continue;
-											testExp = regexPart;
-											testExp += matchToken.substr(0, l + 1);
-											testExp = testExp.replace(/\|$/, "");
-											for (var j = 0; j < openGroupCount; j++) {
-												testExp += ")";
-											}
-											var exp = new RegExp("^(" + testExp + ")$");
-											isvalid = exp.test(bufferStr);
-											if (isvalid) break;
-										}
-									}
-									regexPart += matchToken;
-								}
-								if (isvalid) break;
-							}
+            function validateRegexToken(token, fromGroup) {
+              var isvalid = false;
+              if (fromGroup) {
+                regexPart += "(";
+                openGroupCount++;
+              }
+              for (var mndx = 0; mndx < token["matches"].length; mndx++) {
+                var matchToken = token["matches"][mndx];
+                if (matchToken["isGroup"] == true) {
+                  isvalid = validateRegexToken(matchToken, true);
+                } else if (matchToken["isQuantifier"] == true) {
+                  var crrntndx = $.inArray(matchToken, token["matches"]),
+                    matchGroup = token["matches"][crrntndx - 1];
+                  var regexPartBak = regexPart;
+                  if (isNaN(matchToken.quantifier.max)) {
+                    while (matchToken["repeaterPart"] && matchToken["repeaterPart"] != regexPart && matchToken["repeaterPart"].length > regexPart.length) {
+                      isvalid = validateRegexToken(matchGroup, true);
+                      if (isvalid) break;
+                    }
+                    isvalid = isvalid || validateRegexToken(matchGroup, true);
+                    if (isvalid) matchToken["repeaterPart"] = regexPart;
+                    regexPart = regexPartBak + matchToken.quantifier.max;
+                  } else {
+                    for (var i = 0, qm = matchToken.quantifier.max - 1; i < qm; i++) {
+                      isvalid = validateRegexToken(matchGroup, true);
+                      if (isvalid) break;
+                    }
+                    regexPart = regexPartBak + "{" + matchToken.quantifier.min + "," + matchToken.quantifier.max + "}";
+                  }
+                } else if (matchToken["matches"] != undefined) {
+                  for (var k = 0; k < matchToken.length; k++) {
+                    isvalid = validateRegexToken(matchToken[k], fromGroup);
+                    if (isvalid) break;
+                  }
+                } else {
+                  var testExp;
+                  if (matchToken.charAt(0) == "[") {
+                    testExp = regexPart;
+                    testExp += matchToken;
+                    for (var j = 0; j < openGroupCount; j++) {
+                      testExp += ")";
+                    }
+                    var exp = new RegExp("^(" + testExp + ")$");
+                    isvalid = exp.test(bufferStr);
+                  } else {
+                    for (var l = 0, tl = matchToken.length; l < tl; l++) {
+                      if (matchToken.charAt(l) == "\\") continue;
+                      testExp = regexPart;
+                      testExp += matchToken.substr(0, l + 1);
+                      testExp = testExp.replace(/\|$/, "");
+                      for (var j = 0; j < openGroupCount; j++) {
+                        testExp += ")";
+                      }
+                      var exp = new RegExp("^(" + testExp + ")$");
+                      isvalid = exp.test(bufferStr);
+                      if (isvalid) break;
+                    }
+                  }
+                  regexPart += matchToken;
+                }
+                if (isvalid) break;
+              }
 
-							if (fromGroup) {
-								regexPart += ")";
-								openGroupCount--;
-							}
+              if (fromGroup) {
+                regexPart += ")";
+                openGroupCount--;
+              }
 
-							return isvalid;
-						}
+              return isvalid;
+            }
 
 
-						if (opts.regexTokens == null) {
-							analyseRegex();
-						}
+            if (opts.regexTokens == null) {
+              analyseRegex();
+            }
 
-						var cbuffer = maskset.buffer.slice(),
-							regexPart = "",
-							isValid = false,
-							openGroupCount = 0;
-						cbuffer.splice(pos, 0, chrs);
-						var bufferStr = cbuffer.join('');
-						for (var i = 0; i < opts.regexTokens.length; i++) {
-							var regexToken = opts.regexTokens[i];
-							isValid = validateRegexToken(regexToken, regexToken["isGroup"]);
-							if (isValid) break;
-						}
+            var cbuffer = maskset.buffer.slice(),
+              regexPart = "",
+              isValid = false,
+              openGroupCount = 0;
+            cbuffer.splice(pos, 0, chrs);
+            var bufferStr = cbuffer.join('');
+            for (var i = 0; i < opts.regexTokens.length; i++) {
+              var regexToken = opts.regexTokens[i];
+              isValid = validateRegexToken(regexToken, regexToken["isGroup"]);
+              if (isValid) break;
+            }
 
-						return isValid;
-					},
-					cardinality: 1
-				}
-			}
-		}
-	});
-	return $.fn.inputmask;
+            return isValid;
+          },
+          cardinality: 1
+        }
+      }
+    }
+  });
+  return $.fn.inputmask;
 })(jQuery);