jquery.inputmask.numeric.extensions.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. Input Mask plugin extensions
  3. http://github.com/RobinHerbots/jquery.inputmask
  4. Copyright (c) 2010 - Robin Herbots
  5. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. Version: 0.0.0-dev
  7. Optional extensions on the jquery.inputmask base
  8. */
  9. (function ($) {
  10. //number aliases
  11. $.extend($.inputmask.defaults.aliases, {
  12. 'numeric': {
  13. mask: function (opts) {
  14. function autoEscape(txt) {
  15. var escapedTxt = "";
  16. for (var i = 0; i < txt.length; i++) {
  17. escapedTxt += opts.definitions[txt[i]] ? "\\" + txt[i] : txt[i];
  18. }
  19. return escapedTxt;
  20. }
  21. if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
  22. opts.integerDigits = opts.repeat;
  23. }
  24. opts.repeat = 0;
  25. if (opts.groupSeparator == opts.radixPoint) { //treat equal separator and radixpoint
  26. if (opts.radixPoint == ".")
  27. opts.groupSeparator = ",";
  28. else if (opts.radixPoint == ",")
  29. opts.groupSeparator = ".";
  30. else opts.groupSeparator = "";
  31. }
  32. if (opts.groupSeparator === " ") { //prevent conflict with default skipOptionalPartCharacter
  33. opts.skipOptionalPartCharacter = undefined;
  34. }
  35. opts.autoGroup = opts.autoGroup && opts.groupSeparator != "";
  36. if (opts.autoGroup) {
  37. if (typeof opts.groupSize == "string" && isFinite(opts.groupSize)) opts.groupSize = parseInt(opts.groupSize);
  38. if (isFinite(opts.integerDigits)) {
  39. var seps = Math.floor(opts.integerDigits / opts.groupSize);
  40. var mod = opts.integerDigits % opts.groupSize;
  41. opts.integerDigits = parseInt(opts.integerDigits) + (mod == 0 ? seps - 1 : seps);
  42. }
  43. }
  44. //enforce placeholder to single
  45. if (opts.placeholder.length > 1)
  46. opts.placeholder = opts.placeholder.charAt(0);
  47. //only allow radixfocus when placeholder = 0
  48. opts.radixFocus = opts.radixFocus && opts.placeholder == "0";
  49. opts.definitions[";"] = opts.definitions["~"]; //clone integer def for decimals
  50. opts.definitions[";"].definitionSymbol = "~";
  51. var mask = autoEscape(opts.prefix);
  52. mask += "[+]";
  53. mask += "~{1," + opts.integerDigits + "}";
  54. if (opts.digits != undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
  55. if (opts.digitsOptional)
  56. mask += "[" + (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}]";
  57. else mask += (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}";
  58. }
  59. if (opts.negationSymbol.back != "")
  60. mask += "[-]";
  61. mask += autoEscape(opts.suffix);
  62. opts.greedy = false; //enforce greedy false
  63. return mask;
  64. },
  65. placeholder: "",
  66. greedy: false,
  67. digits: "*", //number of fractionalDigits
  68. digitsOptional: true,
  69. groupSeparator: "",//",", // | "."
  70. radixPoint: ".",
  71. radixFocus: true,
  72. groupSize: 3,
  73. autoGroup: false,
  74. allowPlus: true,
  75. allowMinus: true,
  76. negationSymbol: {
  77. front: "-", //"("
  78. back: "" //")"
  79. },
  80. integerDigits: "+", //number of integerDigits
  81. prefix: "",
  82. suffix: "",
  83. rightAlign: true,
  84. decimalProtect: true, //do not allow assumption of decimals input without entering the radixpoint
  85. min: undefined, //minimum value
  86. max: undefined, //maximum value
  87. postFormat: function (buffer, pos, reformatOnly, opts) { //this needs to be removed // this is crap
  88. //console.log("input " + buffer);
  89. var negationStrip = false;
  90. var suffixStripped = false;
  91. if (buffer.length >= opts.suffix.length && buffer.join('').indexOf(opts.suffix) == (buffer.length - opts.suffix.length)) {
  92. buffer.length = buffer.length - opts.suffix.length; //strip suffix
  93. suffixStripped = true;
  94. }
  95. //position overflow corrections
  96. pos = pos >= buffer.length ? buffer.length - 1 : (pos < opts.prefix.length ? opts.prefix.length : pos);
  97. var needsRefresh = false, charAtPos = buffer[pos];
  98. if (opts.groupSeparator == "" ||
  99. ($.inArray(opts.radixPoint, buffer) != -1 && pos > $.inArray(opts.radixPoint, buffer)) ||
  100. new RegExp('[' + $.inputmask.escapeRegex(opts.negationSymbol.front) + '\+]').test(charAtPos)
  101. ) {
  102. if (suffixStripped) {
  103. for (var i = 0, l = opts.suffix.length; i < l; i++) {
  104. buffer.push(opts.suffix.charAt(i));
  105. }
  106. }
  107. //console.log("return input " + buffer);
  108. return { pos: pos };
  109. }
  110. var cbuf = buffer.slice();
  111. if (charAtPos == opts.groupSeparator) {
  112. cbuf.splice(pos--, 1);
  113. charAtPos = cbuf[pos];
  114. }
  115. if (reformatOnly) {
  116. if(charAtPos != opts.radixPoint) cbuf[pos] = "?";
  117. } else cbuf.splice(pos, 0, "?"); //set position indicator
  118. var bufVal = cbuf.join(''), bufValOrigin = bufVal;
  119. if (bufVal.length > 0 && opts.autoGroup || (reformatOnly && bufVal.indexOf(opts.groupSeparator) != -1)) {
  120. var escapedGroupSeparator = $.inputmask.escapeRegex(opts.groupSeparator);
  121. needsRefresh = bufVal.indexOf(opts.groupSeparator) == 0;
  122. bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), '');
  123. var radixSplit = bufVal.split(opts.radixPoint);
  124. bufVal = opts.radixPoint == "" ? bufVal : radixSplit[0];
  125. if (bufVal != (opts.prefix + "?0") && bufVal.length >= (opts.groupSize + opts.prefix.length)) {
  126. //needsRefresh = true;
  127. var reg = new RegExp('([-\+]?[\\d\?]+)([\\d\?]{' + opts.groupSize + '})');
  128. while (reg.test(bufVal)) {
  129. bufVal = bufVal.replace(reg, '$1' + opts.groupSeparator + '$2');
  130. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  131. }
  132. }
  133. if (opts.radixPoint != "" && radixSplit.length > 1)
  134. bufVal += opts.radixPoint + radixSplit[1];
  135. }
  136. needsRefresh = bufValOrigin != bufVal;
  137. buffer.length = bufVal.length; //align the length
  138. for (var i = 0, l = bufVal.length; i < l; i++) {
  139. buffer[i] = bufVal.charAt(i);
  140. }
  141. var newPos = $.inArray("?", buffer);
  142. if(newPos == -1) newPos = pos;
  143. if (reformatOnly) buffer[newPos] = charAtPos; else buffer.splice(newPos, 1);
  144. if (!needsRefresh && suffixStripped) {
  145. for (var i = 0, l = opts.suffix.length; i < l; i++) {
  146. buffer.push(opts.suffix.charAt(i));
  147. }
  148. }
  149. //console.log("formatted " + buffer + " refresh " + needsRefresh);
  150. return { pos: newPos, "refreshFromBuffer": needsRefresh, "buffer": buffer };
  151. },
  152. onBeforeWrite: function (e, buffer, caretPos, opts) {
  153. if (e && e.type == "blur") {
  154. //handle minvalue
  155. var maskedValue = buffer.join(''),
  156. processValue = maskedValue.replace(opts.prefix, "");
  157. processValue = processValue.replace(opts.suffix, "");
  158. processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  159. if (opts.radixPoint === ",") processValue = processValue.replace($.inputmask.escapeRegex(opts.radixPoint), ".");
  160. if (isFinite(processValue)) {
  161. if (isFinite(opts.min) && parseFloat(processValue) < parseFloat(opts.min)) {
  162. return $.extend(true, { "refreshFromBuffer": true, "buffer": (opts.prefix + opts.min).split('') }, opts.postFormat((opts.prefix + opts.min).split(''), 0, true, opts));
  163. }
  164. }
  165. var tmpBufSplit = opts.radixPoint != "" ? buffer.join('').split(opts.radixPoint) : [buffer.join('')],
  166. matchRslt = tmpBufSplit[0].match(opts.regex.integerPart(opts)),
  167. matchRsltDigits = tmpBufSplit.length == 2 ? tmpBufSplit[1].match(opts.regex.integerNPart(opts)) : undefined;
  168. if (matchRslt && (matchRslt[0] == opts.negationSymbol.front + "0" || matchRslt[0] == opts.negationSymbol.front || matchRslt[0] == "+") && (matchRsltDigits == undefined || matchRsltDigits[0].match(/^0+$/))) {
  169. buffer.splice(matchRslt.index, 1);
  170. }
  171. var radixPosition = $.inArray(opts.radixPoint, buffer);
  172. if (radixPosition != -1 && isFinite(opts.digits) && !opts.digitsOptional) {
  173. for (var i = 1; i <= opts.digits; i++) {
  174. if (buffer[radixPosition + i] == undefined || buffer[radixPosition + i] == opts.placeholder.charAt(0)) buffer[radixPosition + i] = "0";
  175. }
  176. return { "refreshFromBuffer": true, "buffer": buffer };
  177. }
  178. }
  179. if (opts.autoGroup) {
  180. var rslt = opts.postFormat(buffer, caretPos - 1, true, opts);
  181. rslt.caret = caretPos <= opts.prefix.length ? rslt.pos : rslt.pos + 1;
  182. return rslt;
  183. }
  184. },
  185. regex: {
  186. integerPart: function (opts) { return new RegExp('[' + $.inputmask.escapeRegex(opts.negationSymbol.front) + '\+]?\\d+'); },
  187. integerNPart: function (opts) { return new RegExp('[\\d' + $.inputmask.escapeRegex(opts.groupSeparator) + ']+'); }
  188. },
  189. signHandler: function (chrs, maskset, pos, strict, opts) {
  190. if (!strict && (opts.allowMinus && chrs === "-") || (opts.allowPlus && chrs === "+")) {
  191. var matchRslt = maskset.buffer.join('').match(opts.regex.integerPart(opts));
  192. if (matchRslt && matchRslt[0].length > 0) {
  193. if (maskset.buffer[matchRslt.index] == (chrs === "-" ? "+" : opts.negationSymbol.front)) {
  194. if (chrs == "-") {
  195. if (opts.negationSymbol.back != "")
  196. return { "pos": matchRslt.index, "c": opts.negationSymbol.front, "remove": matchRslt.index, "caret": pos, "insert": { "pos": maskset["buffer"].length - opts.suffix.length - 1, "c": opts.negationSymbol.back } };
  197. else return { "pos": matchRslt.index, "c": opts.negationSymbol.front, "remove": matchRslt.index, "caret": pos };
  198. } else {
  199. if (opts.negationSymbol.back != "")
  200. return { "pos": matchRslt.index, "c": "+", "remove": [matchRslt.index, maskset["buffer"].length - opts.suffix.length - 1], "caret": pos };
  201. else return { "pos": matchRslt.index, "c": "+", "remove": matchRslt.index, "caret": pos };
  202. }
  203. } else if (maskset.buffer[matchRslt.index] == (chrs === "-" ? opts.negationSymbol.front : "+")) {
  204. if (chrs == "-" && opts.negationSymbol.back != "") {
  205. return { "remove": [matchRslt.index, maskset["buffer"].length - opts.suffix.length - 1], "caret": pos - 1 };
  206. } else {
  207. return { "remove": matchRslt.index, "caret": pos - 1 };
  208. }
  209. } else {
  210. if (chrs == "-") {
  211. if (opts.negationSymbol.back != "")
  212. return { "pos": matchRslt.index, "c": opts.negationSymbol.front, "caret": pos + 1, "insert": { "pos": maskset["buffer"].length - opts.suffix.length, "c": opts.negationSymbol.back } };
  213. else return { "pos": matchRslt.index, "c": opts.negationSymbol.front, "caret": pos + 1 };
  214. } else {
  215. return { "pos": matchRslt.index, "c": chrs, "caret": pos + 1 };
  216. }
  217. }
  218. }
  219. }
  220. return false;
  221. },
  222. radixHandler: function (chrs, maskset, pos, strict, opts) {
  223. if (!strict && chrs === opts.radixPoint && opts.digits > 0) {
  224. var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join('').match(opts.regex.integerPart(opts));
  225. if (radixPos != -1 && maskset["validPositions"][radixPos]) {
  226. if (maskset["validPositions"][radixPos - 1])
  227. return { "caret": radixPos + 1 };
  228. else return { "pos": integerValue.index, c: integerValue[0], "caret": radixPos + 1 };
  229. } else if (!integerValue || (integerValue["0"] == "0" && (integerValue.index + 1) != pos)) {
  230. maskset.buffer[integerValue ? integerValue.index : pos] = "0";
  231. return { "pos": (integerValue ? integerValue.index : pos) + 1 };
  232. }
  233. }
  234. return false;
  235. },
  236. leadingZeroHandler: function (chrs, maskset, pos, strict, opts) {
  237. var matchRslt = maskset.buffer.join('').match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  238. if (matchRslt && !strict && (radixPosition == -1 || pos <= radixPosition)) {
  239. if (matchRslt["0"].indexOf("0") == 0) {
  240. if (pos < opts.prefix.length) pos = matchRslt.index; //position
  241. var _radixPosition = $.inArray(opts.radixPoint, maskset._buffer);
  242. var digitsMatch = maskset._buffer && maskset.buffer.slice(radixPosition).join('') == maskset._buffer.slice(_radixPosition).join('') || parseInt(maskset.buffer.slice(radixPosition + 1).join('')) == 0;
  243. var integerMatch = maskset._buffer && maskset.buffer.slice(matchRslt.index, radixPosition).join('') == maskset._buffer.slice(opts.prefix.length, _radixPosition).join('') || maskset.buffer.slice(matchRslt.index, radixPosition).join('') == "0";
  244. if (radixPosition == -1 || digitsMatch && integerMatch) {
  245. maskset.buffer.splice(matchRslt.index, 1);
  246. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index;
  247. return { "pos": pos, "remove": matchRslt.index };
  248. } else if (matchRslt.index + 1 == pos || chrs == "0") {
  249. maskset.buffer.splice(matchRslt.index, 1);
  250. pos = matchRslt.index;
  251. return { "pos": pos, "remove": matchRslt.index };
  252. }
  253. } else if (chrs === "0" && pos <= matchRslt.index && matchRslt["0"] != opts.groupSeparator) {
  254. return false;
  255. }
  256. }
  257. return true;
  258. },
  259. postValidation: function (buffer, opts) {
  260. //handle maxvalue
  261. var isValid = true,
  262. maskedValue = buffer.join(''),
  263. processValue = maskedValue.replace(opts.prefix, "");
  264. processValue = processValue.replace(opts.suffix, "");
  265. processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  266. if (opts.radixPoint === ",") processValue = processValue.replace($.inputmask.escapeRegex(opts.radixPoint), ".");
  267. //handle negation symbol
  268. processValue = processValue.replace(new RegExp("^" + $.inputmask.escapeRegex(opts.negationSymbol.front)), "-");
  269. processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  270. if (isFinite(processValue)) {
  271. if (isFinite(opts.max)) {
  272. isValid = parseFloat(processValue) <= parseFloat(opts.max);
  273. }
  274. }
  275. return isValid;
  276. },
  277. definitions: {
  278. '~': {
  279. validator: function (chrs, maskset, pos, strict, opts) {
  280. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  281. if (!isValid) {
  282. isValid = opts.radixHandler(chrs, maskset, pos, strict, opts);
  283. if (!isValid) {
  284. isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
  285. if (isValid === true) {
  286. isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts);
  287. if (isValid === true) {
  288. //handle overwrite when fixed precision
  289. var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  290. if (opts.digitsOptional === false && pos > radixPosition && !strict) {
  291. isValid = { "pos": pos, "remove": pos };
  292. } else isValid = { pos: pos };
  293. }
  294. }
  295. }
  296. }
  297. return isValid;
  298. },
  299. cardinality: 1,
  300. prevalidator: null
  301. },
  302. '+': {
  303. validator: function (chrs, maskset, pos, strict, opts) {
  304. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts), nbl;
  305. if (!isValid && ((strict && opts.allowMinus && chrs === opts.negationSymbol.front) || (opts.allowMinus && chrs == "-") || (opts.allowPlus && chrs == "+"))) {
  306. if (chrs == "-") {
  307. if (opts.negationSymbol.back != "")
  308. isValid = { "pos": pos, "c": chrs === "-" ? opts.negationSymbol.front : "+", "caret": pos + 1, "insert": { "pos": maskset["buffer"].length, "c": opts.negationSymbol.back } };
  309. else isValid = { "pos": pos, "c": chrs === "-" ? opts.negationSymbol.front : "+", "caret": pos + 1 };
  310. } else {
  311. isValid = true;
  312. }
  313. }
  314. return isValid;
  315. },
  316. cardinality: 1,
  317. prevalidator: null,
  318. placeholder: ''
  319. },
  320. '-': {
  321. validator: function (chrs, maskset, pos, strict, opts) {
  322. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  323. if (!isValid && strict && opts.allowMinus && chrs === opts.negationSymbol.back) {
  324. isValid = true;
  325. }
  326. return isValid;
  327. },
  328. cardinality: 1,
  329. prevalidator: null,
  330. placeholder: ''
  331. },
  332. ':': {
  333. validator: function (chrs, maskset, pos, strict, opts) {
  334. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  335. if (!isValid) {
  336. var radix = "[" + $.inputmask.escapeRegex(opts.radixPoint) + "]";
  337. isValid = new RegExp(radix).test(chrs);
  338. if (isValid && maskset["validPositions"][pos] && maskset["validPositions"][pos]["match"].placeholder == opts.radixPoint) {
  339. isValid = { "caret": pos + 1 };
  340. }
  341. }
  342. return isValid;
  343. },
  344. cardinality: 1,
  345. prevalidator: null,
  346. placeholder: function (opts) { return opts.radixPoint; }
  347. }
  348. },
  349. insertMode: true,
  350. autoUnmask: false,
  351. unmaskAsNumber: false,
  352. onUnMask: function (maskedValue, unmaskedValue, opts) {
  353. var processValue = maskedValue.replace(opts.prefix, "");
  354. processValue = processValue.replace(opts.suffix, "");
  355. processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  356. if (opts.unmaskAsNumber) {
  357. processValue = processValue.replace($.inputmask.escapeRegex.call(this, opts.radixPoint), ".");
  358. return Number(processValue);
  359. }
  360. return processValue;
  361. },
  362. isComplete: function (buffer, opts) {
  363. var maskedValue = buffer.join(''), bufClone = buffer.slice();
  364. //verify separator positions
  365. opts.postFormat(bufClone, 0, true, opts);
  366. if (bufClone.join('') != maskedValue) return false;
  367. var processValue = maskedValue.replace(opts.prefix, "");
  368. processValue = processValue.replace(opts.suffix, "");
  369. processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  370. if (opts.radixPoint === ",") processValue = processValue.replace($.inputmask.escapeRegex(opts.radixPoint), ".");
  371. return isFinite(processValue);
  372. },
  373. onBeforeMask: function (initialValue, opts) {
  374. if (opts.radixPoint != "" && isFinite(initialValue)) {
  375. initialValue = initialValue.toString().replace(".", opts.radixPoint);
  376. } else {
  377. var kommaMatches = initialValue.match(/,/g);
  378. var dotMatches = initialValue.match(/\./g);
  379. if (dotMatches && kommaMatches) {
  380. if (dotMatches.length > kommaMatches.length) {
  381. initialValue = initialValue.replace(/\./g, "");
  382. initialValue = initialValue.replace(",", opts.radixPoint);
  383. } else if (kommaMatches.length > dotMatches.length) {
  384. initialValue = initialValue.replace(/,/g, "");
  385. initialValue = initialValue.replace(".", opts.radixPoint);
  386. } else { //equal
  387. initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "");
  388. }
  389. } else {
  390. initialValue = initialValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  391. }
  392. }
  393. if (opts.digits == 0) {
  394. if (initialValue.indexOf(".") != -1) {
  395. initialValue = initialValue.substring(0, initialValue.indexOf("."));
  396. } else if (initialValue.indexOf(",") != -1) {
  397. initialValue = initialValue.substring(0, initialValue.indexOf(","));
  398. }
  399. }
  400. return initialValue;
  401. },
  402. canClearPosition: function (maskset, position, lvp, strict, opts) {
  403. var positionInput = maskset["validPositions"][position].input,
  404. canClear = (positionInput != opts.radixPoint && isFinite(positionInput)) ||
  405. position == lvp ||
  406. positionInput == opts.groupSeparator ||
  407. positionInput == opts.negationSymbol.front ||
  408. positionInput == opts.negationSymbol.back,
  409. posOffset = 0;
  410. if (canClear && isFinite(positionInput)) {
  411. var matchRslt
  412. if (!strict && maskset["buffer"]) {
  413. matchRslt = maskset["buffer"].join('').substr(0, position).match(opts.regex.integerNPart(opts));
  414. var pos = position + 1, isNull = matchRslt == null || parseInt(matchRslt["0"].replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), "")) == 0;
  415. if (isNull) {
  416. while (maskset["validPositions"][pos] && (maskset["validPositions"][pos].input == opts.groupSeparator || maskset["validPositions"][pos].input == "0")) {
  417. delete maskset["validPositions"][pos];
  418. pos++;
  419. }
  420. }
  421. }
  422. var buffer = [];
  423. //build new buffer from validPositions
  424. for (var vp in maskset.validPositions) {
  425. buffer.push(maskset.validPositions[vp].input);
  426. }
  427. matchRslt = buffer.join('').match(opts.regex.integerNPart(opts));
  428. var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  429. if (matchRslt && (radixPosition == -1 || position <= radixPosition)) {
  430. if (matchRslt["0"].indexOf("0") == 0) {
  431. canClear = matchRslt.index != position || radixPosition == -1;
  432. } else {
  433. var intPart = parseInt(matchRslt["0"].replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), ""));
  434. if (radixPosition != -1 && intPart < 10 /*&& opts.placeholder.charAt(0) == "0"*/) {
  435. maskset["validPositions"][position].input = "0";
  436. maskset["p"] = opts.prefix.length + 1;
  437. canClear = false;
  438. }
  439. }
  440. }
  441. }
  442. return canClear;
  443. }
  444. },
  445. 'currency': {
  446. prefix: "$ ",
  447. groupSeparator: ",",
  448. alias: "numeric",
  449. placeholder: "0",
  450. autoGroup: true,
  451. digits: 2,
  452. digitsOptional: false,
  453. clearMaskOnLostFocus: false
  454. },
  455. 'decimal': {
  456. alias: "numeric"
  457. },
  458. 'integer': {
  459. alias: "numeric",
  460. digits: "0",
  461. radixPoint: ""
  462. }
  463. });
  464. return $.fn.inputmask;
  465. })(jQuery);