!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?e(require("jquery")):e(jQuery)}(function(A){var a,e=navigator.userAgent,R=/iphone/i.test(e),S=/chrome/i.test(e),T=/android/i.test(e);A.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},A.fn.extend({caret:function(e,t){var n;if(0!==this.length&&!this.is(":hidden")&&this.get(0)===document.activeElement)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(t,p){var n,v,b,k,y,x,j;if(!t&&0<this.length){var e=A(this[0]).data(A.mask.dataName);return e?e():void 0}return p=A.extend({autoclear:A.mask.autoclear,placeholder:A.mask.placeholder,completed:null},p),n=A.mask.definitions,v=[],b=x=t.length,k=null,t=String(t),A.each(t.split(""),function(e,t){"?"==t?(x--,b=e):n[t]?(v.push(new RegExp(n[t])),null===k&&(k=v.length-1),e<b&&(y=v.length-1)):v.push(null)}),this.trigger("unmask").each(function(){var o=A(this),c=A.map(t.split(""),function(e,t){if("?"!=e)return n[e]?u(t):e}),l=c.join(""),i=o.val();function r(){if(p.completed){for(var e=k;e<=y;e++)if(v[e]&&c[e]===u(e))return;p.completed.call(o)}}function u(e){return e<p.placeholder.length?p.placeholder.charAt(e):p.placeholder.charAt(0)}function s(e){for(;++e<x&&!v[e];);return e}function f(e,t){var n,a;if(!(e<0)){for(n=e,a=s(t);n<x;n++)if(v[n]){if(!(a<x&&v[n].test(c[a])))break;c[n]=c[a],c[a]=u(a),a=s(a)}m(),o.caret(Math.max(k,e))}}function h(e){d(),o.val()!=i&&o.change()}function g(e,t){for(var n=e;n<t&&n<x;n++)v[n]&&(c[n]=u(n))}function m(){o.val(c.join(""))}function d(e){for(var t,n=o.val(),a=-1,i=0,r=0;i<x;i++)if(v[i]){for(c[i]=u(i);r++<n.length;)if(t=n.charAt(r-1),v[i].test(t)){c[i]=t,a=i;break}if(r>n.length){g(i+1,x);break}}else c[i]===n.charAt(r)&&r++,i<b&&(a=i);return e?m():a+1<b?p.autoclear||c.join("")===l?(o.val()&&o.val(""),g(0,x)):m():(m(),o.val(o.val().substring(0,a+1))),b?i:k}o.data(A.mask.dataName,function(){return A.map(c,function(e,t){return v[t]&&e!=u(t)?e:null}).join("")}),o.one("unmask",function(){o.off(".mask").removeData(A.mask.dataName)}).on("focus.mask",function(){var e;o.prop("readonly")||(clearTimeout(a),i=o.val(),e=d(),a=setTimeout(function(){o.get(0)===document.activeElement&&(m(),e==t.replace("?","").length?o.caret(0,e):o.caret(e))},10))}).on("blur.mask",h).on("keydown.mask",function(e){var t,n,a;o.prop("readonly")||(t=e.which||e.keyCode,j=o.val(),8===t||46===t||R&&127===t?(n=(a=o.caret()).begin,(a=a.end)-n==0&&(n=46!==t?function(e){for(;0<=--e&&!v[e];);return e}(n):a=s(n-1),a=46===t?s(a):a),g(n,a),f(n,a-1),e.preventDefault()):13===t?h.call(this,e):27===t&&(o.val(i),o.caret(0,d()),e.preventDefault()))}).on("keypress.mask",function(e){var t,n,a,i;o.prop("readonly")||(i=e.which||e.keyCode,t=o.caret(),e.ctrlKey||e.altKey||e.metaKey||i<32||i&&13!==i&&(t.end-t.begin!=0&&(g(t.begin,t.end),f(t.begin,t.end-1)),(n=s(t.begin-1))<x&&(i=String.fromCharCode(i),v[n].test(i)&&(function(e){for(var t,n,a=e,i=u(e);a<x;a++)if(v[a]){if(t=s(a),n=c[a],c[a]=i,!(t<x&&v[t].test(n)))break;i=n}}(n),c[n]=i,m(),a=s(n),T?setTimeout(function(){A.proxy(A.fn.caret,o,a)()},0):o.caret(a),t.begin<=y&&r())),e.preventDefault()))}).on("input.mask paste.mask",function(){o.prop("readonly")||setTimeout(function(){var e=d(!0);o.caret(e),r()},0)}),S&&T&&o.off("input.mask").on("input.mask",function(e){function t(){A.proxy(A.fn.caret,o,a.begin,a.begin)()}var n=o.val(),a=o.caret();if(j&&j.length&&j.length>n.length){for(d(!0);0<a.begin&&!v[a.begin-1];)a.begin--;if(0===a.begin)for(;a.begin<k&&!v[a.begin];)a.begin++;setTimeout(t,0)}else{var i=d(!0),n=n.charAt(a.begin);a.begin<x&&(v[a.begin]?v[a.begin].test(n)&&a.begin++:a.begin=i),setTimeout(t,0)}r()}),d()})}})});