!function (e) { var t, n = function () { var e = document.createElement("input"), t = "onpaste"; return e.setAttribute(t, ""), "function" == typeof e[t] ? "paste" : "input" }() + ".mask", a = navigator.userAgent, r = /iphone/i.test(a), o = /android/i.test(a); e.mask = { definitions: { 9: "[0-9]", a: "[A-Za-z]", "*": "[A-Za-z0-9]" }, dataName: "rawMaskFn", placeholder: "_" }, e.fn.extend({ caret: function (e, t) { var n; if (0 !== this.length && !this.is(":hidden")) return "number" == typeof e ? (t = "number" == typeof t ? t : e, this.each(function () { this.setSelectionRange ? this.setSelectionRange(e, t) : this.createTextRange && ((n = this.createTextRange()).collapse(!0), n.moveEnd("character", t), n.moveStart("character", e), n.select()) })) : (this[0].setSelectionRange ? (e = this[0].selectionStart, t = this[0].selectionEnd) : document.selection && document.selection.createRange && (n = document.selection.createRange(), e = 0 - n.duplicate().moveStart("character", -1e5), t = e + n.text.length), { begin: e, end: t }) }, unmask: function () { return this.trigger("unmask") }, mask: function (a, i) { var c, l, s, u, f; return !a && this.length > 0 ? e(this[0]).data(e.mask.dataName)() : (i = e.extend({ placeholder: e.mask.placeholder, completed: null }, i), c = e.mask.definitions, l = [], s = f = a.length, u = null, e.each(a.split(""), function (e, t) { "?" == t ? (f-- , s = e) : c[t] ? (l.push(RegExp(c[t])), null === u && (u = l.length - 1)) : l.push(null) }), this.trigger("unmask").each(function () { function h(e) { for (; f > ++e && !l[e];); return e } function m(e, t) { var n, a; if (!(0 > e)) { for (n = e, a = h(t); f > n; n++)if (l[n]) { if (!(f > a && l[n].test(k[a]))) break; k[n] = k[a], k[a] = i.placeholder, a = h(a) } p(), v.caret(Math.max(u, e)) } } function d(e, t) { var n; for (n = e; t > n && f > n; n++)l[n] && (k[n] = i.placeholder) } function p() { v.val(k.join("")) } function g(e) { var t, n, a = v.val(), r = -1; for (t = 0, pos = 0; f > t; t++)if (l[t]) { for (k[t] = i.placeholder; pos++ < a.length;)if (n = a.charAt(pos - 1), l[t].test(n)) { k[t] = n, r = t; break } if (pos > a.length) break } else k[t] === a.charAt(pos) && t !== s && (pos++ , r = t); return e ? p() : s > r + 1 ? (v.val(""), d(0, f)) : (p(), v.val(v.val().substring(0, r + 1))), s ? t : u } var v = e(this), k = e.map(a.split(""), function (e) { return "?" != e ? c[e] ? i.placeholder : e : void 0 }), b = v.val(); v.data(e.mask.dataName, function () { return e.map(k, function (e, t) { return l[t] && e != i.placeholder ? e : null }).join("") }), v.attr("readonly") || v.one("unmask", function () { v.off(".mask").removeData(e.mask.dataName) }).on("focus.mask", function () { var e; clearTimeout(t), b = v.val(), e = g(), t = setTimeout(function () { p(), e == a.length ? v.caret(0, e) : v.caret(e) }, 10) }).on("blur.mask", function () { g(), v.val() != b && v.change() }).on("keydown.mask", function (e) { var t, n, a, o = e.which; 8 === o || 46 === o || r && 127 === o ? (n = (t = v.caret()).begin, 0 == (a = t.end) - n && (n = 46 !== o ? function (e) { for (; --e >= 0 && !l[e];); return e }(n) : a = h(n - 1), a = 46 === o ? h(a) : a), d(n, a), m(n, a - 1), e.preventDefault()) : 27 == o && (v.val(b), v.caret(0, g()), e.preventDefault()) }).on("keypress.mask", function (t) { var n, a, r, c = t.which, s = v.caret(); t.ctrlKey || t.altKey || t.metaKey || 32 > c || c && (0 != s.end - s.begin && (d(s.begin, s.end), m(s.begin, s.end - 1)), n = h(s.begin - 1), f > n && (a = String.fromCharCode(c), l[n].test(a) && (function (e) { var t, n, a, r; for (t = e, n = i.placeholder; f > t; t++)if (l[t]) { if (a = h(t), r = k[t], k[t] = n, !(f > a && l[a].test(r))) break; n = r } }(n), k[n] = a, p(), r = h(n), o ? setTimeout(e.proxy(e.fn.caret, v, r), 0) : v.caret(r), i.completed && r >= f && i.completed.call(v))), t.preventDefault()) }).on(n, function () { setTimeout(function () { var e = g(!0); v.caret(e), i.completed && e == v.val().length && i.completed.call(v) }, 0) }), g() })) } }) }(jQuery);