|
|
@@ -38,10 +38,10 @@ class DateObject {
|
|
|
let dynMatches = new RegExp("\\d+$").exec(match[0]), fcode = dynMatches ? (match[0][0] + "x") : match[0],
|
|
|
value;
|
|
|
if (mask !== undefined) {
|
|
|
- console.log("mask", mask);
|
|
|
+ // console.log("mask", mask);
|
|
|
if (dynMatches) {
|
|
|
let lastIndex = getTokenizer(opts).lastIndex,
|
|
|
- tokenMatch = getTokenMatch(match.index, opts, inputmask && inputmask.maskset);
|
|
|
+ tokenMatch = getTokenMatch.call(inputmask, match.index, opts, inputmask && inputmask.maskset);
|
|
|
getTokenizer(opts).lastIndex = lastIndex;
|
|
|
value = mask.slice(0, mask.indexOf(tokenMatch.nextMatch[0]));
|
|
|
} else {
|
|
|
@@ -294,7 +294,7 @@ function isValidDate(dateParts, currentResult, opts) {
|
|
|
return currentResult;
|
|
|
} else { //take corrective action if possible
|
|
|
if (dateParts.day == "29") {
|
|
|
- var tokenMatch = getTokenMatch(currentResult.pos, opts, inputmask.maskset);
|
|
|
+ var tokenMatch = getTokenMatch.call(inputmask, currentResult.pos, opts, inputmask.maskset);
|
|
|
if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] === "yyyy" && currentResult.pos - tokenMatch.targetMatchIndex === 2) {
|
|
|
currentResult.remove = currentResult.pos + 1;
|
|
|
return currentResult;
|
|
|
@@ -432,12 +432,24 @@ function importDate(dateObj, opts) {
|
|
|
}
|
|
|
|
|
|
function getTokenMatch(pos, opts, maskset) {
|
|
|
+ var inputmask = this;
|
|
|
var masksetHint = (maskset && maskset.tests[pos]) ? maskset.tests[pos][0].match.placeholder : "";
|
|
|
var calcPos = 0, targetMatch, match, matchLength = 0;
|
|
|
getTokenizer(opts).lastIndex = 0;
|
|
|
while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
|
|
|
var dynMatches = new RegExp("\\d+$").exec(match[0]);
|
|
|
- matchLength = dynMatches ? parseInt(dynMatches[0]) : match[0].length;
|
|
|
+ if (dynMatches) {
|
|
|
+ matchLength = parseInt(dynMatches[0]);
|
|
|
+ } else {
|
|
|
+ let targetSymbol = match[0][0],
|
|
|
+ ndx = calcPos;
|
|
|
+ while (inputmask && getTest.call(inputmask, ndx).match.placeholder === targetSymbol) {
|
|
|
+ ndx++;
|
|
|
+ }
|
|
|
+ matchLength = ndx - calcPos;
|
|
|
+ if(matchLength === 0) matchLength = match[0].length;
|
|
|
+ }
|
|
|
+
|
|
|
calcPos += matchLength;
|
|
|
if (match[0].indexOf(masksetHint) != -1 || calcPos >= pos + 1) {
|
|
|
// console.log("gettokenmatch " + match[0] + " ~ " + (maskset ? maskset.tests[pos][0].match.placeholder : ""));
|
|
|
@@ -478,9 +490,10 @@ Inputmask.extendAliases({
|
|
|
max: null, //needs to be in the same format as the inputfornat,
|
|
|
skipOptionalPartCharacter: "",
|
|
|
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
|
|
|
+ const inputmask = this;
|
|
|
if (strict) return true;
|
|
|
if (isNaN(c) && buffer[pos] !== c) {
|
|
|
- var tokenMatch = getTokenMatch(pos, opts);
|
|
|
+ var tokenMatch = getTokenMatch.call(inputmask, pos, opts, maskset);
|
|
|
if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) {
|
|
|
var validator = formatcode(tokenMatch.targetMatch)[0];
|
|
|
if (new RegExp(validator).test("0" + buffer[pos - 1])) {
|
|
|
@@ -500,11 +513,11 @@ Inputmask.extendAliases({
|
|
|
if (strict) return true;
|
|
|
var tokenMatch, validator;
|
|
|
if (currentResult === false) { //try some shifting
|
|
|
- tokenMatch = getTokenMatch(pos + 1, opts, maskset);
|
|
|
+ tokenMatch = getTokenMatch.call(inputmask, pos + 1, opts, maskset);
|
|
|
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
|
|
|
validator = formatcode(tokenMatch.targetMatch)[0];
|
|
|
} else {
|
|
|
- tokenMatch = getTokenMatch(pos + 2, opts, maskset);
|
|
|
+ tokenMatch = getTokenMatch.call(inputmask,pos + 2, opts, maskset);
|
|
|
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos + 1 && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
|
|
|
validator = formatcode(tokenMatch.targetMatch)[0];
|
|
|
}
|
|
|
@@ -537,7 +550,7 @@ Inputmask.extendAliases({
|
|
|
}
|
|
|
|
|
|
//full validate target
|
|
|
- tokenMatch = getTokenMatch(pos, opts, maskset);
|
|
|
+ tokenMatch = getTokenMatch.call(inputmask, pos, opts, maskset);
|
|
|
if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
|
|
|
let fcode = formatcode(tokenMatch.targetMatch);
|
|
|
validator = fcode[0];
|