123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- /*!
- * inputmask.date.extensions.js
- * https://github.com/RobinHerbots/jquery.inputmask
- * Copyright (c) 2010 - 2016 Robin Herbots
- * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
- * Version: 3.3.1
- */
- !function(factory) {
- "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);
- }(function($, Inputmask) {
- return Inputmask.extendDefinitions({
- h: {
- validator: "[01][0-9]|2[0-3]",
- cardinality: 2,
- prevalidator: [ {
- validator: "[0-2]",
- cardinality: 1
- } ]
- },
- s: {
- validator: "[0-5][0-9]",
- cardinality: 2,
- prevalidator: [ {
- validator: "[0-5]",
- cardinality: 1
- } ]
- },
- d: {
- validator: "0[1-9]|[12][0-9]|3[01]",
- cardinality: 2,
- prevalidator: [ {
- validator: "[0-3]",
- cardinality: 1
- } ]
- },
- m: {
- validator: "0[1-9]|1[012]",
- cardinality: 2,
- prevalidator: [ {
- validator: "[01]",
- cardinality: 1
- } ]
- },
- y: {
- validator: "(19|20)\\d{2}",
- cardinality: 4,
- prevalidator: [ {
- validator: "[12]",
- cardinality: 1
- }, {
- validator: "(19|20)",
- cardinality: 2
- }, {
- validator: "(19|20)\\d",
- cardinality: 3
- } ]
- }
- }), Inputmask.extendAliases({
- "dd/mm/yyyy": {
- mask: "1/2/y",
- placeholder: "dd/mm/yyyy",
- regex: {
- val1pre: new RegExp("[0-3]"),
- val1: new RegExp("0[1-9]|[12][0-9]|3[01]"),
- val2pre: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])");
- },
- val2: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- 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]))");
- }
- },
- leapday: "29/02/",
- separator: "/",
- yearrange: {
- minyear: 1900,
- maxyear: 2099
- },
- isInYearRange: function(chrs, minyear, maxyear) {
- if (isNaN(chrs)) return !1;
- var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length))), enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
- return (isNaN(enteredyear) ? !1 : enteredyear >= minyear && maxyear >= enteredyear) || (isNaN(enteredyear2) ? !1 : enteredyear2 >= minyear && maxyear >= enteredyear2);
- },
- determinebaseyear: function(minyear, maxyear, hint) {
- var currentyear = new Date().getFullYear();
- if (minyear > currentyear) return minyear;
- if (currentyear > maxyear) {
- for (var maxYearPrefix = maxyear.toString().slice(0, 2), maxYearPostfix = maxyear.toString().slice(2, 4); maxYearPrefix + hint > maxyear; ) maxYearPrefix--;
- var maxxYear = maxYearPrefix + maxYearPostfix;
- return minyear > maxxYear ? minyear : maxxYear;
- }
- if (currentyear >= minyear && maxyear >= currentyear) {
- for (var currentYearPrefix = currentyear.toString().slice(0, 2); currentYearPrefix + hint > maxyear; ) currentYearPrefix--;
- var currentYearAndHint = currentYearPrefix + hint;
- return minyear > currentYearAndHint ? minyear : currentYearAndHint;
- }
- return currentyear;
- },
- onKeyDown: function(e, buffer, caretPos, opts) {
- var $input = $(this);
- if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
- var today = new Date();
- $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString()),
- $input.trigger("setvalue");
- }
- },
- getFrontValue: function(mask, buffer, opts) {
- for (var start = 0, length = 0, i = 0; i < mask.length && "2" !== mask.charAt(i); i++) {
- var definition = opts.definitions[mask.charAt(i)];
- definition ? (start += length, length = definition.cardinality) : length++;
- }
- return buffer.join("").substr(start, length);
- },
- definitions: {
- "1": {
- validator: function(chrs, maskset, pos, strict, opts) {
- var isValid = opts.regex.val1.test(chrs);
- return strict || isValid || chrs.charAt(1) !== opts.separator && -1 === "-./".indexOf(chrs.charAt(1)) || !(isValid = opts.regex.val1.test("0" + chrs.charAt(0))) ? isValid : (maskset.buffer[pos - 1] = "0",
- {
- refreshFromBuffer: {
- start: pos - 1,
- end: pos
- },
- pos: pos,
- c: chrs.charAt(0)
- });
- },
- cardinality: 2,
- prevalidator: [ {
- validator: function(chrs, maskset, pos, strict, opts) {
- var pchrs = chrs;
- isNaN(maskset.buffer[pos + 1]) || (pchrs += maskset.buffer[pos + 1]);
- var isValid = 1 === pchrs.length ? opts.regex.val1pre.test(pchrs) : opts.regex.val1.test(pchrs);
- if (!strict && !isValid) {
- if (isValid = opts.regex.val1.test(chrs + "0")) return maskset.buffer[pos] = chrs,
- maskset.buffer[++pos] = "0", {
- pos: pos,
- c: "0"
- };
- if (isValid = opts.regex.val1.test("0" + chrs)) return maskset.buffer[pos] = "0",
- pos++, {
- pos: pos
- };
- }
- return isValid;
- },
- cardinality: 1
- } ]
- },
- "2": {
- validator: function(chrs, maskset, pos, strict, opts) {
- var frontValue = opts.getFrontValue(maskset.mask, maskset.buffer, opts);
- -1 !== frontValue.indexOf(opts.placeholder[0]) && (frontValue = "01" + opts.separator);
- var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
- if (!strict && !isValid && (chrs.charAt(1) === opts.separator || -1 !== "-./".indexOf(chrs.charAt(1))) && (isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0)))) return maskset.buffer[pos - 1] = "0",
- {
- refreshFromBuffer: {
- start: pos - 1,
- end: pos
- },
- pos: pos,
- c: chrs.charAt(0)
- };
- if (opts.mask.indexOf("2") === opts.mask.length - 1 && isValid) {
- var dayMonthValue = maskset.buffer.join("").substr(4, 4) + chrs;
- if (dayMonthValue !== opts.leapday) return !0;
- var year = parseInt(maskset.buffer.join("").substr(0, 4), 10);
- return year % 4 === 0 ? year % 100 === 0 ? year % 400 === 0 ? !0 : !1 : !0 : !1;
- }
- return isValid;
- },
- cardinality: 2,
- prevalidator: [ {
- validator: function(chrs, maskset, pos, strict, opts) {
- isNaN(maskset.buffer[pos + 1]) || (chrs += maskset.buffer[pos + 1]);
- var frontValue = opts.getFrontValue(maskset.mask, maskset.buffer, opts);
- -1 !== frontValue.indexOf(opts.placeholder[0]) && (frontValue = "01" + opts.separator);
- var isValid = 1 === chrs.length ? opts.regex.val2pre(opts.separator).test(frontValue + chrs) : opts.regex.val2(opts.separator).test(frontValue + chrs);
- return strict || isValid || !(isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs)) ? isValid : (maskset.buffer[pos] = "0",
- pos++, {
- pos: pos
- });
- },
- cardinality: 1
- } ]
- },
- y: {
- validator: function(chrs, maskset, pos, strict, opts) {
- if (opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
- var dayMonthValue = maskset.buffer.join("").substr(0, 6);
- if (dayMonthValue !== opts.leapday) return !0;
- var year = parseInt(chrs, 10);
- return year % 4 === 0 ? year % 100 === 0 ? year % 400 === 0 ? !0 : !1 : !0 : !1;
- }
- return !1;
- },
- cardinality: 4,
- prevalidator: [ {
- validator: function(chrs, maskset, pos, strict, opts) {
- var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
- if (!strict && !isValid) {
- var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 1);
- if (isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) return maskset.buffer[pos++] = yearPrefix.charAt(0),
- {
- pos: pos
- };
- if (yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 2),
- isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) return maskset.buffer[pos++] = yearPrefix.charAt(0),
- maskset.buffer[pos++] = yearPrefix.charAt(1), {
- pos: pos
- };
- }
- return isValid;
- },
- cardinality: 1
- }, {
- validator: function(chrs, maskset, pos, strict, opts) {
- var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
- if (!strict && !isValid) {
- var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
- if (isValid = opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear)) return maskset.buffer[pos++] = yearPrefix.charAt(1),
- {
- pos: pos
- };
- if (yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2),
- opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
- var dayMonthValue = maskset.buffer.join("").substr(0, 6);
- if (dayMonthValue !== opts.leapday) isValid = !0; else {
- var year = parseInt(chrs, 10);
- isValid = year % 4 === 0 ? year % 100 === 0 ? year % 400 === 0 ? !0 : !1 : !0 : !1;
- }
- } else isValid = !1;
- if (isValid) return maskset.buffer[pos - 1] = yearPrefix.charAt(0), maskset.buffer[pos++] = yearPrefix.charAt(1),
- maskset.buffer[pos++] = chrs.charAt(0), {
- refreshFromBuffer: {
- start: pos - 3,
- end: pos
- },
- pos: pos
- };
- }
- return isValid;
- },
- cardinality: 2
- }, {
- validator: function(chrs, maskset, pos, strict, opts) {
- return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
- },
- cardinality: 3
- } ]
- }
- },
- insertMode: !1,
- autoUnmask: !1
- },
- "mm/dd/yyyy": {
- placeholder: "mm/dd/yyyy",
- alias: "dd/mm/yyyy",
- regex: {
- val2pre: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])");
- },
- val2: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- 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)");
- },
- val1pre: new RegExp("[01]"),
- val1: new RegExp("0[1-9]|1[012]")
- },
- leapday: "02/29/",
- onKeyDown: function(e, buffer, caretPos, opts) {
- var $input = $(this);
- if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
- var today = new Date();
- $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString()),
- $input.trigger("setvalue");
- }
- }
- },
- "yyyy/mm/dd": {
- mask: "y/1/2",
- placeholder: "yyyy/mm/dd",
- alias: "mm/dd/yyyy",
- leapday: "/02/29",
- onKeyDown: function(e, buffer, caretPos, opts) {
- var $input = $(this);
- if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
- var today = new Date();
- $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString()),
- $input.trigger("setvalue");
- }
- }
- },
- "dd.mm.yyyy": {
- mask: "1.2.y",
- placeholder: "dd.mm.yyyy",
- leapday: "29.02.",
- separator: ".",
- alias: "dd/mm/yyyy"
- },
- "dd-mm-yyyy": {
- mask: "1-2-y",
- placeholder: "dd-mm-yyyy",
- leapday: "29-02-",
- separator: "-",
- alias: "dd/mm/yyyy"
- },
- "mm.dd.yyyy": {
- mask: "1.2.y",
- placeholder: "mm.dd.yyyy",
- leapday: "02.29.",
- separator: ".",
- alias: "mm/dd/yyyy"
- },
- "mm-dd-yyyy": {
- mask: "1-2-y",
- placeholder: "mm-dd-yyyy",
- leapday: "02-29-",
- separator: "-",
- alias: "mm/dd/yyyy"
- },
- "yyyy.mm.dd": {
- mask: "y.1.2",
- placeholder: "yyyy.mm.dd",
- leapday: ".02.29",
- separator: ".",
- alias: "yyyy/mm/dd"
- },
- "yyyy-mm-dd": {
- mask: "y-1-2",
- placeholder: "yyyy-mm-dd",
- leapday: "-02-29",
- separator: "-",
- alias: "yyyy/mm/dd"
- },
- datetime: {
- mask: "1/2/y h:s",
- placeholder: "dd/mm/yyyy hh:mm",
- alias: "dd/mm/yyyy",
- regex: {
- hrspre: new RegExp("[012]"),
- hrs24: new RegExp("2[0-4]|1[3-9]"),
- hrs: new RegExp("[01][0-9]|2[0-4]"),
- ampm: new RegExp("^[a|p|A|P][m|M]"),
- mspre: new RegExp("[0-5]"),
- ms: new RegExp("[0-5][0-9]")
- },
- timeseparator: ":",
- hourFormat: "24",
- definitions: {
- h: {
- validator: function(chrs, maskset, pos, strict, opts) {
- if ("24" === opts.hourFormat && 24 === parseInt(chrs, 10)) return maskset.buffer[pos - 1] = "0",
- maskset.buffer[pos] = "0", {
- refreshFromBuffer: {
- start: pos - 1,
- end: pos
- },
- c: "0"
- };
- var isValid = opts.regex.hrs.test(chrs);
- if (!strict && !isValid && (chrs.charAt(1) === opts.timeseparator || -1 !== "-.:".indexOf(chrs.charAt(1))) && (isValid = opts.regex.hrs.test("0" + chrs.charAt(0)))) return maskset.buffer[pos - 1] = "0",
- maskset.buffer[pos] = chrs.charAt(0), pos++, {
- refreshFromBuffer: {
- start: pos - 2,
- end: pos
- },
- pos: pos,
- c: opts.timeseparator
- };
- if (isValid && "24" !== opts.hourFormat && opts.regex.hrs24.test(chrs)) {
- var tmp = parseInt(chrs, 10);
- return 24 === tmp ? (maskset.buffer[pos + 5] = "a", maskset.buffer[pos + 6] = "m") : (maskset.buffer[pos + 5] = "p",
- maskset.buffer[pos + 6] = "m"), tmp -= 12, 10 > tmp ? (maskset.buffer[pos] = tmp.toString(),
- maskset.buffer[pos - 1] = "0") : (maskset.buffer[pos] = tmp.toString().charAt(1),
- maskset.buffer[pos - 1] = tmp.toString().charAt(0)), {
- refreshFromBuffer: {
- start: pos - 1,
- end: pos + 6
- },
- c: maskset.buffer[pos]
- };
- }
- return isValid;
- },
- cardinality: 2,
- prevalidator: [ {
- validator: function(chrs, maskset, pos, strict, opts) {
- var isValid = opts.regex.hrspre.test(chrs);
- return strict || isValid || !(isValid = opts.regex.hrs.test("0" + chrs)) ? isValid : (maskset.buffer[pos] = "0",
- pos++, {
- pos: pos
- });
- },
- cardinality: 1
- } ]
- },
- s: {
- validator: "[0-5][0-9]",
- cardinality: 2,
- prevalidator: [ {
- validator: function(chrs, maskset, pos, strict, opts) {
- var isValid = opts.regex.mspre.test(chrs);
- return strict || isValid || !(isValid = opts.regex.ms.test("0" + chrs)) ? isValid : (maskset.buffer[pos] = "0",
- pos++, {
- pos: pos
- });
- },
- cardinality: 1
- } ]
- },
- t: {
- validator: function(chrs, maskset, pos, strict, opts) {
- return opts.regex.ampm.test(chrs + "m");
- },
- casing: "lower",
- cardinality: 1
- }
- },
- insertMode: !1,
- autoUnmask: !1
- },
- datetime12: {
- mask: "1/2/y h:s t\\m",
- placeholder: "dd/mm/yyyy hh:mm xm",
- alias: "datetime",
- hourFormat: "12"
- },
- "mm/dd/yyyy hh:mm xm": {
- mask: "1/2/y h:s t\\m",
- placeholder: "mm/dd/yyyy hh:mm xm",
- alias: "datetime12",
- regex: {
- val2pre: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])");
- },
- val2: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- 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)");
- },
- val1pre: new RegExp("[01]"),
- val1: new RegExp("0[1-9]|1[012]")
- },
- leapday: "02/29/",
- onKeyDown: function(e, buffer, caretPos, opts) {
- var $input = $(this);
- if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
- var today = new Date();
- $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString()),
- $input.trigger("setvalue");
- }
- }
- },
- "hh:mm t": {
- mask: "h:s t\\m",
- placeholder: "hh:mm xm",
- alias: "datetime",
- hourFormat: "12"
- },
- "h:s t": {
- mask: "h:s t\\m",
- placeholder: "hh:mm xm",
- alias: "datetime",
- hourFormat: "12"
- },
- "hh:mm:ss": {
- mask: "h:s:s",
- placeholder: "hh:mm:ss",
- alias: "datetime",
- autoUnmask: !1
- },
- "hh:mm": {
- mask: "h:s",
- placeholder: "hh:mm",
- alias: "datetime",
- autoUnmask: !1
- },
- date: {
- alias: "dd/mm/yyyy"
- },
- "mm/yyyy": {
- mask: "1/y",
- placeholder: "mm/yyyy",
- leapday: "donotuse",
- separator: "/",
- alias: "mm/dd/yyyy"
- },
- shamsi: {
- regex: {
- val2pre: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "[0-3])");
- },
- val2: function(separator) {
- var escapedSeparator = Inputmask.escapeRegex.call(this, separator);
- 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)");
- },
- val1pre: new RegExp("[01]"),
- val1: new RegExp("0[1-9]|1[012]")
- },
- yearrange: {
- minyear: 1300,
- maxyear: 1499
- },
- mask: "y/1/2",
- leapday: "/12/30",
- placeholder: "yyyy/mm/dd",
- alias: "mm/dd/yyyy",
- clearIncomplete: !0
- }
- }), Inputmask;
- });
|