inputmask.date.extensions.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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 (factory) {
  10. if (typeof define === "function" && define.amd) {
  11. define(["./dependencyLibs/inputmask.dependencyLib", "./inputmask"], factory);
  12. } else if (typeof exports === "object") {
  13. module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./inputmask"));
  14. } else {
  15. factory(window.dependencyLib || jQuery, window.Inputmask);
  16. }
  17. }
  18. (function ($, Inputmask) {
  19. function isLeapYear(year) {
  20. return isNaN(year) || new Date(year, 2, 0).getDate() === 29;
  21. }
  22. Inputmask.extendAliases({
  23. "dd/mm/yyyy": {
  24. mask: "1/2/y",
  25. placeholder: "dd/mm/yyyy",
  26. regex: {
  27. val1pre: new RegExp("[0-3]"), //daypre
  28. val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), //day
  29. val2pre: function (separator) {
  30. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  31. return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])");
  32. }, //monthpre
  33. val2: function (separator) {
  34. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  35. return new RegExp("((0[1-9]|[12][0-9])" + escapedSeparator + "(0[1-9]|1[012]))|(30" + escapedSeparator + "(0[13-9]|1[012]))|(31" + escapedSeparator + "(0[13578]|1[02]))");
  36. } //month
  37. },
  38. leapday: "29/02/",
  39. separator: "/",
  40. yearrange: {
  41. minyear: 1900,
  42. maxyear: 2099
  43. },
  44. isInYearRange: function (chrs, minyear, maxyear) {
  45. if (isNaN(chrs)) return false;
  46. var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length)));
  47. var enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
  48. return (!isNaN(enteredyear) ? minyear <= enteredyear && enteredyear <= maxyear : false) ||
  49. (!isNaN(enteredyear2) ? minyear <= enteredyear2 && enteredyear2 <= maxyear : false);
  50. },
  51. determinebaseyear: function (minyear, maxyear, hint) {
  52. var currentyear = (new Date()).getFullYear();
  53. if (minyear > currentyear) return minyear;
  54. if (maxyear < currentyear) {
  55. var maxYearPrefix = maxyear.toString().slice(0, 2);
  56. var maxYearPostfix = maxyear.toString().slice(2, 4);
  57. while (maxyear < maxYearPrefix + hint) {
  58. maxYearPrefix--;
  59. }
  60. var maxxYear = maxYearPrefix + maxYearPostfix;
  61. return minyear > maxxYear ? minyear : maxxYear;
  62. }
  63. if (minyear <= currentyear && currentyear <= maxyear) {
  64. var currentYearPrefix = currentyear.toString().slice(0, 2);
  65. while (maxyear < currentYearPrefix + hint) {
  66. currentYearPrefix--;
  67. }
  68. var currentYearAndHint = currentYearPrefix + hint;
  69. return currentYearAndHint < minyear ? minyear : currentYearAndHint;
  70. }
  71. return currentyear;
  72. },
  73. onKeyDown: function (e, buffer, caretPos, opts) {
  74. var $input = $(this);
  75. if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
  76. var today = new Date();
  77. $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString());
  78. $input.trigger("setvalue");
  79. }
  80. },
  81. getFrontValue: function (mask, buffer, opts) {
  82. var start = 0,
  83. length = 0;
  84. for (var i = 0; i < mask.length; i++) {
  85. if (mask.charAt(i) === "2") break;
  86. var definition = opts.definitions[mask.charAt(i)];
  87. if (definition) {
  88. start += length;
  89. length = definition.cardinality;
  90. } else length++;
  91. }
  92. return buffer.join("").substr(start, length);
  93. },
  94. postValidation: function (buffer, currentResult, opts) {
  95. var dayMonthValue, year, bufferStr = buffer.join("");
  96. if (opts.mask.indexOf("y") === 0) {
  97. year = bufferStr.substr(0, 4);
  98. dayMonthValue = bufferStr.substring(4, 10);
  99. } else {
  100. year = bufferStr.substring(6, 10);
  101. dayMonthValue = bufferStr.substr(0, 6);
  102. }
  103. return currentResult && (dayMonthValue !== opts.leapday ? true : isLeapYear(year));
  104. },
  105. definitions: {
  106. "1": { //val1 ~ day or month
  107. validator: function (chrs, maskset, pos, strict, opts) {
  108. var isValid = opts.regex.val1.test(chrs);
  109. if (!strict && !isValid) {
  110. if (chrs.charAt(1) === opts.separator || "-./".indexOf(chrs.charAt(1)) !== -1) {
  111. isValid = opts.regex.val1.test("0" + chrs.charAt(0));
  112. if (isValid) {
  113. maskset.buffer[pos - 1] = "0";
  114. return {
  115. "refreshFromBuffer": {
  116. start: pos - 1,
  117. end: pos
  118. },
  119. "pos": pos,
  120. "c": chrs.charAt(0)
  121. };
  122. }
  123. }
  124. }
  125. return isValid;
  126. },
  127. cardinality: 2,
  128. prevalidator: [{
  129. validator: function (chrs, maskset, pos, strict, opts) {
  130. var pchrs = chrs;
  131. if (!isNaN(maskset.buffer[pos + 1])) pchrs += maskset.buffer[pos + 1];
  132. var isValid = pchrs.length === 1 ? opts.regex.val1pre.test(pchrs) : opts.regex.val1.test(pchrs);
  133. if (isValid && maskset.validPositions[pos]) { //check if total is valid if defined
  134. if (!opts.regex.val2(opts.separator).test(chrs + maskset.validPositions[pos].input)) {
  135. maskset.validPositions[pos].input = (chrs === "0" ? "1" : "0");
  136. }
  137. }
  138. if (!strict && !isValid) {
  139. isValid = opts.regex.val1.test(chrs + "0");
  140. if (isValid) {
  141. maskset.buffer[pos] = chrs;
  142. maskset.buffer[++pos] = "0";
  143. return {
  144. "pos": pos,
  145. "c": "0"
  146. };
  147. }
  148. isValid = opts.regex.val1.test("0" + chrs);
  149. if (isValid) {
  150. maskset.buffer[pos] = "0";
  151. pos++;
  152. return {
  153. "pos": pos
  154. };
  155. }
  156. }
  157. return isValid;
  158. },
  159. cardinality: 1
  160. }]
  161. },
  162. "2": { //val2 ~ day or month
  163. validator: function (chrs, maskset, pos, strict, opts) {
  164. var frontValue = opts.getFrontValue(maskset.mask, maskset.buffer, opts);
  165. if (frontValue.indexOf(opts.placeholder[0]) !== -1) frontValue = "01" + opts.separator;
  166. var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
  167. if (!strict && !isValid) {
  168. if (chrs.charAt(1) === opts.separator || "-./".indexOf(chrs.charAt(1)) !== -1) {
  169. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
  170. if (isValid) {
  171. maskset.buffer[pos - 1] = "0";
  172. return {
  173. "refreshFromBuffer": {
  174. start: pos - 1,
  175. end: pos
  176. },
  177. "pos": pos,
  178. "c": chrs.charAt(0)
  179. };
  180. }
  181. }
  182. }
  183. return isValid;
  184. },
  185. cardinality: 2,
  186. prevalidator: [{
  187. validator: function (chrs, maskset, pos, strict, opts) {
  188. if (!isNaN(maskset.buffer[pos + 1])) chrs += maskset.buffer[pos + 1];
  189. var frontValue = opts.getFrontValue(maskset.mask, maskset.buffer, opts);
  190. if (frontValue.indexOf(opts.placeholder[0]) !== -1) frontValue = "01" + opts.separator;
  191. var isValid = chrs.length === 1 ? opts.regex.val2pre(opts.separator).test(frontValue + chrs) : opts.regex.val2(opts.separator).test(frontValue + chrs);
  192. if (isValid && maskset.validPositions[pos]) { //check if total is valid if defined
  193. if (!opts.regex.val2(opts.separator).test(chrs + maskset.validPositions[pos].input)) {
  194. maskset.validPositions[pos].input = (chrs === "0" ? "1" : "0");
  195. }
  196. }
  197. if (!strict && !isValid) {
  198. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
  199. if (isValid) {
  200. maskset.buffer[pos] = "0";
  201. pos++;
  202. return {
  203. "pos": pos
  204. };
  205. }
  206. }
  207. return isValid;
  208. },
  209. cardinality: 1
  210. }]
  211. },
  212. "y": { //year
  213. validator: function (chrs, maskset, pos, strict, opts) {
  214. return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  215. },
  216. cardinality: 4,
  217. prevalidator: [{
  218. validator: function (chrs, maskset, pos, strict, opts) {
  219. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  220. if (!strict && !isValid) {
  221. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 1);
  222. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  223. if (isValid) {
  224. maskset.buffer[pos++] = yearPrefix.charAt(0);
  225. return {
  226. "pos": pos
  227. };
  228. }
  229. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 2);
  230. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  231. if (isValid) {
  232. maskset.buffer[pos++] = yearPrefix.charAt(0);
  233. maskset.buffer[pos++] = yearPrefix.charAt(1);
  234. return {
  235. "pos": pos
  236. };
  237. }
  238. }
  239. return isValid;
  240. },
  241. cardinality: 1
  242. }, {
  243. validator: function (chrs, maskset, pos, strict, opts) {
  244. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  245. if (!strict && !isValid) {
  246. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  247. isValid = opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear);
  248. if (isValid) {
  249. maskset.buffer[pos++] = yearPrefix.charAt(1);
  250. return {
  251. "pos": pos
  252. };
  253. }
  254. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  255. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  256. if (isValid) {
  257. maskset.buffer[pos - 1] = yearPrefix.charAt(0);
  258. maskset.buffer[pos++] = yearPrefix.charAt(1);
  259. maskset.buffer[pos++] = chrs.charAt(0);
  260. return {
  261. "refreshFromBuffer": {
  262. start: pos - 3,
  263. end: pos
  264. },
  265. "pos": pos
  266. };
  267. }
  268. }
  269. return isValid;
  270. },
  271. cardinality: 2
  272. }, {
  273. validator: function (chrs, maskset, pos, strict, opts) {
  274. return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  275. },
  276. cardinality: 3
  277. }]
  278. }
  279. },
  280. insertMode: false,
  281. autoUnmask: false
  282. },
  283. "mm/dd/yyyy": {
  284. placeholder: "mm/dd/yyyy",
  285. alias: "dd/mm/yyyy", //reuse functionality of dd/mm/yyyy alias
  286. regex: {
  287. val2pre: function (separator) {
  288. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  289. return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])");
  290. }
  291. , //daypre
  292. val2: function (separator) {
  293. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  294. return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[13-9]|1[012])" + escapedSeparator + "30)|((0[13578]|1[02])" + escapedSeparator + "31)");
  295. }
  296. , //day
  297. val1pre: new RegExp("[01]"), //monthpre
  298. val1: new RegExp("0[1-9]|1[012]") //month
  299. }
  300. ,
  301. leapday: "02/29/",
  302. onKeyDown: function (e, buffer, caretPos, opts) {
  303. var $input = $(this);
  304. if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
  305. var today = new Date();
  306. $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
  307. $input.trigger("setvalue");
  308. }
  309. }
  310. }
  311. ,
  312. "yyyy/mm/dd": {
  313. mask: "y/1/2",
  314. placeholder: "yyyy/mm/dd",
  315. alias: "mm/dd/yyyy",
  316. leapday: "/02/29",
  317. onKeyDown: function (e, buffer, caretPos, opts) {
  318. var $input = $(this);
  319. if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
  320. var today = new Date();
  321. $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString());
  322. $input.trigger("setvalue");
  323. }
  324. }
  325. }
  326. ,
  327. "dd.mm.yyyy": {
  328. mask: "1.2.y",
  329. placeholder: "dd.mm.yyyy",
  330. leapday: "29.02.",
  331. separator: ".",
  332. alias: "dd/mm/yyyy"
  333. }
  334. ,
  335. "dd-mm-yyyy": {
  336. mask: "1-2-y",
  337. placeholder: "dd-mm-yyyy",
  338. leapday: "29-02-",
  339. separator: "-",
  340. alias: "dd/mm/yyyy"
  341. }
  342. ,
  343. "mm.dd.yyyy": {
  344. mask: "1.2.y",
  345. placeholder: "mm.dd.yyyy",
  346. leapday: "02.29.",
  347. separator: ".",
  348. alias: "mm/dd/yyyy"
  349. }
  350. ,
  351. "mm-dd-yyyy": {
  352. mask: "1-2-y",
  353. placeholder: "mm-dd-yyyy",
  354. leapday: "02-29-",
  355. separator: "-",
  356. alias: "mm/dd/yyyy"
  357. }
  358. ,
  359. "yyyy.mm.dd": {
  360. mask: "y.1.2",
  361. placeholder: "yyyy.mm.dd",
  362. leapday: ".02.29",
  363. separator: ".",
  364. alias: "yyyy/mm/dd"
  365. }
  366. ,
  367. "yyyy-mm-dd": {
  368. mask: "y-1-2",
  369. placeholder: "yyyy-mm-dd",
  370. leapday: "-02-29",
  371. separator: "-",
  372. alias: "yyyy/mm/dd"
  373. }
  374. ,
  375. "datetime": {
  376. mask: "1/2/y h:s",
  377. placeholder: "dd/mm/yyyy hh:mm",
  378. alias: "dd/mm/yyyy",
  379. regex: {
  380. hrspre: new RegExp("[012]"), //hours pre
  381. hrs24: new RegExp("2[0-4]|1[3-9]"),
  382. hrs: new RegExp("[01][0-9]|2[0-4]"), //hours
  383. ampm: new RegExp("^[a|p|A|P][m|M]"),
  384. mspre: new RegExp("[0-5]"), //minutes/seconds pre
  385. ms: new RegExp("[0-5][0-9]")
  386. }
  387. ,
  388. timeseparator: ":",
  389. hourFormat: "24", // or 12
  390. definitions: {
  391. "h": { //hours
  392. validator: function (chrs, maskset, pos, strict, opts) {
  393. if (opts.hourFormat === "24") {
  394. if (parseInt(chrs, 10) === 24) {
  395. maskset.buffer[pos - 1] = "0";
  396. maskset.buffer[pos] = "0";
  397. return {
  398. "refreshFromBuffer": {
  399. start: pos - 1,
  400. end: pos
  401. },
  402. "c": "0"
  403. };
  404. }
  405. }
  406. var isValid = opts.regex.hrs.test(chrs);
  407. if (!strict && !isValid) {
  408. if (chrs.charAt(1) === opts.timeseparator || "-.:".indexOf(chrs.charAt(1)) !== -1) {
  409. isValid = opts.regex.hrs.test("0" + chrs.charAt(0));
  410. if (isValid) {
  411. maskset.buffer[pos - 1] = "0";
  412. maskset.buffer[pos] = chrs.charAt(0);
  413. pos++;
  414. return {
  415. "refreshFromBuffer": {
  416. start: pos - 2,
  417. end: pos
  418. },
  419. "pos": pos,
  420. "c": opts.timeseparator
  421. };
  422. }
  423. }
  424. }
  425. if (isValid && opts.hourFormat !== "24" && opts.regex.hrs24.test(chrs)) {
  426. var tmp = parseInt(chrs, 10);
  427. if (tmp === 24) {
  428. maskset.buffer[pos + 5] = "a";
  429. maskset.buffer[pos + 6] = "m";
  430. } else {
  431. maskset.buffer[pos + 5] = "p";
  432. maskset.buffer[pos + 6] = "m";
  433. }
  434. tmp = tmp - 12;
  435. if (tmp < 10) {
  436. maskset.buffer[pos] = tmp.toString();
  437. maskset.buffer[pos - 1] = "0";
  438. } else {
  439. maskset.buffer[pos] = tmp.toString().charAt(1);
  440. maskset.buffer[pos - 1] = tmp.toString().charAt(0);
  441. }
  442. return {
  443. "refreshFromBuffer": {
  444. start: pos - 1,
  445. end: pos + 6
  446. },
  447. "c": maskset.buffer[pos]
  448. };
  449. }
  450. return isValid;
  451. }
  452. ,
  453. cardinality: 2,
  454. prevalidator: [{
  455. validator: function (chrs, maskset, pos, strict, opts) {
  456. var isValid = opts.regex.hrspre.test(chrs);
  457. if (!strict && !isValid) {
  458. isValid = opts.regex.hrs.test("0" + chrs);
  459. if (isValid) {
  460. maskset.buffer[pos] = "0";
  461. pos++;
  462. return {
  463. "pos": pos
  464. };
  465. }
  466. }
  467. return isValid;
  468. },
  469. cardinality: 1
  470. }]
  471. }
  472. ,
  473. "s": { //seconds || minutes
  474. validator: "[0-5][0-9]",
  475. cardinality: 2,
  476. prevalidator: [{
  477. validator: function (chrs, maskset, pos, strict, opts) {
  478. var isValid = opts.regex.mspre.test(chrs);
  479. if (!strict && !isValid) {
  480. isValid = opts.regex.ms.test("0" + chrs);
  481. if (isValid) {
  482. maskset.buffer[pos] = "0";
  483. pos++;
  484. return {
  485. "pos": pos
  486. };
  487. }
  488. }
  489. return isValid;
  490. },
  491. cardinality: 1
  492. }]
  493. }
  494. ,
  495. "t": { //am/pm
  496. validator: function (chrs, maskset, pos, strict, opts) {
  497. return opts.regex.ampm.test(chrs + "m");
  498. }
  499. ,
  500. casing: "lower",
  501. cardinality: 1
  502. }
  503. }
  504. ,
  505. insertMode: false,
  506. autoUnmask: false
  507. }
  508. ,
  509. "datetime12": {
  510. mask: "1/2/y h:s t\\m",
  511. placeholder: "dd/mm/yyyy hh:mm xm",
  512. alias: "datetime",
  513. hourFormat: "12"
  514. }
  515. ,
  516. "mm/dd/yyyy hh:mm xm": {
  517. mask: "1/2/y h:s t\\m",
  518. placeholder: "mm/dd/yyyy hh:mm xm",
  519. alias: "datetime12",
  520. regex: {
  521. val2pre: function (separator) {
  522. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  523. return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])");
  524. }
  525. ,
  526. val2: function (separator) {
  527. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  528. return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[13-9]|1[012])" + escapedSeparator + "30)|((0[13578]|1[02])" + escapedSeparator + "31)");
  529. }
  530. ,
  531. val1pre: new RegExp("[01]"),
  532. val1: new RegExp("0[1-9]|1[012]")
  533. }
  534. ,
  535. leapday: "02/29/",
  536. onKeyDown: function (e, buffer, caretPos, opts) {
  537. var $input = $(this);
  538. if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
  539. var today = new Date();
  540. $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
  541. $input.trigger("setvalue");
  542. }
  543. }
  544. }
  545. ,
  546. "hh:mm t": {
  547. mask: "h:s t\\m",
  548. placeholder: "hh:mm xm",
  549. alias: "datetime",
  550. hourFormat: "12"
  551. }
  552. ,
  553. "h:s t": {
  554. mask: "h:s t\\m",
  555. placeholder: "hh:mm xm",
  556. alias: "datetime",
  557. hourFormat: "12"
  558. }
  559. ,
  560. "hh:mm:ss": {
  561. mask: "h:s:s",
  562. placeholder: "hh:mm:ss",
  563. alias: "datetime",
  564. autoUnmask: false
  565. }
  566. ,
  567. "hh:mm": {
  568. mask: "h:s",
  569. placeholder: "hh:mm",
  570. alias: "datetime",
  571. autoUnmask: false
  572. }
  573. ,
  574. "date": {
  575. alias: "dd/mm/yyyy" // "mm/dd/yyyy"
  576. }
  577. ,
  578. "mm/yyyy": {
  579. mask: "1/y",
  580. placeholder: "mm/yyyy",
  581. leapday: "donotuse",
  582. separator: "/",
  583. alias: "mm/dd/yyyy"
  584. }
  585. ,
  586. "shamsi": {
  587. regex: {
  588. val2pre: function (separator) {
  589. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  590. return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "[0-3])");
  591. }
  592. ,
  593. val2: function (separator) {
  594. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  595. return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[1-9]|1[012])" + escapedSeparator + "30)|((0[1-6])" + escapedSeparator + "31)");
  596. }
  597. ,
  598. val1pre: new RegExp("[01]"),
  599. val1: new RegExp("0[1-9]|1[012]")
  600. }
  601. ,
  602. yearrange: {
  603. minyear: 1300,
  604. maxyear: 1499
  605. }
  606. ,
  607. mask: "y/1/2",
  608. leapday: "/12/30",
  609. placeholder: "yyyy/mm/dd",
  610. alias: "mm/dd/yyyy",
  611. clearIncomplete: true
  612. },
  613. "yyyy-mm-dd hh:mm:ss": {
  614. mask: "y-1-2 h:s:s",
  615. placeholder: "yyyy-mm-dd hh:mm:ss",
  616. alias: "datetime",
  617. separator: "-",
  618. leapday: "-02-29",
  619. regex: {
  620. val2pre: function (separator) {
  621. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  622. return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])");
  623. }, //daypre
  624. val2: function (separator) {
  625. var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
  626. return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[13-9]|1[012])" + escapedSeparator + "30)|((0[13578]|1[02])" + escapedSeparator + "31)");
  627. }, //day
  628. val1pre: new RegExp("[01]"), //monthpre
  629. val1: new RegExp("0[1-9]|1[012]") //month
  630. },
  631. onKeyDown: function (e, buffer, caretPos, opts) {
  632. }
  633. }
  634. });
  635. return Inputmask;
  636. }));