jquery.inputmask.numeric.extensions.js 27 KB

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