inputmask.numeric.extensions.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /*!
  2. * inputmask.numeric.extensions.js
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2015 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.2.6-25
  7. */
  8. !function(factory) {
  9. "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);
  10. }(function($, Inputmask) {
  11. return Inputmask.extendAliases({
  12. numeric2: {
  13. mask: function(opts) {
  14. function autoEscape(txt) {
  15. for (var escapedTxt = "", i = 0; i < txt.length; i++) escapedTxt += opts.definitions[txt.charAt(i)] ? "\\" + txt.charAt(i) : txt.charAt(i);
  16. return escapedTxt;
  17. }
  18. 0 !== opts.repeat && isNaN(opts.integerDigits) && (opts.integerDigits = opts.repeat),
  19. opts.repeat = 0, opts.groupSeparator === opts.radixPoint && ("." === opts.radixPoint ? opts.groupSeparator = "," : "," === opts.radixPoint ? opts.groupSeparator = "." : opts.groupSeparator = ""),
  20. " " === opts.groupSeparator && (opts.skipOptionalPartCharacter = void 0), opts.autoGroup = opts.autoGroup && "" !== opts.groupSeparator;
  21. var seps = "+", mod = 0;
  22. opts.autoGroup && ("string" == typeof opts.groupSize && isFinite(opts.groupSize) && (opts.groupSize = parseInt(opts.groupSize)),
  23. isFinite(opts.integerDigits) && (seps = Math.floor(opts.integerDigits / opts.groupSize),
  24. mod = opts.integerDigits % opts.groupSize)), opts.placeholder.length > 1 && (opts.placeholder = opts.placeholder.charAt(0)),
  25. opts.jitMasking === !0 && opts.placeholder.length > 0 && (opts.jitMasking = 1),
  26. opts.radixFocus = opts.radixFocus && "" !== opts.placeholder && opts.integerOptional === !0,
  27. opts.definitions[";"] = opts.definitions["~"], opts.definitions[";"].definitionSymbol = "~";
  28. var mask = autoEscape(opts.prefix);
  29. return mask += "[+]", opts.autoGroup ? (mask += "(" + opts.groupSeparator + "~{" + opts.groupSize + "}){" + seps + "}",
  30. mod > 0 && (mask += "~{" + mod + "}")) : mask += "~{" + opts.integerDigits + "}",
  31. void 0 !== opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (opts.digitsOptional ? mask += "[" + (opts.decimalProtect ? ":" : opts.radixPoint) + ";{1," + opts.digits + "}]" : (mask += (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}",
  32. isFinite(opts.jitMasking) && opts.jitMasking < 1 + opts.radixPoint.length + (isFinite(opts.digits) ? opts.digits : 2) && (opts.jitMasking = 1 + opts.radixPoint.length + (isFinite(opts.digits) ? opts.digits : 2)))),
  33. "" !== opts.negationSymbol.back && (mask += "[-]"), mask += autoEscape(opts.suffix),
  34. opts.greedy = !1, mask;
  35. },
  36. placeholder: "",
  37. greedy: !1,
  38. digits: "*",
  39. digitsOptional: !0,
  40. radixPoint: ".",
  41. radixFocus: !0,
  42. groupSize: 3,
  43. groupSeparator: "",
  44. autoGroup: !1,
  45. allowPlus: !0,
  46. allowMinus: !0,
  47. negationSymbol: {
  48. front: "-",
  49. back: ""
  50. },
  51. integerDigits: "+",
  52. integerOptional: !0,
  53. prefix: "",
  54. suffix: "",
  55. rightAlign: !0,
  56. decimalProtect: !0,
  57. min: null,
  58. max: null,
  59. step: 1,
  60. insertMode: !0,
  61. autoUnmask: !1,
  62. unmaskAsNumber: !1,
  63. jitMasking: !0,
  64. numericInput: !0,
  65. onBeforeWrite: function(e, buffer, caretPos, opts) {
  66. if (e && ("blur" === e.type || "checkval" === e.type)) {
  67. var maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  68. if (processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  69. "," === opts.radixPoint && (processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".")),
  70. isFinite(processValue) && isFinite(opts.min) && parseFloat(processValue) < parseFloat(opts.min)) return {
  71. refreshFromBuffer: !0,
  72. buffer: (opts.prefix + opts.min).split("")
  73. };
  74. if (opts.numericInput !== !0) {
  75. var tmpBufSplit = "" !== opts.radixPoint ? buffer.join("").split(opts.radixPoint) : [ buffer.join("") ], matchRslt = tmpBufSplit[0].match(opts.regex.integerPart(opts)), matchRsltDigits = 2 === tmpBufSplit.length ? tmpBufSplit[1].match(opts.regex.integerNPart(opts)) : void 0;
  76. if (matchRslt) {
  77. matchRslt[0] !== opts.negationSymbol.front + "0" && matchRslt[0] !== opts.negationSymbol.front && "+" !== matchRslt[0] || void 0 !== matchRsltDigits && !matchRsltDigits[0].match(/^0+$/) || buffer.splice(matchRslt.index, 1);
  78. var radixPosition = $.inArray(opts.radixPoint, buffer);
  79. if (-1 !== radixPosition) {
  80. if (isFinite(opts.digits) && !opts.digitsOptional) {
  81. for (var i = 1; i <= opts.digits; i++) (void 0 === buffer[radixPosition + i] || buffer[radixPosition + i] === opts.placeholder.charAt(0)) && (buffer[radixPosition + i] = "0");
  82. return {
  83. refreshFromBuffer: maskedValue !== buffer.join(""),
  84. buffer: buffer
  85. };
  86. }
  87. if (radixPosition === buffer.length - opts.suffix.length - 1) return buffer.splice(radixPosition, 1),
  88. {
  89. refreshFromBuffer: !0,
  90. buffer: buffer
  91. };
  92. }
  93. }
  94. }
  95. }
  96. },
  97. regex: {
  98. integerPart: function(opts) {
  99. return new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
  100. },
  101. integerNPart: function(opts) {
  102. return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + "]+");
  103. }
  104. },
  105. signHandler: function(chrs, maskset, pos, strict, opts) {
  106. if (!strict && opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) {
  107. var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts));
  108. if (matchRslt && matchRslt[0].length > 0) return maskset.buffer[matchRslt.index] === ("-" === chrs ? "+" : opts.negationSymbol.front) ? "-" === chrs ? "" !== opts.negationSymbol.back ? {
  109. pos: matchRslt.index,
  110. c: opts.negationSymbol.front,
  111. remove: matchRslt.index,
  112. caret: pos,
  113. insert: {
  114. pos: maskset.buffer.length - opts.suffix.length - 1,
  115. c: opts.negationSymbol.back
  116. }
  117. } : {
  118. pos: matchRslt.index,
  119. c: opts.negationSymbol.front,
  120. remove: matchRslt.index,
  121. caret: pos
  122. } : "" !== opts.negationSymbol.back ? {
  123. pos: matchRslt.index,
  124. c: "+",
  125. remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
  126. caret: pos
  127. } : {
  128. pos: matchRslt.index,
  129. c: "+",
  130. remove: matchRslt.index,
  131. caret: pos
  132. } : maskset.buffer[matchRslt.index] === ("-" === chrs ? opts.negationSymbol.front : "+") ? "-" === chrs && "" !== opts.negationSymbol.back ? {
  133. remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
  134. caret: pos - 1
  135. } : {
  136. remove: matchRslt.index,
  137. caret: pos - 1
  138. } : "-" === chrs ? "" !== opts.negationSymbol.back ? {
  139. pos: matchRslt.index,
  140. c: opts.negationSymbol.front,
  141. caret: pos + 1,
  142. insert: {
  143. pos: maskset.buffer.length - opts.suffix.length,
  144. c: opts.negationSymbol.back
  145. }
  146. } : {
  147. pos: matchRslt.index,
  148. c: opts.negationSymbol.front,
  149. caret: pos + 1
  150. } : {
  151. pos: matchRslt.index,
  152. c: chrs,
  153. caret: pos + 1
  154. };
  155. }
  156. return !1;
  157. },
  158. radixHandler: function(chrs, maskset, pos, strict, opts) {
  159. if (!strict && (-1 !== $.inArray(chrs, [ ",", "." ]) && (chrs = opts.radixPoint),
  160. chrs === opts.radixPoint && void 0 !== opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
  161. var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = (opts.numericInput ? maskset.buffer.slice().reverse() : maskset.buffer).join("").match(opts.regex.integerPart(opts));
  162. if (-1 !== radixPos && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? {
  163. caret: radixPos + 1
  164. } : {
  165. pos: integerValue.index,
  166. c: integerValue[0],
  167. caret: radixPos + 1
  168. };
  169. if (!integerValue || "0" === integerValue[0] && integerValue.index + 1 !== pos) return maskset.buffer[integerValue ? integerValue.index : pos] = "0",
  170. {
  171. pos: (integerValue ? integerValue.index : pos) + 1,
  172. c: opts.radixPoint
  173. };
  174. }
  175. return !1;
  176. },
  177. leadingZeroHandler: function(chrs, maskset, pos, strict, opts) {
  178. if (opts.numericInput === !0) {
  179. if ("0" === maskset.buffer[maskset.buffer.length - opts.prefix.length - 1]) return {
  180. pos: pos,
  181. remove: maskset.buffer.length - opts.prefix.length - 1
  182. };
  183. } else {
  184. var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  185. if (matchRslt && !strict && (-1 === radixPosition || radixPosition >= pos)) if (0 === matchRslt[0].indexOf("0")) {
  186. pos < opts.prefix.length && (pos = matchRslt.index);
  187. var _radixPosition = $.inArray(opts.radixPoint, maskset._buffer), digitsMatch = maskset._buffer && maskset.buffer.slice(radixPosition).join("") === maskset._buffer.slice(_radixPosition).join("") || 0 === parseInt(maskset.buffer.slice(radixPosition + 1).join("")), integerMatch = maskset._buffer && maskset.buffer.slice(matchRslt.index, radixPosition).join("") === maskset._buffer.slice(opts.prefix.length, _radixPosition).join("") || "0" === maskset.buffer.slice(matchRslt.index, radixPosition).join("");
  188. if (-1 === radixPosition || digitsMatch && integerMatch) return maskset.buffer.splice(matchRslt.index, 1),
  189. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, {
  190. pos: pos,
  191. remove: matchRslt.index
  192. };
  193. if (matchRslt.index + 1 === pos || "0" === chrs) return maskset.buffer.splice(matchRslt.index, 1),
  194. pos = matchRslt.index, {
  195. pos: pos,
  196. remove: matchRslt.index
  197. };
  198. } else if ("0" === chrs && pos <= matchRslt.index && matchRslt[0] !== opts.groupSeparator) return !1;
  199. }
  200. return !0;
  201. },
  202. postValidation: function(buffer, opts) {
  203. var isValid = !0, maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  204. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  205. "," === opts.radixPoint && (processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".")),
  206. processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-"),
  207. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), ""),
  208. processValue = processValue === opts.negationSymbol.front ? processValue + "0" : processValue,
  209. isFinite(processValue) && (null !== opts.max && isFinite(opts.max) && (isValid = parseFloat(processValue) <= parseFloat(opts.max)),
  210. isValid && null !== opts.min && isFinite(opts.min) && (0 >= processValue || processValue.toString().length >= opts.min.toString().length) && (isValid = parseFloat(processValue) >= parseFloat(opts.min),
  211. isValid || (isValid = {
  212. refreshFromBuffer: !0,
  213. buffer: (opts.prefix + opts.min).split("")
  214. }))), isValid;
  215. },
  216. definitions: {
  217. "~": {
  218. validator: function(chrs, maskset, pos, strict, opts) {
  219. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  220. if (!isValid && (isValid = opts.radixHandler(chrs, maskset, pos, strict, opts),
  221. !isValid && (isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs),
  222. isValid === !0 && (isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts),
  223. isValid === !0)))) {
  224. var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  225. isValid = -1 !== radixPosition && opts.digitsOptional === !1 && opts.numericInput !== !0 && pos > radixPosition && !strict ? {
  226. pos: pos,
  227. remove: pos
  228. } : {
  229. pos: pos
  230. };
  231. }
  232. return isValid;
  233. },
  234. cardinality: 1,
  235. prevalidator: null
  236. },
  237. "+": {
  238. validator: function(chrs, maskset, pos, strict, opts) {
  239. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  240. return !isValid && (strict && opts.allowMinus && chrs === opts.negationSymbol.front || opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) && (isValid = "-" === chrs ? "" !== opts.negationSymbol.back ? {
  241. pos: pos,
  242. c: "-" === chrs ? opts.negationSymbol.front : "+",
  243. caret: pos + 1,
  244. insert: {
  245. pos: maskset.buffer.length,
  246. c: opts.negationSymbol.back
  247. }
  248. } : {
  249. pos: pos,
  250. c: "-" === chrs ? opts.negationSymbol.front : "+",
  251. caret: pos + 1
  252. } : !0), isValid;
  253. },
  254. cardinality: 1,
  255. prevalidator: null,
  256. placeholder: ""
  257. },
  258. "-": {
  259. validator: function(chrs, maskset, pos, strict, opts) {
  260. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  261. return !isValid && strict && opts.allowMinus && chrs === opts.negationSymbol.back && (isValid = !0),
  262. isValid;
  263. },
  264. cardinality: 1,
  265. prevalidator: null,
  266. placeholder: ""
  267. },
  268. ":": {
  269. validator: function(chrs, maskset, pos, strict, opts) {
  270. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  271. if (!isValid) {
  272. var radix = "[" + Inputmask.escapeRegex(opts.radixPoint) + ",\\.]";
  273. isValid = new RegExp(radix).test(chrs), isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder === opts.radixPoint && (isValid = {
  274. caret: pos + 1
  275. });
  276. }
  277. return isValid ? {
  278. c: opts.radixPoint
  279. } : isValid;
  280. },
  281. cardinality: 1,
  282. prevalidator: null,
  283. placeholder: function(opts) {
  284. return opts.radixPoint;
  285. }
  286. }
  287. },
  288. onUnMask: function(maskedValue, unmaskedValue, opts) {
  289. var processValue = maskedValue.replace(opts.prefix, "");
  290. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  291. opts.unmaskAsNumber ? ("" !== opts.radixPoint && -1 !== processValue.indexOf(opts.radixPoint) && (processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".")),
  292. Number(processValue)) : processValue;
  293. },
  294. isComplete: function(buffer, opts) {
  295. var maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  296. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  297. "," === opts.radixPoint && (processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".")),
  298. isFinite(processValue);
  299. },
  300. onBeforeMask: function(initialValue, opts) {
  301. if ("" !== opts.radixPoint && isFinite(initialValue)) initialValue = initialValue.toString().replace(".", opts.radixPoint); else {
  302. var kommaMatches = initialValue.match(/,/g), dotMatches = initialValue.match(/\./g);
  303. dotMatches && kommaMatches ? dotMatches.length > kommaMatches.length ? (initialValue = initialValue.replace(/\./g, ""),
  304. initialValue = initialValue.replace(",", opts.radixPoint)) : kommaMatches.length > dotMatches.length ? (initialValue = initialValue.replace(/,/g, ""),
  305. initialValue = initialValue.replace(".", opts.radixPoint)) : initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "") : initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  306. }
  307. if (0 === opts.digits && (-1 !== initialValue.indexOf(".") ? initialValue = initialValue.substring(0, initialValue.indexOf(".")) : -1 !== initialValue.indexOf(",") && (initialValue = initialValue.substring(0, initialValue.indexOf(",")))),
  308. "" !== opts.radixPoint && isFinite(opts.digits) && -1 !== initialValue.indexOf(opts.radixPoint)) {
  309. var valueParts = initialValue.split(opts.radixPoint), decPart = valueParts[1].match(new RegExp("\\d*"))[0];
  310. if (parseInt(opts.digits) < decPart.toString().length) {
  311. var digitsFactor = Math.pow(10, parseInt(opts.digits));
  312. initialValue = initialValue.replace(Inputmask.escapeRegex(opts.radixPoint), "."),
  313. initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor,
  314. initialValue = initialValue.toString().replace(".", opts.radixPoint);
  315. }
  316. }
  317. return initialValue.toString();
  318. },
  319. canClearPosition: function(maskset, position, lvp, strict, opts) {
  320. var positionInput = maskset.validPositions[position].input, canClear = positionInput !== opts.radixPoint || null !== maskset.validPositions[position].match.fn && opts.decimalProtect === !1 || isFinite(positionInput) || position === lvp || positionInput === opts.groupSeparator || positionInput === opts.negationSymbol.front || positionInput === opts.negationSymbol.back;
  321. if (canClear && isFinite(positionInput)) {
  322. var matchRslt, radixPos = $.inArray(opts.radixPoint, maskset.buffer), radixInjection = !1;
  323. if (void 0 === maskset.validPositions[radixPos] && (maskset.validPositions[radixPos] = {
  324. input: opts.radixPoint
  325. }, radixInjection = !0), !strict && maskset.buffer) {
  326. matchRslt = maskset.buffer.join("").substr(0, position).match(opts.regex.integerNPart(opts));
  327. var pos = position + 1, isNull = null == matchRslt || 0 === parseInt(matchRslt[0].replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""));
  328. if (isNull) for (;maskset.validPositions[pos] && (maskset.validPositions[pos].input === opts.groupSeparator || "0" === maskset.validPositions[pos].input); ) delete maskset.validPositions[pos],
  329. pos++;
  330. }
  331. var buffer = [];
  332. for (var vp in maskset.validPositions) void 0 !== maskset.validPositions[vp].input && buffer.push(maskset.validPositions[vp].input);
  333. if (radixInjection && delete maskset.validPositions[radixPos], radixPos > 0) {
  334. var bufVal = buffer.join("");
  335. if (matchRslt = bufVal.match(opts.regex.integerNPart(opts))) if (radixPos >= position) if (0 === matchRslt[0].indexOf("0")) canClear = matchRslt.index !== position || "0" === opts.placeholder; else {
  336. var intPart = parseInt(matchRslt[0].replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "")), radixPart = parseInt(bufVal.split(opts.radixPoint)[1]);
  337. 10 > intPart && maskset.validPositions[position] && ("0" !== opts.placeholder || radixPart > 0) && (maskset.validPositions[position].input = "0",
  338. maskset.p = opts.prefix.length + 1, canClear = !1);
  339. } else 0 === matchRslt[0].indexOf("0") && 3 === bufVal.length && (maskset.validPositions = {},
  340. canClear = !1);
  341. }
  342. }
  343. return canClear;
  344. },
  345. onKeyDown: function(e, buffer, caretPos, opts) {
  346. var $input = $(this);
  347. if (e.ctrlKey) switch (e.keyCode) {
  348. case Inputmask.keyCode.UP:
  349. $input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step)), $input.trigger("setvalue");
  350. break;
  351. case Inputmask.keyCode.DOWN:
  352. $input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step)), $input.trigger("setvalue");
  353. }
  354. }
  355. },
  356. numeric: {
  357. mask: function(opts) {
  358. function autoEscape(txt) {
  359. for (var escapedTxt = "", i = 0; i < txt.length; i++) escapedTxt += opts.definitions[txt.charAt(i)] ? "\\" + txt.charAt(i) : txt.charAt(i);
  360. return escapedTxt;
  361. }
  362. if (0 !== opts.repeat && isNaN(opts.integerDigits) && (opts.integerDigits = opts.repeat),
  363. opts.repeat = 0, opts.groupSeparator === opts.radixPoint && ("." === opts.radixPoint ? opts.groupSeparator = "," : "," === opts.radixPoint ? opts.groupSeparator = "." : opts.groupSeparator = ""),
  364. " " === opts.groupSeparator && (opts.skipOptionalPartCharacter = void 0), opts.autoGroup = opts.autoGroup && "" !== opts.groupSeparator,
  365. opts.autoGroup && ("string" == typeof opts.groupSize && isFinite(opts.groupSize) && (opts.groupSize = parseInt(opts.groupSize)),
  366. isFinite(opts.integerDigits))) {
  367. var seps = Math.floor(opts.integerDigits / opts.groupSize), mod = opts.integerDigits % opts.groupSize;
  368. opts.integerDigits = parseInt(opts.integerDigits) + (0 === mod ? seps - 1 : seps),
  369. opts.integerDigits < 1 && (opts.integerDigits = "*");
  370. }
  371. opts.placeholder.length > 1 && (opts.placeholder = opts.placeholder.charAt(0)),
  372. opts.radixFocus = opts.radixFocus && "" !== opts.placeholder && opts.integerOptional === !0,
  373. opts.definitions[";"] = opts.definitions["~"], opts.definitions[";"].definitionSymbol = "~";
  374. var mask = autoEscape(opts.prefix);
  375. return mask += "[+]", mask += opts.integerOptional === !0 ? "~{1," + opts.integerDigits + "}" : "~{" + opts.integerDigits + "}",
  376. void 0 !== opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (mask += opts.digitsOptional ? "[" + (opts.decimalProtect ? ":" : opts.radixPoint) + ";{1," + opts.digits + "}]" : (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}"),
  377. "" !== opts.negationSymbol.back && (mask += "[-]"), mask += autoEscape(opts.suffix),
  378. opts.greedy = !1, mask;
  379. },
  380. placeholder: "",
  381. greedy: !1,
  382. digits: "*",
  383. digitsOptional: !0,
  384. radixPoint: ".",
  385. radixFocus: !0,
  386. groupSize: 3,
  387. groupSeparator: "",
  388. autoGroup: !1,
  389. allowPlus: !0,
  390. allowMinus: !0,
  391. negationSymbol: {
  392. front: "-",
  393. back: ""
  394. },
  395. integerDigits: "+",
  396. integerOptional: !0,
  397. prefix: "",
  398. suffix: "",
  399. rightAlign: !0,
  400. decimalProtect: !0,
  401. min: null,
  402. max: null,
  403. step: 1,
  404. insertMode: !0,
  405. autoUnmask: !1,
  406. unmaskAsNumber: !1,
  407. postFormat: function(buffer, pos, reformatOnly, opts) {
  408. opts.numericInput === !0 && (buffer = buffer.reverse(), isFinite(pos) && (pos = buffer.join("").length - pos - 1));
  409. var i, l, suffixStripped = !1;
  410. buffer.length >= opts.suffix.length && buffer.join("").indexOf(opts.suffix) === buffer.length - opts.suffix.length && (buffer.length = buffer.length - opts.suffix.length,
  411. suffixStripped = !0), pos = pos >= buffer.length ? buffer.length - 1 : pos < opts.prefix.length ? opts.prefix.length : pos;
  412. var needsRefresh = !1, charAtPos = buffer[pos];
  413. if ("" === opts.groupSeparator || opts.numericInput !== !0 && -1 !== $.inArray(opts.radixPoint, buffer) && pos > $.inArray(opts.radixPoint, buffer) || new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]").test(charAtPos)) {
  414. if (suffixStripped) for (i = 0, l = opts.suffix.length; l > i; i++) buffer.push(opts.suffix.charAt(i));
  415. return {
  416. pos: pos
  417. };
  418. }
  419. var cbuf = buffer.slice();
  420. charAtPos === opts.groupSeparator && (cbuf.splice(pos--, 1), charAtPos = cbuf[pos]),
  421. reformatOnly ? charAtPos !== opts.radixPoint && (cbuf[pos] = "?") : cbuf.splice(pos, 0, "?");
  422. var bufVal = cbuf.join(""), bufValOrigin = bufVal;
  423. if (bufVal.length > 0 && opts.autoGroup || reformatOnly && -1 !== bufVal.indexOf(opts.groupSeparator)) {
  424. var escapedGroupSeparator = Inputmask.escapeRegex(opts.groupSeparator);
  425. needsRefresh = 0 === bufVal.indexOf(opts.groupSeparator), bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), "");
  426. var radixSplit = bufVal.split(opts.radixPoint);
  427. if (bufVal = "" === opts.radixPoint ? bufVal : radixSplit[0], bufVal !== opts.prefix + "?0" && bufVal.length >= opts.groupSize + opts.prefix.length) for (var reg = new RegExp("([-+]?[\\d?]+)([\\d?]{" + opts.groupSize + "})"); reg.test(bufVal); ) bufVal = bufVal.replace(reg, "$1" + opts.groupSeparator + "$2"),
  428. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  429. "" !== opts.radixPoint && radixSplit.length > 1 && (bufVal += opts.radixPoint + radixSplit[1]);
  430. }
  431. for (needsRefresh = bufValOrigin !== bufVal, buffer.length = bufVal.length, i = 0,
  432. l = bufVal.length; l > i; i++) buffer[i] = bufVal.charAt(i);
  433. var newPos = $.inArray("?", buffer);
  434. if (-1 === newPos && charAtPos === opts.radixPoint && (newPos = $.inArray(opts.radixPoint, buffer)),
  435. reformatOnly ? buffer[newPos] = charAtPos : buffer.splice(newPos, 1), !needsRefresh && suffixStripped) for (i = 0,
  436. l = opts.suffix.length; l > i; i++) buffer.push(opts.suffix.charAt(i));
  437. return newPos = opts.numericInput && isFinite(pos) ? buffer.join("").length - newPos - 1 : newPos,
  438. opts.numericInput && (buffer = buffer.reverse(), $.inArray(opts.radixPoint, buffer) < newPos && buffer.join("").length - opts.suffix.length !== newPos && (newPos -= 1)),
  439. {
  440. pos: newPos,
  441. refreshFromBuffer: needsRefresh,
  442. buffer: buffer
  443. };
  444. },
  445. onBeforeWrite: function(e, buffer, caretPos, opts) {
  446. if (e && ("blur" === e.type || "checkval" === e.type)) {
  447. var maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  448. if (processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  449. "," === opts.radixPoint && (processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".")),
  450. isFinite(processValue) && isFinite(opts.min) && parseFloat(processValue) < parseFloat(opts.min)) return $.extend(!0, {
  451. refreshFromBuffer: !0,
  452. buffer: (opts.prefix + opts.min).split("")
  453. }, opts.postFormat((opts.prefix + opts.min).split(""), 0, !0, opts));
  454. if (opts.numericInput !== !0) {
  455. var tmpBufSplit = "" !== opts.radixPoint ? buffer.join("").split(opts.radixPoint) : [ buffer.join("") ], matchRslt = tmpBufSplit[0].match(opts.regex.integerPart(opts)), matchRsltDigits = 2 === tmpBufSplit.length ? tmpBufSplit[1].match(opts.regex.integerNPart(opts)) : void 0;
  456. if (matchRslt) {
  457. matchRslt[0] !== opts.negationSymbol.front + "0" && matchRslt[0] !== opts.negationSymbol.front && "+" !== matchRslt[0] || void 0 !== matchRsltDigits && !matchRsltDigits[0].match(/^0+$/) || buffer.splice(matchRslt.index, 1);
  458. var radixPosition = $.inArray(opts.radixPoint, buffer);
  459. if (-1 !== radixPosition) {
  460. if (isFinite(opts.digits) && !opts.digitsOptional) {
  461. for (var i = 1; i <= opts.digits; i++) (void 0 === buffer[radixPosition + i] || buffer[radixPosition + i] === opts.placeholder.charAt(0)) && (buffer[radixPosition + i] = "0");
  462. return {
  463. refreshFromBuffer: maskedValue !== buffer.join(""),
  464. buffer: buffer
  465. };
  466. }
  467. if (radixPosition === buffer.length - opts.suffix.length - 1) return buffer.splice(radixPosition, 1),
  468. {
  469. refreshFromBuffer: !0,
  470. buffer: buffer
  471. };
  472. }
  473. }
  474. }
  475. }
  476. if (opts.autoGroup) {
  477. var rslt = opts.postFormat(buffer, opts.numericInput ? caretPos : caretPos - 1, !0, opts);
  478. return rslt.caret = caretPos <= opts.prefix.length ? rslt.pos : rslt.pos + 1, rslt;
  479. }
  480. },
  481. regex: {
  482. integerPart: function(opts) {
  483. return new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
  484. },
  485. integerNPart: function(opts) {
  486. return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + "]+");
  487. }
  488. },
  489. signHandler: function(chrs, maskset, pos, strict, opts) {
  490. if (!strict && opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) {
  491. var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts));
  492. if (matchRslt && matchRslt[0].length > 0) return maskset.buffer[matchRslt.index] === ("-" === chrs ? "+" : opts.negationSymbol.front) ? "-" === chrs ? "" !== opts.negationSymbol.back ? {
  493. pos: matchRslt.index,
  494. c: opts.negationSymbol.front,
  495. remove: matchRslt.index,
  496. caret: pos,
  497. insert: {
  498. pos: maskset.buffer.length - opts.suffix.length - 1,
  499. c: opts.negationSymbol.back
  500. }
  501. } : {
  502. pos: matchRslt.index,
  503. c: opts.negationSymbol.front,
  504. remove: matchRslt.index,
  505. caret: pos
  506. } : "" !== opts.negationSymbol.back ? {
  507. pos: matchRslt.index,
  508. c: "+",
  509. remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
  510. caret: pos
  511. } : {
  512. pos: matchRslt.index,
  513. c: "+",
  514. remove: matchRslt.index,
  515. caret: pos
  516. } : maskset.buffer[matchRslt.index] === ("-" === chrs ? opts.negationSymbol.front : "+") ? "-" === chrs && "" !== opts.negationSymbol.back ? {
  517. remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
  518. caret: pos - 1
  519. } : {
  520. remove: matchRslt.index,
  521. caret: pos - 1
  522. } : "-" === chrs ? "" !== opts.negationSymbol.back ? {
  523. pos: matchRslt.index,
  524. c: opts.negationSymbol.front,
  525. caret: pos + 1,
  526. insert: {
  527. pos: maskset.buffer.length - opts.suffix.length,
  528. c: opts.negationSymbol.back
  529. }
  530. } : {
  531. pos: matchRslt.index,
  532. c: opts.negationSymbol.front,
  533. caret: pos + 1
  534. } : {
  535. pos: matchRslt.index,
  536. c: chrs,
  537. caret: pos + 1
  538. };
  539. }
  540. return !1;
  541. },
  542. radixHandler: function(chrs, maskset, pos, strict, opts) {
  543. if (!strict && (-1 !== $.inArray(chrs, [ ",", "." ]) && (chrs = opts.radixPoint),
  544. chrs === opts.radixPoint && void 0 !== opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
  545. var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join("").match(opts.regex.integerPart(opts));
  546. if (-1 !== radixPos && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? {
  547. caret: radixPos + 1
  548. } : {
  549. pos: integerValue.index,
  550. c: integerValue[0],
  551. caret: radixPos + 1
  552. };
  553. if (!integerValue || "0" === integerValue[0] && integerValue.index + 1 !== pos) return maskset.buffer[integerValue ? integerValue.index : pos] = "0",
  554. {
  555. pos: (integerValue ? integerValue.index : pos) + 1,
  556. c: opts.radixPoint
  557. };
  558. }
  559. return !1;
  560. },
  561. leadingZeroHandler: function(chrs, maskset, pos, strict, opts) {
  562. if (opts.numericInput === !0) {
  563. if ("0" === maskset.buffer[maskset.buffer.length - opts.prefix.length - 1]) return {
  564. pos: pos,
  565. remove: maskset.buffer.length - opts.prefix.length - 1
  566. };
  567. } else {
  568. var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  569. if (matchRslt && !strict && (-1 === radixPosition || radixPosition >= pos)) if (0 === matchRslt[0].indexOf("0")) {
  570. pos < opts.prefix.length && (pos = matchRslt.index);
  571. var _radixPosition = $.inArray(opts.radixPoint, maskset._buffer), digitsMatch = maskset._buffer && maskset.buffer.slice(radixPosition).join("") === maskset._buffer.slice(_radixPosition).join("") || 0 === parseInt(maskset.buffer.slice(radixPosition + 1).join("")), integerMatch = maskset._buffer && maskset.buffer.slice(matchRslt.index, radixPosition).join("") === maskset._buffer.slice(opts.prefix.length, _radixPosition).join("") || "0" === maskset.buffer.slice(matchRslt.index, radixPosition).join("");
  572. if (-1 === radixPosition || digitsMatch && integerMatch) return maskset.buffer.splice(matchRslt.index, 1),
  573. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, {
  574. pos: pos,
  575. remove: matchRslt.index
  576. };
  577. if (matchRslt.index + 1 === pos || "0" === chrs) return maskset.buffer.splice(matchRslt.index, 1),
  578. pos = matchRslt.index, {
  579. pos: pos,
  580. remove: matchRslt.index
  581. };
  582. } else if ("0" === chrs && pos <= matchRslt.index && matchRslt[0] !== opts.groupSeparator) return !1;
  583. }
  584. return !0;
  585. },
  586. postValidation: function(buffer, opts) {
  587. var isValid = !0, maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  588. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  589. "," === opts.radixPoint && (processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".")),
  590. processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-"),
  591. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), ""),
  592. processValue = processValue === opts.negationSymbol.front ? processValue + "0" : processValue,
  593. isFinite(processValue) && (null !== opts.max && isFinite(opts.max) && (isValid = parseFloat(processValue) <= parseFloat(opts.max)),
  594. isValid && null !== opts.min && isFinite(opts.min) && (0 >= processValue || processValue.toString().length >= opts.min.toString().length) && (isValid = parseFloat(processValue) >= parseFloat(opts.min),
  595. isValid || (isValid = $.extend(!0, {
  596. refreshFromBuffer: !0,
  597. buffer: (opts.prefix + opts.min).split("")
  598. }, opts.postFormat((opts.prefix + opts.min).split(""), 0, !0, opts)), isValid.refreshFromBuffer = !0))),
  599. isValid;
  600. },
  601. definitions: {
  602. "~": {
  603. validator: function(chrs, maskset, pos, strict, opts) {
  604. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  605. if (!isValid && (isValid = opts.radixHandler(chrs, maskset, pos, strict, opts),
  606. !isValid && (isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs),
  607. isValid === !0 && (isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts),
  608. isValid === !0)))) {
  609. var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  610. isValid = -1 !== radixPosition && opts.digitsOptional === !1 && opts.numericInput !== !0 && pos > radixPosition && !strict ? {
  611. pos: pos,
  612. remove: pos
  613. } : {
  614. pos: pos
  615. };
  616. }
  617. return isValid;
  618. },
  619. cardinality: 1,
  620. prevalidator: null
  621. },
  622. "+": {
  623. validator: function(chrs, maskset, pos, strict, opts) {
  624. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  625. return !isValid && (strict && opts.allowMinus && chrs === opts.negationSymbol.front || opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) && (isValid = "-" === chrs ? "" !== opts.negationSymbol.back ? {
  626. pos: pos,
  627. c: "-" === chrs ? opts.negationSymbol.front : "+",
  628. caret: pos + 1,
  629. insert: {
  630. pos: maskset.buffer.length,
  631. c: opts.negationSymbol.back
  632. }
  633. } : {
  634. pos: pos,
  635. c: "-" === chrs ? opts.negationSymbol.front : "+",
  636. caret: pos + 1
  637. } : !0), isValid;
  638. },
  639. cardinality: 1,
  640. prevalidator: null,
  641. placeholder: ""
  642. },
  643. "-": {
  644. validator: function(chrs, maskset, pos, strict, opts) {
  645. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  646. return !isValid && strict && opts.allowMinus && chrs === opts.negationSymbol.back && (isValid = !0),
  647. isValid;
  648. },
  649. cardinality: 1,
  650. prevalidator: null,
  651. placeholder: ""
  652. },
  653. ":": {
  654. validator: function(chrs, maskset, pos, strict, opts) {
  655. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  656. if (!isValid) {
  657. var radix = "[" + Inputmask.escapeRegex(opts.radixPoint) + ",\\.]";
  658. isValid = new RegExp(radix).test(chrs), isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder === opts.radixPoint && (isValid = {
  659. caret: pos + 1
  660. });
  661. }
  662. return isValid ? {
  663. c: opts.radixPoint
  664. } : isValid;
  665. },
  666. cardinality: 1,
  667. prevalidator: null,
  668. placeholder: function(opts) {
  669. return opts.radixPoint;
  670. }
  671. }
  672. },
  673. onUnMask: function(maskedValue, unmaskedValue, opts) {
  674. var processValue = maskedValue.replace(opts.prefix, "");
  675. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  676. opts.unmaskAsNumber ? ("" !== opts.radixPoint && -1 !== processValue.indexOf(opts.radixPoint) && (processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".")),
  677. Number(processValue)) : processValue;
  678. },
  679. isComplete: function(buffer, opts) {
  680. var maskedValue = buffer.join(""), bufClone = buffer.slice();
  681. if (opts.postFormat(bufClone, 0, !0, opts), bufClone.join("") !== maskedValue) return !1;
  682. var processValue = maskedValue.replace(opts.prefix, "");
  683. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  684. "," === opts.radixPoint && (processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".")),
  685. isFinite(processValue);
  686. },
  687. onBeforeMask: function(initialValue, opts) {
  688. if ("" !== opts.radixPoint && isFinite(initialValue)) initialValue = initialValue.toString().replace(".", opts.radixPoint); else {
  689. var kommaMatches = initialValue.match(/,/g), dotMatches = initialValue.match(/\./g);
  690. dotMatches && kommaMatches ? dotMatches.length > kommaMatches.length ? (initialValue = initialValue.replace(/\./g, ""),
  691. initialValue = initialValue.replace(",", opts.radixPoint)) : kommaMatches.length > dotMatches.length ? (initialValue = initialValue.replace(/,/g, ""),
  692. initialValue = initialValue.replace(".", opts.radixPoint)) : initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "") : initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  693. }
  694. if (0 === opts.digits && (-1 !== initialValue.indexOf(".") ? initialValue = initialValue.substring(0, initialValue.indexOf(".")) : -1 !== initialValue.indexOf(",") && (initialValue = initialValue.substring(0, initialValue.indexOf(",")))),
  695. "" !== opts.radixPoint && isFinite(opts.digits) && -1 !== initialValue.indexOf(opts.radixPoint)) {
  696. var valueParts = initialValue.split(opts.radixPoint), decPart = valueParts[1].match(new RegExp("\\d*"))[0];
  697. if (parseInt(opts.digits) < decPart.toString().length) {
  698. var digitsFactor = Math.pow(10, parseInt(opts.digits));
  699. initialValue = initialValue.replace(Inputmask.escapeRegex(opts.radixPoint), "."),
  700. initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor,
  701. initialValue = initialValue.toString().replace(".", opts.radixPoint);
  702. }
  703. }
  704. return initialValue.toString();
  705. },
  706. canClearPosition: function(maskset, position, lvp, strict, opts) {
  707. var positionInput = maskset.validPositions[position].input, canClear = positionInput !== opts.radixPoint || null !== maskset.validPositions[position].match.fn && opts.decimalProtect === !1 || isFinite(positionInput) || position === lvp || positionInput === opts.groupSeparator || positionInput === opts.negationSymbol.front || positionInput === opts.negationSymbol.back;
  708. if (canClear && isFinite(positionInput)) {
  709. var matchRslt, radixPos = $.inArray(opts.radixPoint, maskset.buffer), radixInjection = !1;
  710. if (void 0 === maskset.validPositions[radixPos] && (maskset.validPositions[radixPos] = {
  711. input: opts.radixPoint
  712. }, radixInjection = !0), !strict && maskset.buffer) {
  713. matchRslt = maskset.buffer.join("").substr(0, position).match(opts.regex.integerNPart(opts));
  714. var pos = position + 1, isNull = null == matchRslt || 0 === parseInt(matchRslt[0].replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""));
  715. if (isNull) for (;maskset.validPositions[pos] && (maskset.validPositions[pos].input === opts.groupSeparator || "0" === maskset.validPositions[pos].input); ) delete maskset.validPositions[pos],
  716. pos++;
  717. }
  718. var buffer = [];
  719. for (var vp in maskset.validPositions) void 0 !== maskset.validPositions[vp].input && buffer.push(maskset.validPositions[vp].input);
  720. if (radixInjection && delete maskset.validPositions[radixPos], radixPos > 0) {
  721. var bufVal = buffer.join("");
  722. if (matchRslt = bufVal.match(opts.regex.integerNPart(opts))) if (radixPos >= position) if (0 === matchRslt[0].indexOf("0")) canClear = matchRslt.index !== position || "0" === opts.placeholder; else {
  723. var intPart = parseInt(matchRslt[0].replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "")), radixPart = parseInt(bufVal.split(opts.radixPoint)[1]);
  724. 10 > intPart && maskset.validPositions[position] && ("0" !== opts.placeholder || radixPart > 0) && (maskset.validPositions[position].input = "0",
  725. maskset.p = opts.prefix.length + 1, canClear = !1);
  726. } else 0 === matchRslt[0].indexOf("0") && 3 === bufVal.length && (maskset.validPositions = {},
  727. canClear = !1);
  728. }
  729. }
  730. return canClear;
  731. },
  732. onKeyDown: function(e, buffer, caretPos, opts) {
  733. var $input = $(this);
  734. if (e.ctrlKey) switch (e.keyCode) {
  735. case Inputmask.keyCode.UP:
  736. $input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step)), $input.trigger("setvalue");
  737. break;
  738. case Inputmask.keyCode.DOWN:
  739. $input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step)), $input.trigger("setvalue");
  740. }
  741. }
  742. },
  743. currency: {
  744. prefix: "$ ",
  745. groupSeparator: ",",
  746. alias: "numeric",
  747. placeholder: "0",
  748. autoGroup: !0,
  749. digits: 2,
  750. digitsOptional: !1,
  751. clearMaskOnLostFocus: !1
  752. },
  753. decimal: {
  754. alias: "numeric"
  755. },
  756. integer: {
  757. alias: "numeric",
  758. digits: 0,
  759. radixPoint: ""
  760. },
  761. percentage: {
  762. alias: "numeric",
  763. digits: 2,
  764. radixPoint: ".",
  765. placeholder: "0",
  766. autoGroup: !1,
  767. min: 0,
  768. max: 100,
  769. suffix: " %",
  770. allowPlus: !1,
  771. allowMinus: !1
  772. }
  773. }), Inputmask;
  774. });