jquery.inputmask.numeric.extensions.js 27 KB

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