|
@@ -19,577 +19,6 @@ Optional extensions on the jquery.inputmask base
|
|
|
(function($, Inputmask) {
|
|
(function($, Inputmask) {
|
|
|
//number aliases
|
|
//number aliases
|
|
|
Inputmask.extendAliases({
|
|
Inputmask.extendAliases({
|
|
|
- "numeric2": {
|
|
|
|
|
- mask: function(opts) {
|
|
|
|
|
- function autoEscape(txt) {
|
|
|
|
|
- var escapedTxt = "";
|
|
|
|
|
- for (var i = 0; i < txt.length; i++) {
|
|
|
|
|
- escapedTxt += opts.definitions[txt.charAt(i)] ? "\\" + txt.charAt(i) : txt.charAt(i);
|
|
|
|
|
- }
|
|
|
|
|
- return escapedTxt;
|
|
|
|
|
- }
|
|
|
|
|
- if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
|
|
|
|
|
- opts.integerDigits = opts.repeat;
|
|
|
|
|
- }
|
|
|
|
|
- opts.repeat = 0;
|
|
|
|
|
- if (opts.groupSeparator === opts.radixPoint) { //treat equal separator and radixpoint
|
|
|
|
|
- if (opts.radixPoint === ".") {
|
|
|
|
|
- opts.groupSeparator = ",";
|
|
|
|
|
- } else if (opts.radixPoint === ",") {
|
|
|
|
|
- opts.groupSeparator = ".";
|
|
|
|
|
- } else opts.groupSeparator = "";
|
|
|
|
|
- }
|
|
|
|
|
- if (opts.groupSeparator === " ") { //prevent conflict with default skipOptionalPartCharacter
|
|
|
|
|
- opts.skipOptionalPartCharacter = undefined;
|
|
|
|
|
- }
|
|
|
|
|
- opts.autoGroup = opts.autoGroup && opts.groupSeparator !== "";
|
|
|
|
|
- var seps = "+",
|
|
|
|
|
- mod = 0;
|
|
|
|
|
- if (opts.autoGroup) {
|
|
|
|
|
- if (typeof opts.groupSize == "string" && isFinite(opts.groupSize)) opts.groupSize = parseInt(opts.groupSize);
|
|
|
|
|
- if (isFinite(opts.integerDigits)) {
|
|
|
|
|
- seps = Math.floor(opts.integerDigits / opts.groupSize);
|
|
|
|
|
- mod = opts.integerDigits % opts.groupSize;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //enforce placeholder to single
|
|
|
|
|
- if (opts.placeholder.length > 1) {
|
|
|
|
|
- opts.placeholder = opts.placeholder.charAt(0);
|
|
|
|
|
- }
|
|
|
|
|
- if (opts.jitMasking === true && opts.placeholder.length > 0) {
|
|
|
|
|
- opts.jitMasking = 1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //only allow radixfocus when placeholder = 0
|
|
|
|
|
- opts.radixFocus = (opts.radixFocus || (opts.radixFocus === false && isNaN(opts.digits))) && opts.placeholder !== "" && opts.integerOptional === true;
|
|
|
|
|
-
|
|
|
|
|
- opts.definitions[";"] = opts.definitions["~"]; //clone integer def for decimals
|
|
|
|
|
- opts.definitions[";"].definitionSymbol = "~";
|
|
|
|
|
-
|
|
|
|
|
- var mask = autoEscape(opts.prefix);
|
|
|
|
|
- mask += "[+]";
|
|
|
|
|
- if (opts.autoGroup) {
|
|
|
|
|
- mask += "(" + opts.groupSeparator + "~{" + opts.groupSize + "}){" + seps + "}";
|
|
|
|
|
- if (mod > 0) mask += "~{" + mod + "}";
|
|
|
|
|
- } else {
|
|
|
|
|
- mask += "~{" + opts.integerDigits + "}";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
|
|
|
|
|
- if (opts.digitsOptional || isNaN(opts.digits)) {
|
|
|
|
|
- mask += "[:;{1," + opts.digits + "}]";
|
|
|
|
|
- } else {
|
|
|
|
|
- mask += ":;{" + opts.digits + "}";
|
|
|
|
|
- if (isFinite(opts.jitMasking)) {
|
|
|
|
|
- if (opts.jitMasking < (1 + opts.radixPoint.length + (isFinite(opts.digits) ? opts.digits : 2))) {
|
|
|
|
|
- opts.jitMasking = (1 + opts.radixPoint.length + (isFinite(opts.digits) ? opts.digits : 2));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (opts.negationSymbol.back !== "") {
|
|
|
|
|
- mask += "[-]";
|
|
|
|
|
- }
|
|
|
|
|
- mask += autoEscape(opts.suffix);
|
|
|
|
|
-
|
|
|
|
|
- opts.greedy = false; //enforce greedy false
|
|
|
|
|
-
|
|
|
|
|
- console.log(mask);
|
|
|
|
|
- return mask;
|
|
|
|
|
- },
|
|
|
|
|
- placeholder: "",
|
|
|
|
|
- greedy: false,
|
|
|
|
|
- digits: "*", //number of fractionalDigits
|
|
|
|
|
- digitsOptional: true,
|
|
|
|
|
- radixPoint: ".",
|
|
|
|
|
- radixFocus: true,
|
|
|
|
|
- groupSize: 3,
|
|
|
|
|
- groupSeparator: "",
|
|
|
|
|
- autoGroup: false,
|
|
|
|
|
- allowPlus: true,
|
|
|
|
|
- allowMinus: true,
|
|
|
|
|
- negationSymbol: {
|
|
|
|
|
- front: "-", //"("
|
|
|
|
|
- back: "" //")"
|
|
|
|
|
- },
|
|
|
|
|
- integerDigits: "+", //number of integerDigits
|
|
|
|
|
- integerOptional: true,
|
|
|
|
|
- prefix: "",
|
|
|
|
|
- suffix: "",
|
|
|
|
|
- rightAlign: true,
|
|
|
|
|
- decimalProtect: true, //do not allow assumption of decimals input without entering the radixpoint
|
|
|
|
|
- min: null, //minimum value
|
|
|
|
|
- max: null, //maximum value
|
|
|
|
|
- step: 1,
|
|
|
|
|
- insertMode: true,
|
|
|
|
|
- autoUnmask: false,
|
|
|
|
|
- unmaskAsNumber: false,
|
|
|
|
|
- jitMasking: true,
|
|
|
|
|
- numericInput: true,
|
|
|
|
|
- onBeforeWrite: function(e, buffer, caretPos, opts) {
|
|
|
|
|
- // if (e && (e.type === "blur" || e.type === "checkval")) {
|
|
|
|
|
- // //handle minvalue
|
|
|
|
|
- // var maskedValue = buffer.join(""),
|
|
|
|
|
- // processValue = maskedValue.replace(opts.prefix, "");
|
|
|
|
|
- // processValue = processValue.replace(opts.suffix, "");
|
|
|
|
|
- // processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
|
|
|
|
- // if (opts.radixPoint === ",") processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
|
|
|
|
|
- //
|
|
|
|
|
- // if (isFinite(processValue)) {
|
|
|
|
|
- // if (isFinite(opts.min) && parseFloat(processValue) < parseFloat(opts.min)) {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "refreshFromBuffer": true,
|
|
|
|
|
- // "buffer": (opts.prefix + opts.min).split("")
|
|
|
|
|
- // };
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // var tmpBufSplit = opts.radixPoint !== "" ? buffer.join("").split(opts.radixPoint) : [buffer.join("")],
|
|
|
|
|
- // matchRslt = tmpBufSplit[0].match(opts.regex.integerPart(opts)),
|
|
|
|
|
- // matchRsltDigits = tmpBufSplit.length === 2 ? tmpBufSplit[1].match(opts.regex.integerNPart(opts)) : undefined;
|
|
|
|
|
- // if (matchRslt) {
|
|
|
|
|
- // if ((matchRslt[0] === opts.negationSymbol.front + "0" || matchRslt[0] === opts.negationSymbol.front || matchRslt[0] === "+") && (matchRsltDigits === undefined || matchRsltDigits[0].match(/^0+$/))) {
|
|
|
|
|
- // buffer.splice(matchRslt.index, 1);
|
|
|
|
|
- // }
|
|
|
|
|
- // var radixPosition = $.inArray(opts.radixPoint, buffer);
|
|
|
|
|
- // if (radixPosition !== -1) {
|
|
|
|
|
- // if (isFinite(opts.digits) && !opts.digitsOptional) {
|
|
|
|
|
- // for (var i = 1; i <= opts.digits; i++) {
|
|
|
|
|
- // if (buffer[radixPosition + i] === undefined || buffer[radixPosition + i] === opts.placeholder.charAt(0)) {
|
|
|
|
|
- // buffer[radixPosition + i] = "0";
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // return {
|
|
|
|
|
- // "refreshFromBuffer": maskedValue !== buffer.join(""),
|
|
|
|
|
- // "buffer": buffer
|
|
|
|
|
- // };
|
|
|
|
|
- // } else if (radixPosition === buffer.length - opts.suffix.length - 1) {
|
|
|
|
|
- // buffer.splice(radixPosition, 1);
|
|
|
|
|
- // return {
|
|
|
|
|
- // "refreshFromBuffer": true,
|
|
|
|
|
- // "buffer": buffer
|
|
|
|
|
- // };
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- },
|
|
|
|
|
- regex: {
|
|
|
|
|
- integerPart: function(opts) {
|
|
|
|
|
- return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + "]+[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "\+]?$");
|
|
|
|
|
- },
|
|
|
|
|
- integerNPart: function(opts) {
|
|
|
|
|
- return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + "]+");
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- signHandler: function(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
- // if (!strict && (opts.allowMinus && chrs === "-") || (opts.allowPlus && chrs === "+")) {
|
|
|
|
|
- // var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts));
|
|
|
|
|
- //
|
|
|
|
|
- // if (matchRslt && matchRslt[0].length > 0) {
|
|
|
|
|
- // if (maskset.buffer[matchRslt.index] === (chrs === "-" ? "+" : opts.negationSymbol.front)) {
|
|
|
|
|
- // if (chrs === "-") {
|
|
|
|
|
- // if (opts.negationSymbol.back !== "") {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "pos": matchRslt.index,
|
|
|
|
|
- // "c": opts.negationSymbol.front,
|
|
|
|
|
- // "remove": matchRslt.index,
|
|
|
|
|
- // "caret": pos,
|
|
|
|
|
- // "insert": {
|
|
|
|
|
- // "pos": maskset.buffer.length - opts.suffix.length - 1,
|
|
|
|
|
- // "c": opts.negationSymbol.back
|
|
|
|
|
- // }
|
|
|
|
|
- // };
|
|
|
|
|
- // } else {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "pos": matchRslt.index,
|
|
|
|
|
- // "c": opts.negationSymbol.front,
|
|
|
|
|
- // "remove": matchRslt.index,
|
|
|
|
|
- // "caret": pos
|
|
|
|
|
- // };
|
|
|
|
|
- // }
|
|
|
|
|
- // } else {
|
|
|
|
|
- // if (opts.negationSymbol.back !== "") {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "pos": matchRslt.index,
|
|
|
|
|
- // "c": "+",
|
|
|
|
|
- // "remove": [matchRslt.index, maskset.buffer.length - opts.suffix.length - 1],
|
|
|
|
|
- // "caret": pos
|
|
|
|
|
- // };
|
|
|
|
|
- // } else {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "pos": matchRslt.index,
|
|
|
|
|
- // "c": "+",
|
|
|
|
|
- // "remove": matchRslt.index,
|
|
|
|
|
- // "caret": pos
|
|
|
|
|
- // };
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // } else if (maskset.buffer[matchRslt.index] === (chrs === "-" ? opts.negationSymbol.front : "+")) {
|
|
|
|
|
- // if (chrs === "-" && opts.negationSymbol.back !== "") {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "remove": [matchRslt.index, maskset.buffer.length - opts.suffix.length - 1],
|
|
|
|
|
- // "caret": pos - 1
|
|
|
|
|
- // };
|
|
|
|
|
- // } else {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "remove": matchRslt.index,
|
|
|
|
|
- // "caret": pos - 1
|
|
|
|
|
- // };
|
|
|
|
|
- // }
|
|
|
|
|
- // } else {
|
|
|
|
|
- // if (chrs === "-") {
|
|
|
|
|
- // if (opts.negationSymbol.back !== "") {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "pos": matchRslt.index,
|
|
|
|
|
- // "c": opts.negationSymbol.front,
|
|
|
|
|
- // "caret": pos + 1,
|
|
|
|
|
- // "insert": {
|
|
|
|
|
- // "pos": maskset.buffer.length - opts.suffix.length,
|
|
|
|
|
- // "c": opts.negationSymbol.back
|
|
|
|
|
- // }
|
|
|
|
|
- // };
|
|
|
|
|
- // } else {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "pos": matchRslt.index,
|
|
|
|
|
- // "c": opts.negationSymbol.front,
|
|
|
|
|
- // "caret": pos + 1
|
|
|
|
|
- // };
|
|
|
|
|
- // }
|
|
|
|
|
- // } else {
|
|
|
|
|
- // return {
|
|
|
|
|
- // "pos": matchRslt.index,
|
|
|
|
|
- // "c": chrs,
|
|
|
|
|
- // "caret": pos + 1
|
|
|
|
|
- // };
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- return false;
|
|
|
|
|
- },
|
|
|
|
|
- radixHandler: function(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
- if ($.inArray(chrs, [",", "."]) !== -1) chrs = opts.radixPoint;
|
|
|
|
|
- if (chrs === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
|
|
|
|
|
- var radixPos = $.inArray(opts.radixPoint, maskset.buffer);
|
|
|
|
|
- if (radixPos > -1) {
|
|
|
|
|
- return {
|
|
|
|
|
- caret: radixPos < pos ? radixPos : radixPos + 1
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return false;
|
|
|
|
|
- },
|
|
|
|
|
- leadingZeroHandler: function(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
- if (!strict) {
|
|
|
|
|
- if (maskset.buffer[maskset.buffer.length - opts.prefix.length - 1] === "0" && maskset.buffer[maskset.buffer.length - opts.prefix.length - 2] !== opts.radixPoint) {
|
|
|
|
|
- return {
|
|
|
|
|
- "pos": pos,
|
|
|
|
|
- "remove": maskset.buffer.length - opts.prefix.length - 1
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
- },
|
|
|
|
|
- postValidation: function(buffer, opts) {
|
|
|
|
|
-
|
|
|
|
|
- return true;
|
|
|
|
|
- //handle maxvalue
|
|
|
|
|
- var isValid = true,
|
|
|
|
|
- maskedValue = buffer.join(""),
|
|
|
|
|
- processValue = maskedValue.replace(opts.prefix, "");
|
|
|
|
|
- processValue = processValue.replace(opts.suffix, "");
|
|
|
|
|
- processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
|
|
|
|
- if (opts.radixPoint === ",") processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
|
|
|
|
|
- //handle negation symbol
|
|
|
|
|
- processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
|
|
|
|
|
- processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
|
|
|
|
|
- processValue = processValue === opts.negationSymbol.front ? processValue + "0" : processValue;
|
|
|
|
|
-
|
|
|
|
|
- if (isFinite(processValue)) {
|
|
|
|
|
- if (opts.max !== null && isFinite(opts.max)) {
|
|
|
|
|
- isValid = parseFloat(processValue) <= parseFloat(opts.max);
|
|
|
|
|
- }
|
|
|
|
|
- if (isValid && opts.min !== null && isFinite(opts.min) && (processValue <= 0 || processValue.toString().length >= opts.min.toString().length)) {
|
|
|
|
|
- isValid = parseFloat(processValue) >= parseFloat(opts.min);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- isValid = {
|
|
|
|
|
- "refreshFromBuffer": true,
|
|
|
|
|
- "buffer": (opts.prefix + opts.min).split("")
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return isValid;
|
|
|
|
|
- },
|
|
|
|
|
- definitions: {
|
|
|
|
|
- "~": {
|
|
|
|
|
- validator: function(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
- var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- isValid = opts.radixHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
|
|
|
|
|
- if (isValid === true) {
|
|
|
|
|
- isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (isValid === true && !strict && opts.radixFocus === true) {
|
|
|
|
|
- //handle overwrite when fixed precision
|
|
|
|
|
- var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
|
|
|
|
|
- if (radixPosition !== -1 && opts.digitsOptional === false && pos <= radixPosition && pos > 0) {
|
|
|
|
|
- isValid = {
|
|
|
|
|
- "pos": pos - 1,
|
|
|
|
|
- "remove": maskset.validPositions[pos] !== undefined ? pos - 1 : undefined
|
|
|
|
|
- };
|
|
|
|
|
- } //else isValid = pos >= 0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return isValid;
|
|
|
|
|
- },
|
|
|
|
|
- cardinality: 1,
|
|
|
|
|
- prevalidator: null
|
|
|
|
|
- },
|
|
|
|
|
- "+": {
|
|
|
|
|
- validator: function(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
- var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- isValid = opts.radixHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid && ((strict && opts.allowMinus && chrs === opts.negationSymbol.front) || (opts.allowMinus && chrs === "-") || (opts.allowPlus && chrs === "+"))) {
|
|
|
|
|
- if (chrs === "-") {
|
|
|
|
|
- if (opts.negationSymbol.back !== "") {
|
|
|
|
|
- isValid = {
|
|
|
|
|
- "pos": pos,
|
|
|
|
|
- "c": chrs === "-" ? opts.negationSymbol.front : "+",
|
|
|
|
|
- "caret": pos + 1,
|
|
|
|
|
- "insert": {
|
|
|
|
|
- "pos": maskset.buffer.length,
|
|
|
|
|
- "c": opts.negationSymbol.back
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- } else {
|
|
|
|
|
- isValid = {
|
|
|
|
|
- "pos": pos,
|
|
|
|
|
- "c": chrs === "-" ? opts.negationSymbol.front : "+",
|
|
|
|
|
- "caret": pos + 1
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- isValid = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return isValid;
|
|
|
|
|
- },
|
|
|
|
|
- cardinality: 1,
|
|
|
|
|
- prevalidator: null,
|
|
|
|
|
- placeholder: ""
|
|
|
|
|
- },
|
|
|
|
|
- "-": {
|
|
|
|
|
- validator: function(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
- var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- isValid = opts.radixHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid && strict && opts.allowMinus && chrs === opts.negationSymbol.back) {
|
|
|
|
|
- isValid = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return isValid;
|
|
|
|
|
- },
|
|
|
|
|
- cardinality: 1,
|
|
|
|
|
- prevalidator: null,
|
|
|
|
|
- placeholder: ""
|
|
|
|
|
- },
|
|
|
|
|
- ":": {
|
|
|
|
|
- validator: function(chrs, maskset, pos, strict, opts) {
|
|
|
|
|
- var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- isValid = opts.radixHandler(chrs, maskset, pos, strict, opts);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- var radix = "[" + Inputmask.escapeRegex(opts.radixPoint) + ",\\." + "]";
|
|
|
|
|
- isValid = new RegExp(radix).test(chrs);
|
|
|
|
|
- if (!isValid && new RegExp("[0-9]").test(chrs)) {
|
|
|
|
|
- if ((opts.radixFocus !== true || (opts.radixFocus === true && strict)) && pos === $.inArray(opts.radixPoint, maskset.buffer)) {
|
|
|
|
|
- return isValid = {
|
|
|
|
|
- pos: pos,
|
|
|
|
|
- c: opts.radixPoint,
|
|
|
|
|
- insert: {
|
|
|
|
|
- pos: pos + 1,
|
|
|
|
|
- c: chrs,
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else if (!strict) {
|
|
|
|
|
- return isValid = {
|
|
|
|
|
- pos: pos - 1,
|
|
|
|
|
- c: chrs
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return isValid !== true ? isValid : {
|
|
|
|
|
- c: opts.radixPoint
|
|
|
|
|
- };
|
|
|
|
|
- },
|
|
|
|
|
- cardinality: 1,
|
|
|
|
|
- prevalidator: null,
|
|
|
|
|
- definitionSymbol: "~",
|
|
|
|
|
- placeholder: function(opts) {
|
|
|
|
|
- return opts.radixPoint;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- onUnMask: function(maskedValue, unmaskedValue, opts) {
|
|
|
|
|
- var processValue = maskedValue.replace(opts.prefix, "");
|
|
|
|
|
- processValue = processValue.replace(opts.suffix, "");
|
|
|
|
|
- processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
|
|
|
|
- if (opts.unmaskAsNumber) {
|
|
|
|
|
- if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".");
|
|
|
|
|
- return Number(processValue);
|
|
|
|
|
- }
|
|
|
|
|
- return processValue;
|
|
|
|
|
- },
|
|
|
|
|
- isComplete: function(buffer, opts) {
|
|
|
|
|
- var maskedValue = buffer.join("");
|
|
|
|
|
-
|
|
|
|
|
- var processValue = maskedValue.replace(opts.prefix, "");
|
|
|
|
|
- processValue = processValue.replace(opts.suffix, "");
|
|
|
|
|
- processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
|
|
|
|
- if (opts.radixPoint === ",") processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
|
|
|
|
|
- return isFinite(processValue);
|
|
|
|
|
- },
|
|
|
|
|
- onBeforeMask: function(initialValue, opts) {
|
|
|
|
|
- if (opts.radixPoint !== "" && isFinite(initialValue)) {
|
|
|
|
|
- initialValue = initialValue.toString().replace(".", opts.radixPoint);
|
|
|
|
|
- } else {
|
|
|
|
|
- var kommaMatches = initialValue.match(/,/g);
|
|
|
|
|
- var dotMatches = initialValue.match(/\./g);
|
|
|
|
|
- if (dotMatches && kommaMatches) {
|
|
|
|
|
- if (dotMatches.length > kommaMatches.length) {
|
|
|
|
|
- initialValue = initialValue.replace(/\./g, "");
|
|
|
|
|
- initialValue = initialValue.replace(",", opts.radixPoint);
|
|
|
|
|
- } else if (kommaMatches.length > dotMatches.length) {
|
|
|
|
|
- initialValue = initialValue.replace(/,/g, "");
|
|
|
|
|
- initialValue = initialValue.replace(".", opts.radixPoint);
|
|
|
|
|
- } else { //equal
|
|
|
|
|
- initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "");
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (opts.digits === 0) {
|
|
|
|
|
- if (initialValue.indexOf(".") !== -1) {
|
|
|
|
|
- initialValue = initialValue.substring(0, initialValue.indexOf("."));
|
|
|
|
|
- } else if (initialValue.indexOf(",") !== -1) {
|
|
|
|
|
- initialValue = initialValue.substring(0, initialValue.indexOf(","));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (opts.radixPoint !== "" && isFinite(opts.digits) && initialValue.indexOf(opts.radixPoint) !== -1) {
|
|
|
|
|
- var valueParts = initialValue.split(opts.radixPoint),
|
|
|
|
|
- decPart = valueParts[1].match(new RegExp("\\d*"))[0];
|
|
|
|
|
- if (parseInt(opts.digits) < decPart.toString().length) {
|
|
|
|
|
- var digitsFactor = Math.pow(10, parseInt(opts.digits));
|
|
|
|
|
- //make the initialValue a valid javascript number for the parsefloat
|
|
|
|
|
- initialValue = initialValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
|
|
|
|
|
- initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor;
|
|
|
|
|
- initialValue = initialValue.toString().replace(".", opts.radixPoint);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return initialValue.toString();
|
|
|
|
|
- },
|
|
|
|
|
- canClearPosition: function(maskset, position, lvp, strict, opts) {
|
|
|
|
|
- return true;
|
|
|
|
|
- var positionInput = maskset.validPositions[position].input,
|
|
|
|
|
- canClear = ((positionInput !== opts.radixPoint || (maskset.validPositions[position].match.fn !== null && opts.decimalProtect === false)) || isFinite(positionInput)) ||
|
|
|
|
|
- position === lvp ||
|
|
|
|
|
- positionInput === opts.groupSeparator ||
|
|
|
|
|
- positionInput === opts.negationSymbol.front ||
|
|
|
|
|
- positionInput === opts.negationSymbol.back;
|
|
|
|
|
-
|
|
|
|
|
- // if (canClear && isFinite(positionInput)) {
|
|
|
|
|
- // var matchRslt,
|
|
|
|
|
- // radixPos = $.inArray(opts.radixPoint, maskset.buffer);
|
|
|
|
|
- //
|
|
|
|
|
- // //inject radixpoint
|
|
|
|
|
- // var radixInjection = false;
|
|
|
|
|
- // if (maskset.validPositions[radixPos] === undefined) {
|
|
|
|
|
- // maskset.validPositions[radixPos] = {
|
|
|
|
|
- // input: opts.radixPoint
|
|
|
|
|
- // };
|
|
|
|
|
- // radixInjection = true;
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // if (!strict && maskset.buffer) {
|
|
|
|
|
- // matchRslt = maskset.buffer.join("").substr(0, position).match(opts.regex.integerNPart(opts));
|
|
|
|
|
- // var pos = position + 1,
|
|
|
|
|
- // isNull = matchRslt == null || parseInt(matchRslt["0"].replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "")) === 0;
|
|
|
|
|
- // if (isNull) {
|
|
|
|
|
- // while (maskset.validPositions[pos] && (maskset.validPositions[pos].input === opts.groupSeparator || maskset.validPositions[pos].input === "0")) {
|
|
|
|
|
- // delete maskset.validPositions[pos];
|
|
|
|
|
- // pos++;
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // var buffer = [];
|
|
|
|
|
- // //build new buffer from validPositions
|
|
|
|
|
- // for (var vp in maskset.validPositions) {
|
|
|
|
|
- // if (maskset.validPositions[vp].input !== undefined) buffer.push(maskset.validPositions[vp].input);
|
|
|
|
|
- // }
|
|
|
|
|
- // //remove radix Injection
|
|
|
|
|
- // if (radixInjection) {
|
|
|
|
|
- // delete maskset.validPositions[radixPos];
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // if (radixPos > 0) {
|
|
|
|
|
- // var bufVal = buffer.join("");
|
|
|
|
|
- // matchRslt = bufVal.match(opts.regex.integerNPart(opts));
|
|
|
|
|
- // if (matchRslt) {
|
|
|
|
|
- // if (position <= radixPos) {
|
|
|
|
|
- // if (matchRslt["0"].indexOf("0") === 0) {
|
|
|
|
|
- // canClear = matchRslt.index !== position || opts.placeholder === "0";
|
|
|
|
|
- // } else {
|
|
|
|
|
- // var intPart = parseInt(matchRslt["0"].replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "")),
|
|
|
|
|
- // radixPart = parseInt(bufVal.split(opts.radixPoint)[1]);
|
|
|
|
|
- // if (intPart < 10 && maskset.validPositions[position] && (opts.placeholder !== "0" || radixPart > 0)) {
|
|
|
|
|
- // maskset.validPositions[position].input = "0";
|
|
|
|
|
- // maskset.p = opts.prefix.length + 1;
|
|
|
|
|
- // canClear = false;
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // } else if (matchRslt["0"].indexOf("0") === 0) {
|
|
|
|
|
- // if (bufVal.length === 3) {
|
|
|
|
|
- // maskset.validPositions = {};
|
|
|
|
|
- // canClear = false;
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- return canClear;
|
|
|
|
|
- },
|
|
|
|
|
- onKeyDown: function(e, buffer, caretPos, opts) {
|
|
|
|
|
- // var $input = $(this);
|
|
|
|
|
- // if (e.ctrlKey) {
|
|
|
|
|
- // switch (e.keyCode) {
|
|
|
|
|
- // case Inputmask.keyCode.UP:
|
|
|
|
|
- // $input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step));
|
|
|
|
|
- // $input.trigger("setvalue");
|
|
|
|
|
- // break;
|
|
|
|
|
- // case Inputmask.keyCode.DOWN:
|
|
|
|
|
- // $input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step));
|
|
|
|
|
- // $input.trigger("setvalue");
|
|
|
|
|
- // break;
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
"numeric": {
|
|
"numeric": {
|
|
|
mask: function(opts) {
|
|
mask: function(opts) {
|
|
|
function autoEscape(txt) {
|
|
function autoEscape(txt) {
|
|
@@ -998,10 +427,10 @@ Optional extensions on the jquery.inputmask base
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
},
|
|
},
|
|
|
- postValidation: function(buffer, opts) {
|
|
|
|
|
|
|
+ postValidation: function(buffer, currentResult, opts) {
|
|
|
//handle maxvalue
|
|
//handle maxvalue
|
|
|
var isValid = true,
|
|
var isValid = true,
|
|
|
- maskedValue = buffer.join(""),
|
|
|
|
|
|
|
+ maskedValue = opts.numericInput ? buffer.slice().reverse().join("") : buffer.join(""),
|
|
|
processValue = maskedValue.replace(opts.prefix, "");
|
|
processValue = maskedValue.replace(opts.prefix, "");
|
|
|
processValue = processValue.replace(opts.suffix, "");
|
|
processValue = processValue.replace(opts.suffix, "");
|
|
|
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
|
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
|
@@ -1013,17 +442,12 @@ Optional extensions on the jquery.inputmask base
|
|
|
|
|
|
|
|
if (isFinite(processValue)) {
|
|
if (isFinite(processValue)) {
|
|
|
if (opts.max !== null && isFinite(opts.max)) {
|
|
if (opts.max !== null && isFinite(opts.max)) {
|
|
|
- isValid = parseFloat(processValue) <= parseFloat(opts.max);
|
|
|
|
|
|
|
+ processValue = parseFloat(processValue) > parseFloat(opts.max) ? opts.max : processValue;
|
|
|
|
|
+ isValid = opts.postFormat((opts.prefix + processValue).split(""), 0, true, opts);
|
|
|
}
|
|
}
|
|
|
- if (isValid && opts.min !== null && isFinite(opts.min) && (processValue <= 0 || processValue.toString().length >= opts.min.toString().length)) {
|
|
|
|
|
- isValid = parseFloat(processValue) >= parseFloat(opts.min);
|
|
|
|
|
- if (!isValid) {
|
|
|
|
|
- isValid = $.extend(true, {
|
|
|
|
|
- "refreshFromBuffer": true,
|
|
|
|
|
- "buffer": (opts.prefix + opts.min).split("")
|
|
|
|
|
- }, opts.postFormat((opts.prefix + opts.min).split(""), 0, true, opts));
|
|
|
|
|
- isValid.refreshFromBuffer = true; //enforce refresh
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (opts.min !== null && isFinite(opts.min)) {
|
|
|
|
|
+ processValue = parseFloat(processValue) < parseFloat(opts.min) ? opts.min : processValue;
|
|
|
|
|
+ isValid = opts.postFormat((opts.prefix + processValue).split(""), 0, true, opts);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|