inputmask.numeric.extensions.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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.1.64-124
  7. */
  8. !function(factory) {
  9. "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
  10. }(function($) {
  11. return inputmask.extendAliases({
  12. numeric: {
  13. mask: function(opts) {
  14. function autoEscape(txt) {
  15. for (var escapedTxt = "", i = 0; i < txt.length; i++) escapedTxt += opts.definitions[txt[i]] ? "\\" + txt[i] : txt[i];
  16. return escapedTxt;
  17. }
  18. if (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. opts.autoGroup && ("string" == typeof opts.groupSize && isFinite(opts.groupSize) && (opts.groupSize = parseInt(opts.groupSize)),
  22. isFinite(opts.integerDigits))) {
  23. var seps = Math.floor(opts.integerDigits / opts.groupSize), mod = opts.integerDigits % opts.groupSize;
  24. opts.integerDigits = parseInt(opts.integerDigits) + (0 == mod ? seps - 1 : seps);
  25. }
  26. opts.placeholder.length > 1 && (opts.placeholder = opts.placeholder.charAt(0)),
  27. opts.definitions[";"] = opts.definitions["~"], opts.definitions[";"].definitionSymbol = "~",
  28. 1 == opts.numericInput && (opts.radixFocus = !1, opts.digitsOptional = !1, isNaN(opts.digits) && (opts.digits = 2),
  29. opts.decimalProtect = !1);
  30. var mask = autoEscape(opts.prefix);
  31. return mask += "[+]", mask += "~{1," + opts.integerDigits + "}", void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (mask += opts.digitsOptional ? "[" + (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}]" : (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}"),
  32. "" != opts.negationSymbol.back && (mask += "[-]"), mask += autoEscape(opts.suffix),
  33. opts.greedy = !1, mask;
  34. },
  35. placeholder: "",
  36. greedy: !1,
  37. digits: "*",
  38. digitsOptional: !0,
  39. radixPoint: ".",
  40. radixFocus: !0,
  41. groupSize: 3,
  42. groupSeparator: "",
  43. autoGroup: !1,
  44. allowPlus: !0,
  45. allowMinus: !0,
  46. negationSymbol: {
  47. front: "-",
  48. back: ""
  49. },
  50. integerDigits: "+",
  51. prefix: "",
  52. suffix: "",
  53. rightAlign: !0,
  54. decimalProtect: !0,
  55. min: void 0,
  56. max: void 0,
  57. step: 1,
  58. insertMode: !0,
  59. autoUnmask: !1,
  60. unmaskAsNumber: !1,
  61. postFormat: function(buffer, pos, reformatOnly, opts) {
  62. opts.numericInput === !0 && (buffer = buffer.reverse(), isFinite(pos) && (pos = buffer.join("").length - pos - 1));
  63. var suffixStripped = !1;
  64. buffer.length >= opts.suffix.length && buffer.join("").indexOf(opts.suffix) == buffer.length - opts.suffix.length && (buffer.length = buffer.length - opts.suffix.length,
  65. suffixStripped = !0), pos = pos >= buffer.length ? buffer.length - 1 : pos < opts.prefix.length ? opts.prefix.length : pos;
  66. var needsRefresh = !1, charAtPos = buffer[pos];
  67. 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)) {
  68. if (suffixStripped) for (var i = 0, l = opts.suffix.length; l > i; i++) buffer.push(opts.suffix.charAt(i));
  69. return {
  70. pos: pos
  71. };
  72. }
  73. var cbuf = buffer.slice();
  74. charAtPos == opts.groupSeparator && (cbuf.splice(pos--, 1), charAtPos = cbuf[pos]),
  75. reformatOnly ? charAtPos != opts.radixPoint && (cbuf[pos] = "?") : cbuf.splice(pos, 0, "?");
  76. var bufVal = cbuf.join(""), bufValOrigin = bufVal;
  77. if (bufVal.length > 0 && opts.autoGroup || reformatOnly && -1 != bufVal.indexOf(opts.groupSeparator)) {
  78. var escapedGroupSeparator = inputmask.escapeRegex(opts.groupSeparator);
  79. needsRefresh = 0 == bufVal.indexOf(opts.groupSeparator), bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), "");
  80. var radixSplit = bufVal.split(opts.radixPoint);
  81. 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"),
  82. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  83. "" != opts.radixPoint && radixSplit.length > 1 && (bufVal += opts.radixPoint + radixSplit[1]);
  84. }
  85. needsRefresh = bufValOrigin != bufVal, buffer.length = bufVal.length;
  86. for (var i = 0, l = bufVal.length; l > i; i++) buffer[i] = bufVal.charAt(i);
  87. var newPos = $.inArray("?", buffer);
  88. if (-1 == newPos && charAtPos == opts.radixPoint && (newPos = $.inArray(opts.radixPoint, buffer)),
  89. reformatOnly ? buffer[newPos] = charAtPos : buffer.splice(newPos, 1), !needsRefresh && suffixStripped) for (var i = 0, l = opts.suffix.length; l > i; i++) buffer.push(opts.suffix.charAt(i));
  90. return {
  91. pos: opts.numericInput && isFinite(pos) ? buffer.join("").length - newPos - 1 : newPos,
  92. refreshFromBuffer: needsRefresh,
  93. buffer: opts.numericInput === !0 ? buffer.reverse() : buffer
  94. };
  95. },
  96. onBeforeWrite: function(e, buffer, caretPos, opts) {
  97. if (e && "blur" == e.type) {
  98. var maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  99. if (processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  100. "," === opts.radixPoint && (processValue = processValue.replace(inputmask.escapeRegex(opts.radixPoint), ".")),
  101. isFinite(processValue) && isFinite(opts.min) && parseFloat(processValue) < parseFloat(opts.min)) return $.extend(!0, {
  102. refreshFromBuffer: !0,
  103. buffer: (opts.prefix + opts.min).split("")
  104. }, opts.postFormat((opts.prefix + opts.min).split(""), 0, !0, opts));
  105. if (opts.numericInput !== !0) {
  106. 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;
  107. !matchRslt || 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);
  108. var radixPosition = $.inArray(opts.radixPoint, buffer);
  109. if (-1 != radixPosition) {
  110. if (isFinite(opts.digits) && !opts.digitsOptional) {
  111. for (var i = 1; i <= opts.digits; i++) (void 0 == buffer[radixPosition + i] || buffer[radixPosition + i] == opts.placeholder.charAt(0)) && (buffer[radixPosition + i] = "0");
  112. return {
  113. refreshFromBuffer: !0,
  114. buffer: buffer
  115. };
  116. }
  117. if (radixPosition == buffer.length - opts.suffix.length - 1) return buffer.splice(radixPosition, 1),
  118. {
  119. refreshFromBuffer: !0,
  120. buffer: buffer
  121. };
  122. }
  123. }
  124. }
  125. if (opts.autoGroup) {
  126. var rslt = opts.postFormat(buffer, caretPos - 1, !0, opts);
  127. return rslt.caret = caretPos <= opts.prefix.length ? rslt.pos : rslt.pos + 1, rslt;
  128. }
  129. },
  130. regex: {
  131. integerPart: function(opts) {
  132. return new RegExp("[" + inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
  133. },
  134. integerNPart: function(opts) {
  135. return new RegExp("[\\d" + inputmask.escapeRegex(opts.groupSeparator) + "]+");
  136. }
  137. },
  138. signHandler: function(chrs, maskset, pos, strict, opts) {
  139. if (!strict && opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) {
  140. var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts));
  141. if (matchRslt && matchRslt[0].length > 0) return maskset.buffer[matchRslt.index] == ("-" === chrs ? "+" : opts.negationSymbol.front) ? "-" == chrs ? "" != opts.negationSymbol.back ? {
  142. pos: matchRslt.index,
  143. c: opts.negationSymbol.front,
  144. remove: matchRslt.index,
  145. caret: pos,
  146. insert: {
  147. pos: maskset.buffer.length - opts.suffix.length - 1,
  148. c: opts.negationSymbol.back
  149. }
  150. } : {
  151. pos: matchRslt.index,
  152. c: opts.negationSymbol.front,
  153. remove: matchRslt.index,
  154. caret: pos
  155. } : "" != opts.negationSymbol.back ? {
  156. pos: matchRslt.index,
  157. c: "+",
  158. remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
  159. caret: pos
  160. } : {
  161. pos: matchRslt.index,
  162. c: "+",
  163. remove: matchRslt.index,
  164. caret: pos
  165. } : maskset.buffer[matchRslt.index] == ("-" === chrs ? opts.negationSymbol.front : "+") ? "-" == chrs && "" != opts.negationSymbol.back ? {
  166. remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
  167. caret: pos - 1
  168. } : {
  169. remove: matchRslt.index,
  170. caret: pos - 1
  171. } : "-" == chrs ? "" != opts.negationSymbol.back ? {
  172. pos: matchRslt.index,
  173. c: opts.negationSymbol.front,
  174. caret: pos + 1,
  175. insert: {
  176. pos: maskset.buffer.length - opts.suffix.length,
  177. c: opts.negationSymbol.back
  178. }
  179. } : {
  180. pos: matchRslt.index,
  181. c: opts.negationSymbol.front,
  182. caret: pos + 1
  183. } : {
  184. pos: matchRslt.index,
  185. c: chrs,
  186. caret: pos + 1
  187. };
  188. }
  189. return !1;
  190. },
  191. radixHandler: function(chrs, maskset, pos, strict, opts) {
  192. if (!strict && (-1 != $.inArray(chrs, [ ",", "." ]) && (chrs = opts.radixPoint),
  193. chrs === opts.radixPoint && void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
  194. var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join("").match(opts.regex.integerPart(opts));
  195. if (-1 != radixPos && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? {
  196. caret: radixPos + 1
  197. } : {
  198. pos: integerValue.index,
  199. c: integerValue[0],
  200. caret: radixPos + 1
  201. };
  202. if (!integerValue || "0" == integerValue[0] && integerValue.index + 1 != pos) return maskset.buffer[integerValue ? integerValue.index : pos] = "0",
  203. {
  204. pos: (integerValue ? integerValue.index : pos) + 1,
  205. c: opts.radixPoint
  206. };
  207. }
  208. return !1;
  209. },
  210. leadingZeroHandler: function(chrs, maskset, pos, strict, opts) {
  211. if (1 == opts.numericInput) {
  212. if ("0" == maskset.buffer[maskset.buffer.length - opts.prefix.length - 1]) return {
  213. pos: pos,
  214. remove: maskset.buffer.length - opts.prefix.length - 1
  215. };
  216. } else {
  217. var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  218. if (matchRslt && !strict && (-1 == radixPosition || radixPosition >= pos)) if (0 == matchRslt[0].indexOf("0")) {
  219. pos < opts.prefix.length && (pos = matchRslt.index);
  220. 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("");
  221. if (-1 == radixPosition || digitsMatch && integerMatch) return maskset.buffer.splice(matchRslt.index, 1),
  222. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, {
  223. pos: pos,
  224. remove: matchRslt.index
  225. };
  226. if (matchRslt.index + 1 == pos || "0" == chrs) return maskset.buffer.splice(matchRslt.index, 1),
  227. pos = matchRslt.index, {
  228. pos: pos,
  229. remove: matchRslt.index
  230. };
  231. } else if ("0" === chrs && pos <= matchRslt.index && matchRslt[0] != opts.groupSeparator) return !1;
  232. }
  233. return !0;
  234. },
  235. postValidation: function(buffer, opts) {
  236. var isValid = !0, maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  237. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  238. "," === opts.radixPoint && (processValue = processValue.replace(inputmask.escapeRegex(opts.radixPoint), ".")),
  239. processValue = processValue.replace(new RegExp("^" + inputmask.escapeRegex(opts.negationSymbol.front)), "-"),
  240. processValue = processValue.replace(new RegExp(inputmask.escapeRegex(opts.negationSymbol.back) + "$"), ""),
  241. processValue = processValue == opts.negationSymbol.front ? processValue + "0" : processValue,
  242. isFinite(processValue) && (isFinite(opts.max) && (isValid = parseFloat(processValue) <= parseFloat(opts.max)),
  243. isValid && isFinite(opts.min) && (0 >= processValue || processValue.toString().length >= opts.min.toString().length) && (isValid = parseFloat(processValue) >= parseFloat(opts.min),
  244. isValid || (isValid = $.extend(!0, {
  245. refreshFromBuffer: !0,
  246. buffer: (opts.prefix + opts.min).split("")
  247. }, opts.postFormat((opts.prefix + opts.min).split(""), 0, !0, opts)), isValid.refreshFromBuffer = !0))),
  248. isValid;
  249. },
  250. definitions: {
  251. "~": {
  252. validator: function(chrs, maskset, pos, strict, opts) {
  253. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  254. if (!isValid && (isValid = opts.radixHandler(chrs, maskset, pos, strict, opts),
  255. !isValid && (isValid = strict ? new RegExp("[0-9" + inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs),
  256. isValid === !0 && (isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts),
  257. isValid === !0)))) {
  258. var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  259. isValid = -1 != radixPosition && opts.digitsOptional === !1 && pos > radixPosition && !strict ? {
  260. pos: pos,
  261. remove: pos
  262. } : {
  263. pos: pos
  264. };
  265. }
  266. return isValid;
  267. },
  268. cardinality: 1,
  269. prevalidator: null
  270. },
  271. "+": {
  272. validator: function(chrs, maskset, pos, strict, opts) {
  273. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  274. return !isValid && (strict && opts.allowMinus && chrs === opts.negationSymbol.front || opts.allowMinus && "-" == chrs || opts.allowPlus && "+" == chrs) && (isValid = "-" == chrs ? "" != opts.negationSymbol.back ? {
  275. pos: pos,
  276. c: "-" === chrs ? opts.negationSymbol.front : "+",
  277. caret: pos + 1,
  278. insert: {
  279. pos: maskset.buffer.length,
  280. c: opts.negationSymbol.back
  281. }
  282. } : {
  283. pos: pos,
  284. c: "-" === chrs ? opts.negationSymbol.front : "+",
  285. caret: pos + 1
  286. } : !0), isValid;
  287. },
  288. cardinality: 1,
  289. prevalidator: null,
  290. placeholder: ""
  291. },
  292. "-": {
  293. validator: function(chrs, maskset, pos, strict, opts) {
  294. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  295. return !isValid && strict && opts.allowMinus && chrs === opts.negationSymbol.back && (isValid = !0),
  296. isValid;
  297. },
  298. cardinality: 1,
  299. prevalidator: null,
  300. placeholder: ""
  301. },
  302. ":": {
  303. validator: function(chrs, maskset, pos, strict, opts) {
  304. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  305. if (!isValid) {
  306. var radix = "[" + inputmask.escapeRegex(opts.radixPoint) + ",\\.]";
  307. isValid = new RegExp(radix).test(chrs), isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder == opts.radixPoint && (isValid = {
  308. caret: pos + 1
  309. });
  310. }
  311. return isValid ? {
  312. c: opts.radixPoint
  313. } : isValid;
  314. },
  315. cardinality: 1,
  316. prevalidator: null,
  317. placeholder: function(opts) {
  318. return opts.radixPoint;
  319. }
  320. }
  321. },
  322. onUnMask: function(maskedValue, unmaskedValue, opts) {
  323. var processValue = maskedValue.replace(opts.prefix, "");
  324. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  325. opts.unmaskAsNumber ? (processValue = processValue.replace(inputmask.escapeRegex.call(this, opts.radixPoint), "."),
  326. Number(processValue)) : processValue;
  327. },
  328. isComplete: function(buffer, opts) {
  329. var maskedValue = buffer.join(""), bufClone = buffer.slice();
  330. if (opts.postFormat(bufClone, 0, !0, opts), bufClone.join("") != maskedValue) return !1;
  331. var processValue = maskedValue.replace(opts.prefix, "");
  332. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  333. "," === opts.radixPoint && (processValue = processValue.replace(inputmask.escapeRegex(opts.radixPoint), ".")),
  334. isFinite(processValue);
  335. },
  336. onBeforeMask: function(initialValue, opts) {
  337. if ("" != opts.radixPoint && isFinite(initialValue)) initialValue = initialValue.toString().replace(".", opts.radixPoint); else {
  338. var kommaMatches = initialValue.match(/,/g), dotMatches = initialValue.match(/\./g);
  339. dotMatches && kommaMatches ? dotMatches.length > kommaMatches.length ? (initialValue = initialValue.replace(/\./g, ""),
  340. initialValue = initialValue.replace(",", opts.radixPoint)) : kommaMatches.length > dotMatches.length ? (initialValue = initialValue.replace(/,/g, ""),
  341. 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"), "");
  342. }
  343. if (0 == opts.digits && (-1 != initialValue.indexOf(".") ? initialValue = initialValue.substring(0, initialValue.indexOf(".")) : -1 != initialValue.indexOf(",") && (initialValue = initialValue.substring(0, initialValue.indexOf(",")))),
  344. "" != opts.radixPoint && isFinite(opts.digits) && -1 != initialValue.indexOf(opts.radixPoint)) {
  345. var valueParts = initialValue.split(opts.radixPoint), decPart = valueParts[1].match(new RegExp("\\d*"))[0];
  346. if (parseInt(opts.digits) < decPart.toString().length) {
  347. var digitsFactor = Math.pow(10, parseInt(opts.digits));
  348. initialValue = initialValue.replace(inputmask.escapeRegex(opts.radixPoint), "."),
  349. initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor,
  350. initialValue = initialValue.toString().replace(".", opts.radixPoint);
  351. }
  352. }
  353. return initialValue.toString();
  354. },
  355. canClearPosition: function(maskset, position, lvp, strict, opts) {
  356. var positionInput = maskset.validPositions[position].input, canClear = positionInput != opts.radixPoint || null != maskset.validPositions[position].match.fn && 0 == opts.decimalProtect || isFinite(positionInput) || position == lvp || positionInput == opts.groupSeparator || positionInput == opts.negationSymbol.front || positionInput == opts.negationSymbol.back;
  357. if (canClear && isFinite(positionInput)) {
  358. var matchRslt;
  359. if (!strict && maskset.buffer) {
  360. matchRslt = maskset.buffer.join("").substr(0, position).match(opts.regex.integerNPart(opts));
  361. var pos = position + 1, isNull = null == matchRslt || 0 == parseInt(matchRslt[0].replace(new RegExp(inputmask.escapeRegex(opts.groupSeparator), "g"), ""));
  362. if (isNull) for (;maskset.validPositions[pos] && (maskset.validPositions[pos].input == opts.groupSeparator || "0" == maskset.validPositions[pos].input); ) delete maskset.validPositions[pos],
  363. pos++;
  364. }
  365. var buffer = [];
  366. for (var vp in maskset.validPositions) buffer.push(maskset.validPositions[vp].input);
  367. 1 == opts.numericInput && (position = buffer.join("").length - position, buffer.reverse()),
  368. matchRslt = buffer.join("").match(opts.regex.integerNPart(opts));
  369. var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  370. if (matchRslt && (-1 == radixPosition || radixPosition >= position)) if (0 == matchRslt[0].indexOf("0")) canClear = matchRslt.index != position || -1 == radixPosition; else {
  371. var intPart = parseInt(matchRslt[0].replace(new RegExp(inputmask.escapeRegex(opts.groupSeparator), "g"), ""));
  372. -1 != radixPosition && 10 > intPart && maskset.validPositions[position] && (maskset.validPositions[position].input = "0",
  373. maskset.p = opts.prefix.length + 1, canClear = !1);
  374. }
  375. }
  376. return canClear;
  377. },
  378. onKeyDown: function(e, buffer, caretPos, opts) {
  379. var $input = $(this);
  380. if (e.ctrlKey) switch (e.keyCode) {
  381. case inputmask.keyCode.UP:
  382. $input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step)), $input.triggerHandler("setvalue.inputmask");
  383. break;
  384. case inputmask.keyCode.DOWN:
  385. $input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step)), $input.triggerHandler("setvalue.inputmask");
  386. }
  387. }
  388. },
  389. currency: {
  390. prefix: "$ ",
  391. groupSeparator: ",",
  392. alias: "numeric",
  393. placeholder: "0",
  394. autoGroup: !0,
  395. digits: 2,
  396. digitsOptional: !1,
  397. clearMaskOnLostFocus: !1
  398. },
  399. decimal: {
  400. alias: "numeric"
  401. },
  402. integer: {
  403. alias: "numeric",
  404. digits: 0,
  405. radixPoint: ""
  406. },
  407. percentage: {
  408. alias: "numeric",
  409. digits: 2,
  410. radixPoint: ".",
  411. placeholder: "0",
  412. autoGroup: !1,
  413. min: 0,
  414. max: 100,
  415. suffix: " %",
  416. allowPlus: !1,
  417. allowMinus: !1
  418. },
  419. numeric2: {
  420. alias: "numeric"
  421. }
  422. }), inputmask;
  423. });