|
|
@@ -26,8 +26,8 @@ function autoEscape(txt, opts) {
|
|
|
return escapedTxt;
|
|
|
}
|
|
|
|
|
|
-function alignDigits(buffer, digits, opts) {
|
|
|
- if (digits > 0 && !opts.digitsOptional) {
|
|
|
+function alignDigits(buffer, digits, opts, force) {
|
|
|
+ if (digits > 0 && (!opts.digitsOptional || force)) {
|
|
|
var radixPosition = $.inArray(opts.radixPoint, buffer);
|
|
|
if (radixPosition === -1) {
|
|
|
buffer.push(opts.radixPoint);
|
|
|
@@ -193,13 +193,17 @@ function decimalValidator(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
|
function checkForLeadingZeroes(buffer, opts) {
|
|
|
//check leading zeros
|
|
|
- var numberMatches = new RegExp("(^" + (opts.negationSymbol.front != "" ? Inputmask.escapeRegex(opts.negationSymbol.front) + "?" : "") + Inputmask.escapeRegex(opts.prefix) + ")(.*)(" + Inputmask.escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? Inputmask.escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(buffer.slice().reverse().join("")),
|
|
|
- number = numberMatches ? numberMatches[2] : "", leadingzeroes = false;
|
|
|
- if (number) {
|
|
|
- number = number.split(opts.radixPoint.charAt(0))[0];
|
|
|
- leadingzeroes = new RegExp("^[0" + opts.groupSeparator + "]*").exec(number);
|
|
|
+ try {
|
|
|
+ var numberMatches = new RegExp("(^" + (opts.negationSymbol.front !== "" ? Inputmask.escapeRegex(opts.negationSymbol.front) + "?" : "") + Inputmask.escapeRegex(opts.prefix) + ")(.*)(" + Inputmask.escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? Inputmask.escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(buffer.slice().reverse().join("")),
|
|
|
+ number = numberMatches ? numberMatches[2] : "", leadingzeroes = false;
|
|
|
+ if (number) {
|
|
|
+ number = number.split(opts.radixPoint.charAt(0))[0];
|
|
|
+ leadingzeroes = new RegExp("^[0" + opts.groupSeparator + "]*").exec(number);
|
|
|
+ }
|
|
|
+ return leadingzeroes && (leadingzeroes[0].length > 1 || leadingzeroes[0].length > 0 && leadingzeroes[0].length < number.length) ? leadingzeroes : false;
|
|
|
+ } catch(e){
|
|
|
+ console.log(buffer.slice().reverse().join(""));
|
|
|
}
|
|
|
- return leadingzeroes && (leadingzeroes[0].length > 1 || leadingzeroes[0].length > 0 && leadingzeroes[0].length < number.length) ? leadingzeroes : false;
|
|
|
}
|
|
|
|
|
|
//number aliases
|
|
|
@@ -254,7 +258,7 @@ Inputmask.extendAliases({
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos) {
|
|
|
+ preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
|
|
|
if (opts.__financeInput !== false && c === opts.radixPoint) return false;
|
|
|
var radixPos = $.inArray(opts.radixPoint, buffer);
|
|
|
pos = hanndleRadixDance(pos, c, radixPos, opts);
|
|
|
@@ -276,6 +280,8 @@ Inputmask.extendAliases({
|
|
|
caret: radixPos > pos ? pos + 1 : pos
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ if (strict) return true;
|
|
|
if (radixPos !== -1 && (opts._radixDance === true && isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) && radixPos !== pos)) {
|
|
|
return {
|
|
|
"caret": opts._radixDance && pos === radixPos - 1 ? radixPos + 1 : radixPos
|
|
|
@@ -284,7 +290,8 @@ Inputmask.extendAliases({
|
|
|
|
|
|
return {rewritePosition: (isSelection && opts.digitsOptional) ? caretPos.end : pos};
|
|
|
},
|
|
|
- postValidation: function (buffer, pos, currentResult, opts, maskset) {
|
|
|
+ postValidation: function (buffer, pos, currentResult, opts, maskset, strict) {
|
|
|
+ if (strict) return true;
|
|
|
if (opts.min !== null || opts.max !== null) {
|
|
|
var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
|
|
|
unmaskAsNumber: true
|
|
|
@@ -343,7 +350,8 @@ Inputmask.extendAliases({
|
|
|
|
|
|
var valueParts = initialValue.split(radixPoint),
|
|
|
integerPart = valueParts[0].replace(/[^\-0-9]/g, ""),
|
|
|
- decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "";
|
|
|
+ decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "",
|
|
|
+ forceDigits = valueParts.length > 1;
|
|
|
|
|
|
initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
|
|
|
|
|
|
@@ -379,7 +387,7 @@ Inputmask.extendAliases({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return alignDigits(initialValue.toString().split(""), digits, opts).join("");
|
|
|
+ return alignDigits(initialValue.toString().split(""), digits, opts, forceDigits).join("");
|
|
|
},
|
|
|
onBeforeWrite: function (e, buffer, caretPos, opts) {
|
|
|
function stripBuffer(buffer, stripRadix) {
|