inputmask.numeric.extensions.js 28 KB

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