jquery.inputmask.bundle.js 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000
  1. /**
  2. * @license Input Mask plugin for jquery
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2014 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.0.31
  7. */
  8. (function ($) {
  9. if ($.fn.inputmask === undefined) {
  10. //helper functions
  11. function isInputEventSupported(eventName) {
  12. var el = document.createElement('input'),
  13. eventName = 'on' + eventName,
  14. isSupported = (eventName in el);
  15. if (!isSupported) {
  16. el.setAttribute(eventName, 'return;');
  17. isSupported = typeof el[eventName] == 'function';
  18. }
  19. el = null;
  20. return isSupported;
  21. }
  22. function resolveAlias(aliasStr, options, opts) {
  23. var aliasDefinition = opts.aliases[aliasStr];
  24. if (aliasDefinition) {
  25. if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts); //alias is another alias
  26. $.extend(true, opts, aliasDefinition); //merge alias definition in the options
  27. $.extend(true, opts, options); //reapply extra given options
  28. return true;
  29. }
  30. return false;
  31. }
  32. function generateMaskSet(opts) {
  33. var ms = [];
  34. function analyseMask(mask) {
  35. var tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?\})\??|[^.?*+^${[]()|\\]+|./g,
  36. escaped = false;
  37. function maskToken(isGroup, isOptional, isQuantifier, isAlternator) {
  38. this.matches = [];
  39. this.isGroup = isGroup || false;
  40. this.isOptional = isOptional || false;
  41. this.isQuantifier = isQuantifier || false;
  42. this.isAlternator = isAlternator || false;
  43. this.quantifier = { min: 1, max: 1 };
  44. };
  45. //test definition => {fn: RegExp/function, cardinality: int, optionality: bool, newBlockMarker: bool, offset: int, casing: null/upper/lower, def: definitionSymbol}
  46. function insertTestDefinition(mtoken, element, position) {
  47. var maskdef = opts.definitions[element];
  48. var newBlockMarker = mtoken.matches.length == 0;
  49. position = position != undefined ? position : mtoken.matches.length;
  50. if (maskdef && !escaped) {
  51. var prevalidators = maskdef["prevalidator"], prevalidatorsL = prevalidators ? prevalidators.length : 0;
  52. for (var i = 1; i < maskdef.cardinality; i++) {
  53. var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator["validator"], cardinality = prevalidator["cardinality"];
  54. mtoken.matches.splice(position++, 0, { fn: validator ? typeof validator == 'string' ? new RegExp(validator) : new function () { this.test = validator; } : new RegExp("."), cardinality: cardinality ? cardinality : 1, optionality: mtoken.isOptional, newBlockMarker: newBlockMarker, casing: maskdef["casing"], def: maskdef["definitionSymbol"] || element });
  55. }
  56. mtoken.matches.splice(position++, 0, { fn: maskdef.validator ? typeof maskdef.validator == 'string' ? new RegExp(maskdef.validator) : new function () { this.test = maskdef.validator; } : new RegExp("."), cardinality: maskdef.cardinality, optionality: mtoken.isOptional, newBlockMarker: newBlockMarker, casing: maskdef["casing"], def: maskdef["definitionSymbol"] || element });
  57. } else {
  58. mtoken.matches.splice(position++, 0, { fn: null, cardinality: 0, optionality: mtoken.isOptional, newBlockMarker: newBlockMarker, casing: null, def: element });
  59. escaped = false;
  60. }
  61. }
  62. var currentToken = new maskToken(),
  63. match,
  64. m,
  65. openenings = [],
  66. maskTokens = [];
  67. while (match = tokenizer.exec(mask)) {
  68. m = match[0];
  69. switch (m.charAt(0)) {
  70. case opts.optionalmarker.end:
  71. // optional closing
  72. case opts.groupmarker.end:
  73. // Group closing
  74. var openingToken = openenings.pop();
  75. if (openenings.length > 0) {
  76. openenings[openenings.length - 1]["matches"].push(openingToken);
  77. } else {
  78. currentToken.matches.push(openingToken);
  79. }
  80. break;
  81. case opts.optionalmarker.start:
  82. // optional opening
  83. openenings.push(new maskToken(false, true));
  84. break;
  85. case opts.groupmarker.start:
  86. // Group opening
  87. openenings.push(new maskToken(true));
  88. break;
  89. case opts.quantifiermarker.start:
  90. //Quantifier
  91. var quantifier = new maskToken(false, false, true);
  92. m = m.replace(/[{}]/g, "");
  93. var mq = m.split(","),
  94. mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]),
  95. mq1 = mq.length == 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
  96. if (mq1 == "*" || mq1 == "+") {
  97. mq0 = mq1 == "*" ? 0 : 1;
  98. }
  99. quantifier.quantifier = { min: mq0, max: mq1 };
  100. if (openenings.length > 0) {
  101. var matches = openenings[openenings.length - 1]["matches"];
  102. var match = matches.pop();
  103. if (!match["isGroup"]) {
  104. var groupToken = new maskToken(true);
  105. groupToken.matches.push(match);
  106. match = groupToken;
  107. }
  108. matches.push(match);
  109. matches.push(quantifier);
  110. } else {
  111. var match = currentToken.matches.pop();
  112. if (!match["isGroup"]) {
  113. var groupToken = new maskToken(true);
  114. groupToken.matches.push(match);
  115. match = groupToken;
  116. }
  117. currentToken.matches.push(match);
  118. currentToken.matches.push(quantifier);
  119. }
  120. break;
  121. case opts.escapeChar:
  122. escaped = true;
  123. break;
  124. case opts.alternatormarker:
  125. break;
  126. default:
  127. if (openenings.length > 0) {
  128. insertTestDefinition(openenings[openenings.length - 1], m);
  129. } else {
  130. if (currentToken.matches.length > 0) {
  131. var lastMatch = currentToken.matches[currentToken.matches.length - 1];
  132. if (lastMatch["isGroup"]) { //this is not a group but a normal mask => convert
  133. lastMatch.isGroup = false;
  134. insertTestDefinition(lastMatch, opts.groupmarker.start, 0);
  135. insertTestDefinition(lastMatch, opts.groupmarker.end);
  136. }
  137. }
  138. insertTestDefinition(currentToken, m);
  139. }
  140. }
  141. }
  142. if (currentToken.matches.length > 0)
  143. maskTokens.push(currentToken);
  144. //console.log(JSON.stringify(maskTokens));
  145. return maskTokens;
  146. }
  147. function generateMask(mask, metadata) {
  148. if (opts.numericInput && opts.multi !== true) { //TODO FIX FOR DYNAMIC MASKS WITH QUANTIFIERS
  149. mask = mask.split('').reverse();
  150. for (var ndx = 0; ndx < mask.length; ndx++) {
  151. if (mask[ndx] == opts.optionalmarker.start)
  152. mask[ndx] = opts.optionalmarker.end;
  153. else if (mask[ndx] == opts.optionalmarker.end)
  154. mask[ndx] = opts.optionalmarker.start;
  155. else if (mask[ndx] == opts.groupmarker.start)
  156. mask[ndx] = opts.groupmarker.end;
  157. else if (mask[ndx] == opts.groupmarker.end)
  158. mask[ndx] = opts.groupmarker.start;
  159. }
  160. mask = mask.join('');
  161. }
  162. if (mask == undefined || mask == "")
  163. return undefined;
  164. else {
  165. if (opts.repeat > 0 || opts.repeat == "*" || opts.repeat == "+") {
  166. var repeatStart = opts.repeat == "*" ? 0 : (opts.repeat == "+" ? 1 : opts.repeat);
  167. mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
  168. }
  169. if ($.inputmask.masksCache[mask] == undefined) {
  170. $.inputmask.masksCache[mask] = {
  171. "mask": mask,
  172. "maskToken": analyseMask(mask),
  173. "validPositions": {},
  174. "_buffer": undefined,
  175. "buffer": undefined,
  176. "tests": {},
  177. "metadata": metadata
  178. };
  179. }
  180. return $.extend(true, {}, $.inputmask.masksCache[mask]);
  181. }
  182. }
  183. if ($.isFunction(opts.mask)) { //allow mask to be a preprocessing fn - should return a valid mask
  184. opts.mask = opts.mask.call(this, opts);
  185. }
  186. if ($.isArray(opts.mask)) {
  187. $.each(opts.mask, function (ndx, msk) {
  188. if (msk["mask"] != undefined) {
  189. ms.push(generateMask(msk["mask"].toString(), msk));
  190. } else {
  191. ms.push(generateMask(msk.toString()));
  192. }
  193. });
  194. } else {
  195. if (opts.mask.length == 1 && opts.greedy == false && opts.repeat != 0) {
  196. opts.placeholder = "";
  197. } //hide placeholder with single non-greedy mask
  198. if (opts.mask["mask"] != undefined) {
  199. ms = generateMask(opts.mask["mask"].toString(), opts.mask);
  200. } else {
  201. ms = generateMask(opts.mask.toString());
  202. }
  203. }
  204. return ms;
  205. }
  206. var msie1x = typeof ScriptEngineMajorVersion === "function"
  207. ? ScriptEngineMajorVersion() //IE11 detection
  208. : new Function("/*@cc_on return @_jscript_version; @*/")() >= 10, //conditional compilation from mickeysoft trick
  209. ua = navigator.userAgent,
  210. iphone = ua.match(new RegExp("iphone", "i")) !== null,
  211. android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
  212. androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
  213. androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
  214. kindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua),
  215. PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
  216. //if (androidchrome) {
  217. // var browser = navigator.userAgent.match(new RegExp("chrome.*", "i")),
  218. // version = parseInt(new RegExp(/[0-9]+/).exec(browser));
  219. // androidchrome32 = (version == 32);
  220. //}
  221. //masking scope
  222. //actionObj definition see below
  223. function maskScope(actionObj, maskset, opts) {
  224. var isRTL = false,
  225. valueOnFocus,
  226. $el,
  227. skipKeyPressEvent = false, //Safari 5.1.x - modal dialog fires keypress twice workaround
  228. skipInputEvent = false, //skip when triggered from within inputmask
  229. ignorable = false,
  230. maxLength;
  231. //maskset helperfunctions
  232. function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
  233. minimalPos = minimalPos || 0;
  234. var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos;
  235. do {
  236. if (baseOnInput === true && getMaskSet()['validPositions'][pos]) {
  237. var validPos = getMaskSet()['validPositions'][pos];
  238. test = validPos["match"];
  239. ndxIntlzr = validPos["locator"].slice();
  240. maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
  241. } else {
  242. if (minimalPos > pos) {
  243. var testPositions = getTests(pos, ndxIntlzr, pos - 1);
  244. testPos = testPositions[0];
  245. } else {
  246. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  247. }
  248. test = testPos["match"];
  249. ndxIntlzr = testPos["locator"].slice();
  250. maskTemplate.push(test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
  251. }
  252. pos++;
  253. } while ((maxLength == undefined || pos - 1 < maxLength) && test["fn"] != null || (test["fn"] == null && test["def"] != "") || minimalPos >= pos);
  254. maskTemplate.pop(); //drop the last one which is empty
  255. return maskTemplate;
  256. }
  257. function getMaskSet() {
  258. return maskset;
  259. }
  260. function resetMaskSet(soft) {
  261. var maskset = getMaskSet();
  262. maskset["buffer"] = undefined;
  263. maskset["tests"] = {};
  264. if (soft !== true) {
  265. maskset["_buffer"] = undefined;
  266. maskset["validPositions"] = {};
  267. maskset["p"] = -1;
  268. }
  269. }
  270. function getLastValidPosition(closestTo) {
  271. var maskset = getMaskSet(), lastValidPosition = -1, valids = maskset["validPositions"];
  272. if ($.isFunction(opts.getLastValidPosition))
  273. lastValidPosition = opts.getLastValidPosition.call($el, maskset, closestTo, opts);
  274. else {
  275. if (closestTo == undefined) closestTo = -1;
  276. var before = lastValidPosition, after = lastValidPosition;
  277. for (var posNdx in valids) {
  278. var psNdx = parseInt(posNdx);
  279. if (closestTo == -1 || valids[psNdx]["match"].fn != null) {
  280. if (psNdx < closestTo) before = psNdx;
  281. if (psNdx >= closestTo) after = psNdx;
  282. }
  283. }
  284. lastValidPosition = (closestTo - before) > 1 || after < closestTo ? before : after;
  285. }
  286. return lastValidPosition;
  287. }
  288. function setValidPosition(pos, validTest, fromSetValid) {
  289. if (opts.insertMode && getMaskSet()["validPositions"][pos] != undefined && fromSetValid == undefined) {
  290. //reposition & revalidate others
  291. var positionsClone = $.extend(true, {}, getMaskSet()["validPositions"]), lvp = getLastValidPosition(), i;
  292. for (i = pos; i <= lvp; i++) { //clear selection
  293. delete getMaskSet()["validPositions"][i];
  294. }
  295. getMaskSet()["validPositions"][pos] = validTest;
  296. var valid = true;
  297. for (i = pos; i <= lvp ; i++) {
  298. var t = positionsClone[i];
  299. if (t != undefined) {
  300. var j = t["match"].fn == null ? i + 1 : seekNext(i);
  301. if (positionCanMatchDefinition(j, t["match"].def)) {
  302. valid = valid && isValid(j, t["input"], true, true) !== false;
  303. } else valid = false;
  304. }
  305. if (!valid) break;
  306. }
  307. if (!valid) {
  308. getMaskSet()["validPositions"] = $.extend(true, {}, positionsClone);
  309. return false;
  310. }
  311. } else
  312. getMaskSet()["validPositions"][pos] = validTest;
  313. return true;
  314. }
  315. function stripValidPositions(start, end) {
  316. var i, startPos = start, lvp;
  317. for (i = start; i < end; i++) { //clear selection
  318. delete getMaskSet()["validPositions"][i];
  319. }
  320. for (i = end ; i <= getLastValidPosition() ;) {
  321. var t = getMaskSet()["validPositions"][i];
  322. var s = getMaskSet()["validPositions"][startPos];
  323. if (t != undefined && s == undefined) {
  324. if (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t["input"], true) !== false) {
  325. delete getMaskSet()["validPositions"][i];
  326. i++;
  327. }
  328. startPos++;
  329. } else i++;
  330. }
  331. lvp = getLastValidPosition();
  332. //catchup
  333. while (lvp > 0 && (getMaskSet()["validPositions"][lvp] == undefined || getMaskSet()["validPositions"][lvp].match.fn == null)) {
  334. delete getMaskSet()["validPositions"][lvp];
  335. lvp--;
  336. }
  337. resetMaskSet(true);
  338. }
  339. function getTestTemplate(pos, ndxIntlzr, tstPs) {
  340. var testPositions = getTests(pos, ndxIntlzr, tstPs), testPos;
  341. for (var ndx = 0; ndx < testPositions.length; ndx++) {
  342. testPos = testPositions[ndx];
  343. if (opts.greedy || (testPos["match"] && (testPos["match"].optionality === false || testPos["match"].newBlockMarker === false) && testPos["match"].optionalQuantifier !== true)) {
  344. break;
  345. }
  346. }
  347. return testPos;
  348. }
  349. function getTest(pos) {
  350. if (getMaskSet()['validPositions'][pos]) {
  351. return getMaskSet()['validPositions'][pos]["match"];
  352. }
  353. return getTests(pos)[0]["match"];
  354. }
  355. function positionCanMatchDefinition(pos, def) {
  356. var valid = false, tests = getTests(pos);
  357. for (var tndx = 0; tndx < tests.length; tndx++) {
  358. if (tests[tndx]["match"] && tests[tndx]["match"].def == def) {
  359. valid = true;
  360. break;
  361. }
  362. }
  363. return valid;
  364. };
  365. function getTests(pos, ndxIntlzr, tstPs) {
  366. var maskTokens = getMaskSet()["maskToken"], testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [0], matches = [], insertStop = false;
  367. function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
  368. function handleMatch(match, loopNdx, quantifierRecurse) {
  369. if (testPos == pos && match.matches == undefined) {
  370. matches.push({ "match": match, "locator": loopNdx.reverse() });
  371. return true;
  372. } else if (match.matches != undefined) {
  373. if (match.isGroup && quantifierRecurse !== true) { //when a group pass along to the quantifier
  374. match = handleMatch(maskToken.matches[tndx + 1], loopNdx);
  375. if (match) return true;
  376. } else if (match.isOptional) {
  377. var optionalToken = match;
  378. match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  379. if (match) {
  380. var latestMatch = matches[matches.length - 1]["match"];
  381. var isFirstMatch = $.inArray(latestMatch, optionalToken.matches) == 0;
  382. if (isFirstMatch) {
  383. insertStop = true; //insert a stop for non greedy
  384. }
  385. testPos = pos; //match the position after the group
  386. }
  387. } else if (match.isAlternator) {
  388. //TODO
  389. } else if (match.isQuantifier && quantifierRecurse !== true) {
  390. var qt = match;
  391. opts.greedy = opts.greedy && !isNaN(qt.quantifier.max); //greedy must be off when * or + is used (always!!)
  392. for (var qndx = (ndxInitializer.length > 0 && quantifierRecurse !== true) ? ndxInitializer.shift() : 0; (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) {
  393. var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
  394. match = handleMatch(tokenGroup, [qndx].concat(loopNdx), true);
  395. if (match) {
  396. //get latest match
  397. var latestMatch = matches[matches.length - 1]["match"];
  398. latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
  399. var isFirstMatch = $.inArray(latestMatch, tokenGroup.matches) == 0;
  400. if (isFirstMatch) { //search for next possible match
  401. if (qndx > qt.quantifier.min - 1) {
  402. insertStop = true;
  403. testPos = pos; //match the position after the group
  404. break; //stop quantifierloop
  405. } else return true;
  406. } else {
  407. return true;
  408. }
  409. }
  410. }
  411. } else {
  412. match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  413. if (match)
  414. return true;
  415. }
  416. } else testPos++;
  417. }
  418. for (var tndx = (ndxInitializer.length > 0 ? ndxInitializer.shift() : 0) ; tndx < maskToken.matches.length; tndx++) {
  419. if (maskToken.matches[tndx]["isQuantifier"] !== true) {
  420. var match = handleMatch(maskToken.matches[tndx], [tndx].concat(loopNdx), quantifierRecurse);
  421. if (match && testPos == pos) {
  422. return match;
  423. } else if (testPos > pos) {
  424. break;
  425. }
  426. }
  427. }
  428. }
  429. //if (disableCache !== true && getMaskSet()['tests'][pos] && !getMaskSet()['validPositions'][pos]) {
  430. // return getMaskSet()['tests'][pos];
  431. //}
  432. if (ndxIntlzr == undefined) {
  433. var previousPos = pos - 1, test;
  434. while ((test = getMaskSet()['validPositions'][previousPos]) == undefined && previousPos > -1) {
  435. previousPos--;
  436. }
  437. if (test != undefined && previousPos > -1) {
  438. testPos = previousPos;
  439. ndxInitializer = test["locator"].slice();
  440. } else {
  441. previousPos = pos - 1;
  442. while ((test = getMaskSet()['tests'][previousPos]) == undefined && previousPos > -1) {
  443. previousPos--;
  444. }
  445. if (test != undefined && previousPos > -1) {
  446. testPos = previousPos;
  447. ndxInitializer = test[0]["locator"].slice();
  448. }
  449. }
  450. }
  451. for (var mtndx = ndxInitializer.shift() ; mtndx < maskTokens.length; mtndx++) {
  452. var match = ResolveTestFromToken(maskTokens[mtndx], ndxInitializer, [mtndx]);
  453. if ((match && testPos == pos) || testPos > pos) {
  454. break;
  455. }
  456. }
  457. if (matches.length == 0 || insertStop)
  458. matches.push({ "match": { fn: null, cardinality: 0, optionality: true, casing: null, def: "" }, "locator": [] });
  459. getMaskSet()['tests'][pos] = matches;
  460. //console.log(pos + " - " + JSON.stringify(matches));
  461. return matches;
  462. }
  463. function getBufferTemplate() {
  464. if (getMaskSet()['_buffer'] == undefined) {
  465. //generate template
  466. getMaskSet()["_buffer"] = getMaskTemplate(false, 1);
  467. }
  468. return getMaskSet()['_buffer'];
  469. }
  470. function getBuffer() {
  471. if (getMaskSet()['buffer'] == undefined) {
  472. getMaskSet()['buffer'] = getMaskTemplate(true, getLastValidPosition(), true);
  473. }
  474. return getMaskSet()['buffer'];
  475. }
  476. function refreshFromBuffer(start, end) {
  477. var buffer = getBuffer().slice(); //work on clone
  478. for (var i = start; i < end; i++) {
  479. if (buffer[i] != getPlaceholder(i) && buffer[i] != opts.skipOptionalPartCharacter) {
  480. isValid(i, buffer[i], true, true);
  481. }
  482. }
  483. }
  484. function casing(elem, test) {
  485. switch (test.casing) {
  486. case "upper":
  487. elem = elem.toUpperCase();
  488. break;
  489. case "lower":
  490. elem = elem.toLowerCase();
  491. break;
  492. }
  493. return elem;
  494. }
  495. function isValid(pos, c, strict, fromSetValid) { //strict true ~ no correction or autofill
  496. strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions
  497. function _isValid(position, c, strict, fromSetValid) {
  498. var rslt = false;
  499. $.each(getTests(position), function (ndx, tst) {
  500. var test = tst["match"];
  501. var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
  502. for (var i = test.cardinality; i > loopend; i--) {
  503. chrs += getBufferElement(position - (i - 1));
  504. }
  505. if (c) {
  506. chrs += c;
  507. }
  508. //return is false or a json object => { pos: ??, c: ??} or true
  509. rslt = test.fn != null ?
  510. test.fn.test(chrs, buffer, position, strict, opts)
  511. : (c == test["def"] || c == opts.skipOptionalPartCharacter) && test["def"] != "" ? //non mask
  512. { c: test["def"], pos: position }
  513. : false;
  514. if (rslt !== false) {
  515. var elem = rslt.c != undefined ? rslt.c : c;
  516. elem = (elem == opts.skipOptionalPartCharacter && test["fn"] === null) ? test["def"] : elem;
  517. var validatedPos = position;
  518. if (rslt["refreshFromBuffer"]) {
  519. var refresh = rslt["refreshFromBuffer"];
  520. strict = true;
  521. if (refresh === true) {
  522. getMaskSet()["validPositions"] = {};
  523. getMaskSet()["tests"] = {};
  524. refreshFromBuffer(0, getBuffer().length);
  525. }
  526. else {
  527. refreshFromBuffer(refresh["start"], refresh["end"]);
  528. }
  529. if (rslt.pos == undefined && rslt.c == undefined) {
  530. rslt.pos = getLastValidPosition();
  531. return false;//breakout if refreshFromBuffer && nothing to insert
  532. }
  533. validatedPos = rslt.pos != undefined ? rslt.pos : position;
  534. tst = getTests(validatedPos)[0]; //possible mismatch TODO
  535. } else if (rslt !== true && rslt["pos"] != position) { //their is a position offset
  536. validatedPos = rslt["pos"];
  537. refreshFromBuffer(position, validatedPos);
  538. tst = getTests(validatedPos)[0]; //possible mismatch TODO
  539. }
  540. if (ndx > 0) {
  541. resetMaskSet(true);
  542. }
  543. if (!setValidPosition(validatedPos, $.extend({}, tst, { "input": casing(elem, test) }), fromSetValid))
  544. rslt = false;
  545. return false; //break from $.each
  546. }
  547. });
  548. return rslt;
  549. }
  550. var maskPos = pos;
  551. var result = _isValid(maskPos, c, strict, fromSetValid);
  552. if (!strict && result === false) {
  553. var currentPosValid = getMaskSet()["validPositions"][maskPos];
  554. if (currentPosValid && currentPosValid["match"].fn == null && (currentPosValid["match"].def == c || c == opts.skipOptionalPartCharacter)) {
  555. result = { "caret": seekNext(maskPos) };
  556. } else if ((opts.insertMode || getMaskSet()["validPositions"][seekNext(maskPos)] == undefined) && !isMask(maskPos)) { //does the input match on a further position?
  557. for (var nPos = maskPos + 1, snPos = seekNext(maskPos) ; nPos <= snPos; nPos++) {
  558. result = _isValid(nPos, c, strict, fromSetValid);
  559. if (result !== false) {
  560. maskPos = nPos;
  561. break;
  562. }
  563. }
  564. }
  565. }
  566. if (result === true) result = { "pos": maskPos };
  567. return result;
  568. }
  569. function isMask(pos) {
  570. var test = getTest(pos);
  571. return test.fn != null ? test.fn : false;
  572. }
  573. function getMaskLength() {
  574. var maskLength;
  575. maxLength = $el.prop('maxLength');
  576. if (maxLength == -1) maxLength = undefined; /* FF sets no defined max length to -1 */
  577. if (opts.greedy == false) {
  578. var pos, lvp = getLastValidPosition(), testPos = getMaskSet()["validPositions"][lvp],
  579. ndxIntlzr = testPos != undefined ? testPos["locator"].slice() : undefined;
  580. for (pos = lvp + 1; testPos == undefined || (testPos["match"]["fn"] != null || (testPos["match"]["fn"] == null && testPos["match"]["def"] != "")) ; pos++) {
  581. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  582. ndxIntlzr = testPos["locator"].slice();
  583. }
  584. maskLength = pos;
  585. } else
  586. maskLength = getBuffer().length;
  587. return (maxLength == undefined || maskLength < maxLength) ? maskLength : maxLength;
  588. }
  589. function seekNext(pos) {
  590. var maskL = getMaskLength();
  591. if (pos >= maskL) return maskL;
  592. var position = pos;
  593. while (++position < maskL && !isMask(position) && (opts.nojumps !== true || opts.nojumpsThreshold > position)) {
  594. }
  595. return position;
  596. }
  597. function seekPrevious(pos) {
  598. var position = pos;
  599. if (position <= 0) return 0;
  600. while (--position > 0 && !isMask(position)) {
  601. };
  602. return position;
  603. }
  604. function getBufferElement(position) {
  605. return getMaskSet()["validPositions"][position] == undefined ? getPlaceholder(position) : getMaskSet()["validPositions"][position]["input"];
  606. }
  607. function writeBuffer(input, buffer, caretPos) {
  608. input._valueSet(buffer.join(''));
  609. if (caretPos != undefined) {
  610. caret(input, caretPos);
  611. }
  612. }
  613. function getPlaceholder(pos, test) {
  614. test = test || getTest(pos);
  615. return test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length);
  616. }
  617. function checkVal(input, writeOut, strict, nptvl, intelliCheck) {
  618. var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
  619. resetMaskSet();
  620. if (writeOut) input._valueSet(""); //initial clear
  621. $.each(inputValue, function (ndx, charCode) {
  622. if (intelliCheck === true) {
  623. var p = getMaskSet()["p"],
  624. lvp = p == -1 ? p : seekPrevious(p),
  625. pos = lvp == -1 ? ndx : seekNext(lvp);
  626. if ($.inArray(charCode, getBufferTemplate().slice(lvp + 1, pos)) == -1) {
  627. keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, strict, ndx);
  628. }
  629. } else {
  630. keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, strict, ndx);
  631. strict = strict || (ndx > 0 && ndx > getMaskSet()["p"]);
  632. }
  633. });
  634. if (writeOut)
  635. writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : undefined);
  636. }
  637. function escapeRegex(str) {
  638. return $.inputmask.escapeRegex.call(this, str);
  639. }
  640. function truncateInput(inputValue) {
  641. return inputValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*$"), "");
  642. }
  643. function clearOptionalTail(input) {
  644. var buffer = getBuffer(), tmpBuffer = buffer.slice(),
  645. pos, lvp = getLastValidPosition(), positions = {},
  646. ndxIntlzr = getMaskSet()["validPositions"][lvp] != undefined ? getMaskSet()["validPositions"][lvp]["locator"].slice() : undefined, testPos;
  647. for (pos = lvp + 1; pos < tmpBuffer.length; pos++) {
  648. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  649. ndxIntlzr = testPos["locator"].slice();
  650. positions[pos] = testPos;
  651. }
  652. for (pos = tmpBuffer.length - 1; pos > lvp; pos--) {
  653. testPos = positions[pos]["match"];
  654. if (testPos.optionality && tmpBuffer[pos] == getPlaceholder(pos, testPos)) {
  655. tmpBuffer.pop();
  656. } else break;
  657. }
  658. writeBuffer(input, tmpBuffer);
  659. }
  660. function unmaskedvalue($input, skipDatepickerCheck) {
  661. if ($input.data('_inputmask') && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
  662. var umValue = [], vps = getMaskSet()["validPositions"];
  663. for (var pndx in vps) {
  664. if (vps[pndx]["match"] && vps[pndx]["match"].fn != null) {
  665. umValue.push(vps[pndx]["input"]);
  666. }
  667. }
  668. var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join('');
  669. var bufferValue = (isRTL ? getBuffer().reverse() : getBuffer()).join('');
  670. return $.isFunction(opts.onUnMask) ? opts.onUnMask.call($input, bufferValue, unmaskedValue, opts) : unmaskedValue;
  671. } else {
  672. return $input[0]._valueGet();
  673. }
  674. }
  675. function TranslatePosition(pos) {
  676. if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
  677. var bffrLght = getBuffer().length;
  678. pos = bffrLght - pos;
  679. }
  680. return pos;
  681. }
  682. function caret(input, begin, end) {
  683. var npt = input.jquery && input.length > 0 ? input[0] : input, range;
  684. if (typeof begin == 'number') {
  685. begin = TranslatePosition(begin);
  686. end = TranslatePosition(end);
  687. end = (typeof end == 'number') ? end : begin;
  688. //store caret for multi scope
  689. var data = $(npt).data('_inputmask') || {};
  690. data["caret"] = { "begin": begin, "end": end };
  691. $(npt).data('_inputmask', data);
  692. if (!$(npt).is(":visible")) {
  693. return;
  694. }
  695. npt.scrollLeft = npt.scrollWidth;
  696. if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
  697. if (npt.setSelectionRange) {
  698. npt.selectionStart = begin;
  699. npt.selectionEnd = end;
  700. } else if (npt.createTextRange) {
  701. range = npt.createTextRange();
  702. range.collapse(true);
  703. range.moveEnd('character', end);
  704. range.moveStart('character', begin);
  705. range.select();
  706. }
  707. } else {
  708. var data = $(npt).data('_inputmask');
  709. if (!$(npt).is(":visible") && data && data["caret"] != undefined) {
  710. begin = data["caret"]["begin"];
  711. end = data["caret"]["end"];
  712. } else if (npt.setSelectionRange) {
  713. begin = npt.selectionStart;
  714. end = npt.selectionEnd;
  715. } else if (document.selection && document.selection.createRange) {
  716. range = document.selection.createRange();
  717. begin = 0 - range.duplicate().moveStart('character', -100000);
  718. end = begin + range.text.length;
  719. }
  720. begin = TranslatePosition(begin);
  721. end = TranslatePosition(end);
  722. return { "begin": begin, "end": end };
  723. }
  724. }
  725. function isComplete(buffer) { //return true / false / undefined (repeat *)
  726. if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
  727. if (opts.repeat == "*") return undefined;
  728. var complete = false,
  729. aml = seekPrevious(getMaskLength());
  730. if (getLastValidPosition() == aml) {
  731. complete = true;
  732. for (var i = 0; i <= aml; i++) {
  733. var mask = isMask(i);
  734. if ((mask && (buffer[i] == undefined || buffer[i] == getPlaceholder(i))) || (!mask && buffer[i] != getPlaceholder(i))) {
  735. complete = false;
  736. break;
  737. }
  738. }
  739. }
  740. return complete;
  741. }
  742. function isSelection(begin, end) {
  743. return isRTL ? (begin - end) > 1 || ((begin - end) == 1 && opts.insertMode) :
  744. (end - begin) > 1 || ((end - begin) == 1 && opts.insertMode);
  745. }
  746. function installEventRuler(npt) {
  747. var events = $._data(npt).events;
  748. $.each(events, function (eventType, eventHandlers) {
  749. $.each(eventHandlers, function (ndx, eventHandler) {
  750. if (eventHandler.namespace == "inputmask") {
  751. if (eventHandler.type != "setvalue") {
  752. var handler = eventHandler.handler;
  753. eventHandler.handler = function (e) {
  754. if (this.readOnly || this.disabled)
  755. e.preventDefault;
  756. else
  757. return handler.apply(this, arguments);
  758. };
  759. }
  760. }
  761. });
  762. });
  763. }
  764. function patchValueProperty(npt) {
  765. function PatchValhook(type) {
  766. if ($.valHooks[type] == undefined || $.valHooks[type].inputmaskpatch != true) {
  767. var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) { return elem.value; };
  768. var valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
  769. elem.value = value;
  770. return elem;
  771. };
  772. $.valHooks[type] = {
  773. get: function (elem) {
  774. var $elem = $(elem);
  775. if ($elem.data('_inputmask')) {
  776. if ($elem.data('_inputmask')['opts'].autoUnmask)
  777. return $elem.inputmask('unmaskedvalue');
  778. else {
  779. var result = valueGet(elem),
  780. inputData = $elem.data('_inputmask'),
  781. maskset = inputData['maskset'],
  782. bufferTemplate = maskset['_buffer'];
  783. bufferTemplate = bufferTemplate ? bufferTemplate.join('') : '';
  784. return result != bufferTemplate ? result : '';
  785. }
  786. } else return valueGet(elem);
  787. },
  788. set: function (elem, value) {
  789. var $elem = $(elem);
  790. var result = valueSet(elem, value);
  791. if ($elem.data('_inputmask')) $elem.triggerHandler('setvalue.inputmask');
  792. return result;
  793. },
  794. inputmaskpatch: true
  795. };
  796. }
  797. }
  798. var valueProperty;
  799. if (Object.getOwnPropertyDescriptor)
  800. valueProperty = Object.getOwnPropertyDescriptor(npt, "value");
  801. if (valueProperty && valueProperty.get) {
  802. if (!npt._valueGet) {
  803. var valueGet = valueProperty.get;
  804. var valueSet = valueProperty.set;
  805. npt._valueGet = function () {
  806. return isRTL ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
  807. };
  808. npt._valueSet = function (value) {
  809. valueSet.call(this, isRTL ? value.split('').reverse().join('') : value);
  810. };
  811. Object.defineProperty(npt, "value", {
  812. get: function () {
  813. var $self = $(this), inputData = $(this).data('_inputmask');
  814. if (inputData) {
  815. return inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : (valueGet.call(this) != getBufferTemplate().join('') ? valueGet.call(this) : '');
  816. } else return valueGet.call(this);
  817. },
  818. set: function (value) {
  819. valueSet.call(this, value);
  820. $(this).triggerHandler('setvalue.inputmask');
  821. }
  822. });
  823. }
  824. } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
  825. if (!npt._valueGet) {
  826. var valueGet = npt.__lookupGetter__("value");
  827. var valueSet = npt.__lookupSetter__("value");
  828. npt._valueGet = function () {
  829. return isRTL ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
  830. };
  831. npt._valueSet = function (value) {
  832. valueSet.call(this, isRTL ? value.split('').reverse().join('') : value);
  833. };
  834. npt.__defineGetter__("value", function () {
  835. var $self = $(this), inputData = $(this).data('_inputmask');
  836. if (inputData) {
  837. return inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : (valueGet.call(this) != getBufferTemplate().join('') ? valueGet.call(this) : '');
  838. } else return valueGet.call(this);
  839. });
  840. npt.__defineSetter__("value", function (value) {
  841. valueSet.call(this, value);
  842. $(this).triggerHandler('setvalue.inputmask');
  843. });
  844. }
  845. } else {
  846. if (!npt._valueGet) {
  847. npt._valueGet = function () { return isRTL ? this.value.split('').reverse().join('') : this.value; };
  848. npt._valueSet = function (value) { this.value = isRTL ? value.split('').reverse().join('') : value; };
  849. }
  850. PatchValhook(npt.type);
  851. }
  852. }
  853. function HandleRemove(input, k, pos) {
  854. if (opts.numericInput || isRTL) {
  855. switch (k) {
  856. case opts.keyCode.BACKSPACE:
  857. k = opts.keyCode.DELETE;
  858. break;
  859. case opts.keyCode.DELETE:
  860. k = opts.keyCode.BACKSPACE;
  861. break;
  862. }
  863. if (isRTL) {
  864. var pend = pos.end;
  865. pos.end = pos.begin;
  866. pos.begin = pend;
  867. }
  868. }
  869. if (pos.begin == pos.end) {
  870. var posBegin = k == opts.keyCode.BACKSPACE ? pos.begin - 1 : pos.begin;
  871. if (k == opts.keyCode.BACKSPACE)
  872. pos.begin = seekPrevious(pos.begin);
  873. else if (k == opts.keyCode.DELETE)
  874. pos.end++;
  875. } else if (pos.end - pos.begin == 1 && !opts.insertMode) {
  876. if (k == opts.keyCode.BACKSPACE)
  877. pos.begin--;
  878. }
  879. stripValidPositions(pos.begin, pos.end);
  880. var firstMaskPos = seekNext(-1);
  881. if (getLastValidPosition() < firstMaskPos) {
  882. getMaskSet()["p"] = firstMaskPos;
  883. } else {
  884. getMaskSet()["p"] = pos.begin;
  885. }
  886. }
  887. function keydownEvent(e) {
  888. //Safari 5.1.x - modal dialog fires keypress twice workaround
  889. skipKeyPressEvent = false;
  890. var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
  891. //backspace, delete, and escape get special treatment
  892. if (k == opts.keyCode.BACKSPACE || k == opts.keyCode.DELETE || (iphone && k == 127) || e.ctrlKey && k == 88) { //backspace/delete
  893. e.preventDefault(); //stop default action but allow propagation
  894. if (k == 88) valueOnFocus = getBuffer().join('');
  895. HandleRemove(input, k, pos);
  896. writeBuffer(input, getBuffer(), getMaskSet()["p"]);
  897. if (input._valueGet() == getBufferTemplate().join(''))
  898. $input.trigger('cleared');
  899. if (opts.showTooltip) { //update tooltip
  900. $input.prop("title", getMaskSet()["mask"]);
  901. }
  902. } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
  903. setTimeout(function () {
  904. var caretPos = seekNext(getLastValidPosition());
  905. if (!opts.insertMode && caretPos == getMaskLength() && !e.shiftKey) caretPos--;
  906. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
  907. }, 0);
  908. } else if ((k == opts.keyCode.HOME && !e.shiftKey) || k == opts.keyCode.PAGE_UP) { //Home or page_up
  909. caret(input, 0, e.shiftKey ? pos.begin : 0);
  910. } else if (k == opts.keyCode.ESCAPE || (k == 90 && e.ctrlKey)) { //escape && undo
  911. checkVal(input, true, false, valueOnFocus.split(''));
  912. $input.click();
  913. } else if (k == opts.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) { //insert
  914. opts.insertMode = !opts.insertMode;
  915. caret(input, !opts.insertMode && pos.begin == getMaskLength() ? pos.begin - 1 : pos.begin);
  916. } else if (opts.insertMode == false && !e.shiftKey) {
  917. if (k == opts.keyCode.RIGHT) {
  918. setTimeout(function () {
  919. var caretPos = caret(input);
  920. caret(input, caretPos.begin);
  921. }, 0);
  922. } else if (k == opts.keyCode.LEFT) {
  923. setTimeout(function () {
  924. var caretPos = caret(input);
  925. caret(input, caretPos.begin - 1);
  926. }, 0);
  927. }
  928. }
  929. var currentCaretPos = caret(input);
  930. var keydownResult = opts.onKeyDown.call(this, e, getBuffer(), opts);
  931. if (keydownResult && keydownResult["refreshFromBuffer"] === true) { //extra stuff to execute on keydown
  932. getMaskSet()["validPositions"] = {};
  933. getMaskSet()["tests"] = {};
  934. refreshFromBuffer(0, getBuffer().length);
  935. resetMaskSet(true);
  936. writeBuffer(input, getBuffer());
  937. caret(input, currentCaretPos.begin, currentCaretPos.end);
  938. }
  939. ignorable = $.inArray(k, opts.ignorables) != -1;
  940. }
  941. function keypressEvent(e, checkval, k, writeOut, strict, ndx) {
  942. //Safari 5.1.x - modal dialog fires keypress twice workaround
  943. if (k == undefined && skipKeyPressEvent) return false;
  944. skipKeyPressEvent = true;
  945. var input = this, $input = $(input);
  946. e = e || window.event;
  947. var k = checkval ? k : (e.which || e.charCode || e.keyCode);
  948. if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) {
  949. return true;
  950. } else {
  951. if (k) {
  952. //special treat the decimal separator
  953. if (checkval !== true && k == 46 && e.shiftKey == false && opts.radixPoint == ",") k = 44;
  954. var pos, forwardPosition, c = String.fromCharCode(k);
  955. if (checkval) {
  956. var pcaret = strict ? ndx : getLastValidPosition() + 1;
  957. pos = { begin: pcaret, end: pcaret };
  958. } else {
  959. pos = caret(input);
  960. }
  961. //should we clear a possible selection??
  962. var isSlctn = isSelection(pos.begin, pos.end);
  963. if (isSlctn) {
  964. getMaskSet()["undoPositions"] = $.extend(true, {}, getMaskSet()["validPositions"]); //init undobuffer for recovery when not valid
  965. HandleRemove(input, opts.keyCode.DELETE, pos);
  966. if (!opts.insertMode) { //preserve some space
  967. opts.insertMode = !opts.insertMode;
  968. setValidPosition(pos.begin, strict);
  969. opts.insertMode = !opts.insertMode;
  970. }
  971. isSlctn = !opts.multi;
  972. }
  973. getMaskSet()["writeOutBuffer"] = true;
  974. var p = pos.begin;
  975. var valResult = isValid(p, c, strict);
  976. if (valResult !== false) {
  977. if (valResult !== true) {
  978. p = valResult.pos != undefined ? valResult.pos : p; //set new position from isValid
  979. c = valResult.c != undefined ? valResult.c : c; //set new char from isValid
  980. }
  981. resetMaskSet(true);
  982. if (valResult.caret != undefined)
  983. forwardPosition = valResult.caret;
  984. else {
  985. var vps = getMaskSet()["validPositions"];
  986. if (vps[p + 1] != undefined && getTestTemplate(pos + 1, vps[p].locator.slice(), p)["match"].def != vps[p + 1]["match"].def)
  987. forwardPosition = p + 1;
  988. else forwardPosition = seekNext(p);
  989. }
  990. getMaskSet()["p"] = forwardPosition; //needed for checkval
  991. }
  992. if (writeOut !== false) {
  993. var self = this;
  994. setTimeout(function () { opts.onKeyValidation.call(self, valResult, opts); }, 0);
  995. if (getMaskSet()["writeOutBuffer"] && valResult !== false) {
  996. var buffer = getBuffer();
  997. writeBuffer(input, buffer, checkval ? undefined : opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
  998. if (checkval !== true) {
  999. setTimeout(function () { //timeout needed for IE
  1000. if (isComplete(buffer) === true)
  1001. $input.trigger("complete");
  1002. skipInputEvent = true;
  1003. $input.trigger("input");
  1004. }, 0);
  1005. }
  1006. } else if (isSlctn) {
  1007. getMaskSet()["buffer"] = undefined;
  1008. getMaskSet()["validPositions"] = getMaskSet()["undoPositions"];
  1009. }
  1010. } else if (isSlctn) {
  1011. getMaskSet()["buffer"] = undefined;
  1012. getMaskSet()["validPositions"] = getMaskSet()["undoPositions"];
  1013. }
  1014. if (opts.showTooltip) { //update tooltip
  1015. $input.prop("title", getMaskSet()["mask"]);
  1016. }
  1017. //needed for IE8 and below
  1018. if (e && checkval != true) e.preventDefault ? e.preventDefault() : e.returnValue = false;
  1019. }
  1020. }
  1021. }
  1022. function keyupEvent(e) {
  1023. var $input = $(this), input = this, k = e.keyCode, buffer = getBuffer();
  1024. var keyupResult = opts.onKeyUp.call(this, e, buffer, opts);
  1025. if (keyupResult && keyupResult["refreshFromBuffer"] === true) {
  1026. getMaskSet()["validPositions"] = {};
  1027. getMaskSet()["tests"] = {};
  1028. refreshFromBuffer(0, getBuffer().length);
  1029. resetMaskSet(true);
  1030. writeBuffer(input, getBuffer());
  1031. }
  1032. if (k == opts.keyCode.TAB && opts.showMaskOnFocus) {
  1033. if ($input.hasClass('focus.inputmask') && input._valueGet().length == 0) {
  1034. resetMaskSet();
  1035. buffer = getBuffer();
  1036. writeBuffer(input, buffer);
  1037. caret(input, 0);
  1038. valueOnFocus = getBuffer().join('');
  1039. } else {
  1040. writeBuffer(input, buffer);
  1041. caret(input, TranslatePosition(0), TranslatePosition(getMaskLength()));
  1042. }
  1043. }
  1044. }
  1045. function pasteEvent(e) {
  1046. if (skipInputEvent === true && e.type == "input") {
  1047. skipInputEvent = false;
  1048. return true;
  1049. }
  1050. var input = this, $input = $(input);
  1051. //paste event for IE8 and lower I guess ;-)
  1052. if (e.type == "propertychange" && input._valueGet().length <= getMaskLength()) {
  1053. return true;
  1054. }
  1055. setTimeout(function () {
  1056. var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, input._valueGet(), opts) : input._valueGet();
  1057. checkVal(input, true, false, pasteValue.split(''), true);
  1058. if (isComplete(getBuffer()) === true)
  1059. $input.trigger("complete");
  1060. $input.click();
  1061. }, 0);
  1062. }
  1063. function mobileInputEvent(e) {
  1064. if (skipInputEvent === true && e.type == "input") {
  1065. skipInputEvent = false;
  1066. return true;
  1067. }
  1068. var input = this;
  1069. //backspace in chrome32 only fires input event - detect & treat
  1070. var caretPos = caret(input),
  1071. currentValue = input._valueGet();
  1072. currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*"), "");
  1073. //correct caretposition for chrome
  1074. if (caretPos.begin > currentValue.length) {
  1075. caret(input, currentValue.length);
  1076. caretPos = caret(input);
  1077. }
  1078. if ((getBuffer().length - currentValue.length) == 1 && currentValue.charAt(caretPos.begin) != getBuffer()[caretPos.begin]
  1079. && currentValue.charAt(caretPos.begin + 1) != getBuffer()[caretPos.begin]
  1080. && !isMask(caretPos.begin)) {
  1081. e.keyCode = opts.keyCode.BACKSPACE;
  1082. keydownEvent.call(input, e);
  1083. }
  1084. e.preventDefault();
  1085. }
  1086. function mask(el) {
  1087. $el = $(el);
  1088. if ($el.is(":input")) {
  1089. //store tests & original buffer in the input element - used to get the unmasked value
  1090. $el.data('_inputmask', {
  1091. 'maskset': maskset,
  1092. 'opts': opts,
  1093. 'isRTL': false
  1094. });
  1095. //show tooltip
  1096. if (opts.showTooltip) {
  1097. $el.prop("title", getMaskSet()["mask"]);
  1098. }
  1099. patchValueProperty(el);
  1100. if (el.dir == "rtl" || opts.rightAlign)
  1101. $el.css("text-align", "right");
  1102. if (el.dir == "rtl" || opts.numericInput) {
  1103. el.dir = "ltr";
  1104. $el.removeAttr("dir");
  1105. var inputData = $el.data('_inputmask');
  1106. inputData['isRTL'] = true;
  1107. $el.data('_inputmask', inputData);
  1108. isRTL = true;
  1109. }
  1110. //unbind all events - to make sure that no other mask will interfere when re-masking
  1111. $el.unbind(".inputmask");
  1112. $el.removeClass('focus.inputmask');
  1113. //bind events
  1114. $el.closest('form').bind("submit", function () { //trigger change on submit if any
  1115. if (valueOnFocus != getBuffer().join('')) {
  1116. $el.change();
  1117. }
  1118. }).bind('reset', function () {
  1119. setTimeout(function () {
  1120. $el.trigger("setvalue");
  1121. }, 0);
  1122. });
  1123. $el.bind("mouseenter.inputmask", function () {
  1124. var $input = $(this), input = this;
  1125. if (!$input.hasClass('focus.inputmask') && opts.showMaskOnHover) {
  1126. if (input._valueGet() != getBuffer().join('')) {
  1127. writeBuffer(input, getBuffer());
  1128. }
  1129. }
  1130. }).bind("blur.inputmask", function () {
  1131. var $input = $(this), input = this;
  1132. if ($input.data('_inputmask')) {
  1133. var nptValue = input._valueGet(), buffer = getBuffer();
  1134. $input.removeClass('focus.inputmask');
  1135. if (valueOnFocus != getBuffer().join('')) {
  1136. $input.change();
  1137. }
  1138. if (opts.clearMaskOnLostFocus && nptValue != '') {
  1139. if (nptValue == getBufferTemplate().join(''))
  1140. input._valueSet('');
  1141. else { //clearout optional tail of the mask
  1142. clearOptionalTail(input);
  1143. }
  1144. }
  1145. if (isComplete(buffer) === false) {
  1146. $input.trigger("incomplete");
  1147. if (opts.clearIncomplete) {
  1148. resetMaskSet();
  1149. if (opts.clearMaskOnLostFocus)
  1150. input._valueSet('');
  1151. else {
  1152. buffer = getBufferTemplate().slice();
  1153. writeBuffer(input, buffer);
  1154. }
  1155. }
  1156. }
  1157. }
  1158. }).bind("focus.inputmask", function () {
  1159. var $input = $(this), input = this, nptValue = input._valueGet();
  1160. if (opts.showMaskOnFocus && !$input.hasClass('focus.inputmask') && (!opts.showMaskOnHover || (opts.showMaskOnHover && nptValue == ''))) {
  1161. if (input._valueGet() != getBuffer().join('')) {
  1162. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
  1163. }
  1164. }
  1165. $input.addClass('focus.inputmask');
  1166. valueOnFocus = getBuffer().join('');
  1167. }).bind("mouseleave.inputmask", function () {
  1168. var $input = $(this), input = this;
  1169. if (opts.clearMaskOnLostFocus) {
  1170. if (!$input.hasClass('focus.inputmask') && input._valueGet() != $input.attr("placeholder")) {
  1171. if (input._valueGet() == getBufferTemplate().join('') || input._valueGet() == '')
  1172. input._valueSet('');
  1173. else { //clearout optional tail of the mask
  1174. clearOptionalTail(input);
  1175. }
  1176. }
  1177. }
  1178. }).bind("click.inputmask", function () {
  1179. var input = this;
  1180. setTimeout(function () {
  1181. var selectedCaret = caret(input), buffer = getBuffer();
  1182. if (selectedCaret.begin == selectedCaret.end) {
  1183. var clickPosition = isRTL ? TranslatePosition(selectedCaret.begin) : selectedCaret.begin,
  1184. lvp = getLastValidPosition(clickPosition),
  1185. lastPosition = seekNext(lvp);
  1186. if (clickPosition < lastPosition) {
  1187. if (isMask(clickPosition))
  1188. caret(input, clickPosition);
  1189. else caret(input, seekNext(clickPosition));
  1190. } else
  1191. caret(input, lastPosition);
  1192. }
  1193. }, 0);
  1194. }).bind('dblclick.inputmask', function () {
  1195. var input = this;
  1196. setTimeout(function () {
  1197. caret(input, 0, seekNext(getLastValidPosition()));
  1198. }, 0);
  1199. }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent
  1200. ).bind('setvalue.inputmask', function () {
  1201. var input = this;
  1202. checkVal(input, true);
  1203. valueOnFocus = getBuffer().join('');
  1204. if (input._valueGet() == getBufferTemplate().join(''))
  1205. input._valueSet('');
  1206. }).bind('complete.inputmask', opts.oncomplete
  1207. ).bind('incomplete.inputmask', opts.onincomplete
  1208. ).bind('cleared.inputmask', opts.oncleared);
  1209. $el.bind("keydown.inputmask", keydownEvent
  1210. ).bind("keypress.inputmask", keypressEvent
  1211. ).bind("keyup.inputmask", keyupEvent);
  1212. if (android || androidfirefox || androidchrome || kindle) {
  1213. if (PasteEventType == "input") {
  1214. $el.unbind(PasteEventType + ".inputmask");
  1215. }
  1216. $el.bind("input.inputmask", mobileInputEvent);
  1217. }
  1218. if (msie1x)
  1219. $el.bind("input.inputmask", pasteEvent);
  1220. //apply mask
  1221. var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) : el._valueGet();
  1222. checkVal(el, true, false, initialValue.split(''), true);
  1223. valueOnFocus = getBuffer().join('');
  1224. // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
  1225. var activeElement;
  1226. try {
  1227. activeElement = document.activeElement;
  1228. } catch (e) {
  1229. }
  1230. if (activeElement === el) { //position the caret when in focus
  1231. $el.addClass('focus.inputmask');
  1232. caret(el, seekNext(getLastValidPosition()));
  1233. } else if (opts.clearMaskOnLostFocus) {
  1234. if (getBuffer().join('') == getBufferTemplate().join('')) {
  1235. el._valueSet('');
  1236. } else {
  1237. clearOptionalTail(el);
  1238. }
  1239. } else {
  1240. writeBuffer(el, getBuffer());
  1241. }
  1242. installEventRuler(el);
  1243. }
  1244. }
  1245. //action object
  1246. if (actionObj != undefined) {
  1247. switch (actionObj["action"]) {
  1248. case "isComplete":
  1249. $el = $(actionObj["el"]);
  1250. maskset = $el.data('_inputmask')['maskset'];
  1251. opts = $el.data('_inputmask')['opts'];
  1252. return isComplete(actionObj["buffer"]);
  1253. case "unmaskedvalue":
  1254. $el = actionObj["$input"];
  1255. maskset = $el.data('_inputmask')['maskset'];
  1256. opts = $el.data('_inputmask')['opts'];
  1257. isRTL = actionObj["$input"].data('_inputmask')['isRTL'];
  1258. return unmaskedvalue(actionObj["$input"], actionObj["skipDatepickerCheck"]);
  1259. case "mask":
  1260. valueOnFocus = getBuffer().join('');
  1261. mask(actionObj["el"]);
  1262. break;
  1263. case "format":
  1264. $el = $({});
  1265. $el.data('_inputmask', {
  1266. 'maskset': maskset,
  1267. 'opts': opts,
  1268. 'isRTL': opts.numericInput
  1269. });
  1270. if (opts.numericInput) {
  1271. isRTL = true;
  1272. }
  1273. var valueBuffer = actionObj["value"].split('');
  1274. checkVal($el, false, false, isRTL ? valueBuffer.reverse() : valueBuffer, true);
  1275. return isRTL ? getBuffer().reverse().join('') : getBuffer().join('');
  1276. case "isValid":
  1277. $el = $({});
  1278. $el.data('_inputmask', {
  1279. 'maskset': maskset,
  1280. 'opts': opts,
  1281. 'isRTL': opts.numericInput
  1282. });
  1283. if (opts.numericInput) {
  1284. isRTL = true;
  1285. }
  1286. var valueBuffer = actionObj["value"].split('');
  1287. checkVal($el, false, true, isRTL ? valueBuffer.reverse() : valueBuffer);
  1288. return isComplete(getBuffer());
  1289. case "getemptymask":
  1290. $el = $(actionObj["el"]);
  1291. maskset = $el.data('_inputmask')['maskset'];
  1292. opts = $el.data('_inputmask')['opts'];
  1293. return getBufferTemplate();
  1294. case "remove":
  1295. var el = actionObj["el"];
  1296. $el = $(el);
  1297. maskset = $el.data('_inputmask')['maskset'];
  1298. opts = $el.data('_inputmask')['opts'];
  1299. //writeout the unmaskedvalue
  1300. el._valueSet(unmaskedvalue($el));
  1301. //unbind all events
  1302. $el.unbind(".inputmask");
  1303. $el.removeClass('focus.inputmask');
  1304. //clear data
  1305. $el.removeData('_inputmask');
  1306. //restore the value property
  1307. var valueProperty;
  1308. if (Object.getOwnPropertyDescriptor)
  1309. valueProperty = Object.getOwnPropertyDescriptor(el, "value");
  1310. if (valueProperty && valueProperty.get) {
  1311. if (el._valueGet) {
  1312. Object.defineProperty(el, "value", {
  1313. get: el._valueGet,
  1314. set: el._valueSet
  1315. });
  1316. }
  1317. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  1318. if (el._valueGet) {
  1319. el.__defineGetter__("value", el._valueGet);
  1320. el.__defineSetter__("value", el._valueSet);
  1321. }
  1322. }
  1323. try { //try catch needed for IE7 as it does not supports deleting fns
  1324. delete el._valueGet;
  1325. delete el._valueSet;
  1326. } catch (e) {
  1327. el._valueGet = undefined;
  1328. el._valueSet = undefined;
  1329. }
  1330. break;
  1331. }
  1332. }
  1333. };
  1334. $.inputmask = {
  1335. //options default
  1336. defaults: {
  1337. placeholder: "_",
  1338. optionalmarker: { start: "[", end: "]" },
  1339. quantifiermarker: { start: "{", end: "}" },
  1340. groupmarker: { start: "(", end: ")" },
  1341. alternatormarker: "|",
  1342. escapeChar: "\\",
  1343. mask: null,
  1344. oncomplete: $.noop, //executes when the mask is complete
  1345. onincomplete: $.noop, //executes when the mask is incomplete and focus is lost
  1346. oncleared: $.noop, //executes when the mask is cleared
  1347. repeat: 0, //repetitions of the mask: * ~ forever, otherwise specify an integer
  1348. greedy: true, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
  1349. autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
  1350. clearMaskOnLostFocus: true,
  1351. insertMode: true, //insert the input or overwrite the input
  1352. clearIncomplete: false, //clear the incomplete input on blur
  1353. aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
  1354. onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
  1355. onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
  1356. onBeforeMask: undefined, //executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
  1357. onBeforePaste: undefined, //executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
  1358. onUnMask: undefined, //executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
  1359. showMaskOnFocus: true, //show the mask-placeholder when the input has focus
  1360. showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
  1361. onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
  1362. skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
  1363. showTooltip: false, //show the activemask as tooltip
  1364. numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
  1365. getLastValidPosition: undefined, //override getLastValidPosition - args => maskset, closestTo, opts - return position (int)
  1366. rightAlign: false, //align to the right
  1367. //numeric basic properties
  1368. radixPoint: "", //".", // | ","
  1369. //numeric basic properties
  1370. definitions: {
  1371. '9': {
  1372. validator: "[0-9]",
  1373. cardinality: 1,
  1374. definitionSymbol: "*"
  1375. },
  1376. 'a': {
  1377. validator: "[A-Za-z\u0410-\u044F\u0401\u0451]",
  1378. cardinality: 1,
  1379. definitionSymbol: "*"
  1380. },
  1381. '*': {
  1382. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1383. cardinality: 1
  1384. }
  1385. },
  1386. keyCode: {
  1387. ALT: 18, BACKSPACE: 8, CAPS_LOCK: 20, COMMA: 188, COMMAND: 91, COMMAND_LEFT: 91, COMMAND_RIGHT: 93, CONTROL: 17, DELETE: 46, DOWN: 40, END: 35, ENTER: 13, ESCAPE: 27, HOME: 36, INSERT: 45, LEFT: 37, MENU: 93, NUMPAD_ADD: 107, NUMPAD_DECIMAL: 110, NUMPAD_DIVIDE: 111, NUMPAD_ENTER: 108,
  1388. NUMPAD_MULTIPLY: 106, NUMPAD_SUBTRACT: 109, PAGE_DOWN: 34, PAGE_UP: 33, PERIOD: 190, RIGHT: 39, SHIFT: 16, SPACE: 32, TAB: 9, UP: 38, WINDOWS: 91
  1389. },
  1390. //specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
  1391. ignorables: [8, 9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
  1392. isComplete: undefined //override for isComplete - args => buffer, opts - return true || false
  1393. },
  1394. masksCache: {},
  1395. escapeRegex: function (str) {
  1396. var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
  1397. return str.replace(new RegExp('(\\' + specials.join('|\\') + ')', 'gim'), '\\$1');
  1398. },
  1399. format: function (value, options) {
  1400. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1401. resolveAlias(opts.alias, options, opts);
  1402. return maskScope({ "action": "format", "value": value }, generateMaskSet(opts), opts);
  1403. },
  1404. isValid: function (value, options) {
  1405. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1406. resolveAlias(opts.alias, options, opts);
  1407. return maskScope({ "action": "isValid", "value": value }, generateMaskSet(opts), opts);
  1408. }
  1409. };
  1410. $.fn.inputmask = function (fn, options, targetScope, targetData, msk) {
  1411. targetScope = targetScope || maskScope;
  1412. targetData = targetData || "_inputmask";
  1413. function importAttributeOptions(npt, opts) {
  1414. var $npt = $(npt);
  1415. for (var option in opts) {
  1416. var optionData = $npt.data("inputmask-" + option.toLowerCase());
  1417. if (optionData != undefined)
  1418. opts[option] = optionData;
  1419. }
  1420. return opts;
  1421. }
  1422. var opts = $.extend(true, {}, $.inputmask.defaults, options),
  1423. maskset;
  1424. if (typeof fn === "string") {
  1425. switch (fn) {
  1426. case "mask":
  1427. //resolve possible aliases given by options
  1428. resolveAlias(opts.alias, options, opts);
  1429. maskset = generateMaskSet(opts);
  1430. if (maskset.length == 0) { return this; }
  1431. return this.each(function () {
  1432. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), importAttributeOptions(this, opts));
  1433. });
  1434. case "unmaskedvalue":
  1435. var $input = $(this);
  1436. if ($input.data(targetData)) {
  1437. return targetScope({ "action": "unmaskedvalue", "$input": $input });
  1438. } else return $input.val();
  1439. case "remove":
  1440. return this.each(function () {
  1441. var $input = $(this);
  1442. if ($input.data(targetData)) {
  1443. targetScope({ "action": "remove", "el": this });
  1444. }
  1445. });
  1446. case "getemptymask": //return the default (empty) mask value, usefull for setting the default value in validation
  1447. if (this.data(targetData)) {
  1448. return targetScope({ "action": "getemptymask", "el": this });
  1449. }
  1450. else return "";
  1451. case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
  1452. return this.data(targetData) ? !this.data(targetData)['opts'].autoUnmask : false;
  1453. case "isComplete":
  1454. if (this.data(targetData)) {
  1455. return targetScope({ "action": "isComplete", "buffer": this[0]._valueGet().split(''), "el": this });
  1456. } else return true;
  1457. case "getmetadata": //return mask metadata if exists
  1458. if (this.data(targetData)) {
  1459. maskset = this.data(targetData)['maskset'];
  1460. return maskset['metadata'];
  1461. }
  1462. else return undefined;
  1463. case "_detectScope":
  1464. resolveAlias(opts.alias, options, opts);
  1465. if (msk != undefined && !resolveAlias(msk, options, opts) && $.inArray(msk, ["mask", "unmaskedvalue", "remove", "getemptymask", "hasMaskedValue", "isComplete", "getmetadata", "_detectScope"]) == -1) {
  1466. opts.mask = msk;
  1467. }
  1468. if ($.isFunction(opts.mask)) {
  1469. opts.mask = opts.mask.call(this, opts);
  1470. }
  1471. return $.isArray(opts.mask);
  1472. default:
  1473. //check if the fn is an alias
  1474. if (!resolveAlias(fn, options, opts)) {
  1475. //maybe fn is a mask so we try
  1476. //set mask
  1477. opts.mask = fn;
  1478. }
  1479. maskset = generateMaskSet(opts);
  1480. if (maskset == undefined) { return this; }
  1481. return this.each(function () {
  1482. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), importAttributeOptions(this, opts));
  1483. });
  1484. }
  1485. } else if (typeof fn == "object") {
  1486. opts = $.extend(true, {}, $.inputmask.defaults, fn);
  1487. resolveAlias(opts.alias, fn, opts); //resolve aliases
  1488. maskset = generateMaskSet(opts);
  1489. if (maskset == undefined) { return this; }
  1490. return this.each(function () {
  1491. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), importAttributeOptions(this, opts));
  1492. });
  1493. } else if (fn == undefined) {
  1494. //look for data-inputmask atribute - the attribute should only contain optipns
  1495. return this.each(function () {
  1496. var attrOptions = $(this).attr("data-inputmask");
  1497. if (attrOptions && attrOptions != "") {
  1498. try {
  1499. attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
  1500. var dataoptions = $.parseJSON("{" + attrOptions + "}");
  1501. $.extend(true, dataoptions, options);
  1502. opts = $.extend(true, {}, $.inputmask.defaults, dataoptions);
  1503. resolveAlias(opts.alias, dataoptions, opts);
  1504. opts.alias = undefined;
  1505. $(this).inputmask("mask", opts, targetScope);
  1506. } catch (ex) { } //need a more relax parseJSON
  1507. }
  1508. });
  1509. }
  1510. };
  1511. }
  1512. })(jQuery);
  1513. /**
  1514. * @license Input Mask plugin for jquery
  1515. * http://github.com/RobinHerbots/jquery.inputmask
  1516. * Copyright (c) 2010 - 2014 Robin Herbots
  1517. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1518. * Version: 3.0.31
  1519. */
  1520. (function ($) {
  1521. if ($.fn.inputmask != undefined) {
  1522. function multiMaskScope(actionObj, masksets, opts) {
  1523. function isInputEventSupported(eventName) {
  1524. var el = document.createElement('input'),
  1525. eventName = 'on' + eventName,
  1526. isSupported = (eventName in el);
  1527. if (!isSupported) {
  1528. el.setAttribute(eventName, 'return;');
  1529. isSupported = typeof el[eventName] == 'function';
  1530. }
  1531. el = null;
  1532. return isSupported;
  1533. }
  1534. var PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange",
  1535. isRTL, el, $el, elmasks, activeMasksetIndex;
  1536. function PatchValhookMulti(type) {
  1537. if ($.valHooks[type] == undefined || $.valHooks[type].inputmaskmultipatch != true) {
  1538. var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) { return elem.value; };
  1539. var valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
  1540. elem.value = value;
  1541. return elem;
  1542. };
  1543. $.valHooks[type] = {
  1544. get: function (elem) {
  1545. var $elem = $(elem);
  1546. if ($elem.data('_inputmask-multi')) {
  1547. var data = $elem.data('_inputmask-multi');
  1548. return valueGet(data["elmasks"][data["activeMasksetIndex"]]);
  1549. } else return valueGet(elem);
  1550. },
  1551. set: function (elem, value) {
  1552. var $elem = $(elem);
  1553. var result = valueSet(elem, value);
  1554. if ($elem.data('_inputmask-multi')) $elem.triggerHandler('setvalue');
  1555. return result;
  1556. },
  1557. inputmaskmultipatch: true
  1558. };
  1559. }
  1560. }
  1561. function mcaret(input, begin, end) {
  1562. var npt = input.jquery && input.length > 0 ? input[0] : input, range;
  1563. if (typeof begin == 'number') {
  1564. begin = TranslatePosition(begin);
  1565. end = TranslatePosition(end);
  1566. end = (typeof end == 'number') ? end : begin;
  1567. //store caret for multi scope
  1568. if (npt != el) {
  1569. var data = $(npt).data('_inputmask') || {};
  1570. data["caret"] = { "begin": begin, "end": end };
  1571. $(npt).data('_inputmask', data);
  1572. }
  1573. if (!$(npt).is(":visible")) {
  1574. return;
  1575. }
  1576. npt.scrollLeft = npt.scrollWidth;
  1577. if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
  1578. if (npt.setSelectionRange) {
  1579. npt.selectionStart = begin;
  1580. npt.selectionEnd = end;
  1581. } else if (npt.createTextRange) {
  1582. range = npt.createTextRange();
  1583. range.collapse(true);
  1584. range.moveEnd('character', end);
  1585. range.moveStart('character', begin);
  1586. range.select();
  1587. }
  1588. } else {
  1589. var data = $(npt).data('_inputmask');
  1590. if (!$(npt).is(":visible") && data && data["caret"] != undefined) {
  1591. begin = data["caret"]["begin"];
  1592. end = data["caret"]["end"];
  1593. } else if (npt.setSelectionRange) {
  1594. begin = npt.selectionStart;
  1595. end = npt.selectionEnd;
  1596. } else if (document.selection && document.selection.createRange) {
  1597. range = document.selection.createRange();
  1598. begin = 0 - range.duplicate().moveStart('character', -100000);
  1599. end = begin + range.text.length;
  1600. }
  1601. begin = TranslatePosition(begin);
  1602. end = TranslatePosition(end);
  1603. return { "begin": begin, "end": end };
  1604. }
  1605. }
  1606. function TranslatePosition(pos) {
  1607. if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
  1608. var bffrLght = el.value.length;
  1609. pos = bffrLght - pos;
  1610. }
  1611. return pos;
  1612. }
  1613. function determineActiveMask(eventType, elmasks) {
  1614. if (eventType != "multiMaskScope") {
  1615. if ($.isFunction(opts.determineActiveMasksetIndex))
  1616. activeMasksetIndex = opts.determineActiveMasksetIndex.call($el, eventType, elmasks);
  1617. else {
  1618. var lpc = -1, cp = -1, lvp = -1;;
  1619. $.each(elmasks, function (ndx, lmsk) {
  1620. var data = $(lmsk).data('_inputmask');
  1621. var maskset = data["maskset"];
  1622. var lastValidPosition = -1, validPositionCount = 0, caretPos = mcaret(lmsk).begin;
  1623. for (var posNdx in maskset["validPositions"]) {
  1624. var psNdx = parseInt(posNdx);
  1625. if (psNdx > lastValidPosition) lastValidPosition = psNdx;
  1626. validPositionCount++;
  1627. }
  1628. if (validPositionCount > lpc
  1629. || (validPositionCount == lpc && cp > caretPos && lvp > lastValidPosition)
  1630. || (validPositionCount == lpc && cp == caretPos && lvp < lastValidPosition)
  1631. ) {
  1632. //console.log("lvp " + lastValidPosition + " vpc " + validPositionCount + " caret " + caretPos + " ams " + ndx);
  1633. lpc = validPositionCount;
  1634. cp = caretPos;
  1635. activeMasksetIndex = ndx;
  1636. lvp = lastValidPosition;
  1637. }
  1638. });
  1639. }
  1640. var data = $el.data('_inputmask-multi') || { "activeMasksetIndex": 0, "elmasks": elmasks };
  1641. data["activeMasksetIndex"] = activeMasksetIndex;
  1642. $el.data('_inputmask-multi', data);
  1643. }
  1644. if ($.inArray(eventType, ["focus"]) == -1 && el.value != elmasks[activeMasksetIndex]._valueGet()) {
  1645. var value = $(elmasks[activeMasksetIndex]).val() == "" ? elmasks[activeMasksetIndex]._valueGet() : $(elmasks[activeMasksetIndex]).val();
  1646. el.value = value;
  1647. }
  1648. if ($.inArray(eventType, ["blur", "focus"]) == -1) {
  1649. if ($(elmasks[activeMasksetIndex]).hasClass("focus.inputmask")) {
  1650. var activeCaret = mcaret(elmasks[activeMasksetIndex]);
  1651. mcaret(el, activeCaret.begin, activeCaret.end);
  1652. }
  1653. }
  1654. }
  1655. opts.multi = true;
  1656. function mask(npt) {
  1657. el = npt;
  1658. $el = $(el);
  1659. isRTL = el.dir == "rtl" || opts.numericInput;
  1660. activeMasksetIndex = 0;
  1661. elmasks = $.map(masksets, function (msk, ndx) {
  1662. var elMaskStr = '<input type="text" ';
  1663. if ($el.attr("value")) elMaskStr += 'value="' + $el.attr("value") + '" ';
  1664. if ($el.attr("dir")) elMaskStr += 'dir="' + $el.attr("dir") + '" ';
  1665. elMaskStr += '/>';
  1666. var elmask = $(elMaskStr)[0];
  1667. $(elmask).inputmask($.extend({}, opts, { mask: msk.mask }));
  1668. return elmask;
  1669. });
  1670. $el.data('_inputmask-multi', { "activeMasksetIndex": 0, "elmasks": elmasks });
  1671. if (el.dir == "rtl" || opts.rightAlign)
  1672. $el.css("text-align", "right");
  1673. el.dir = "ltr";
  1674. $el.removeAttr("dir");
  1675. if ($el.attr("value") != "") {
  1676. determineActiveMask("init", elmasks);
  1677. }
  1678. $el.bind("mouseenter blur focus mouseleave click dblclick keydown keypress keypress", function (e) {
  1679. var caretPos = mcaret(el), k, goDetermine = true;
  1680. if (e.type == "keydown") {
  1681. k = e.keyCode;
  1682. if (k == opts.keyCode.DOWN && activeMasksetIndex < elmasks.length - 1) {
  1683. activeMasksetIndex++;
  1684. determineActiveMask("multiMaskScope", elmasks);
  1685. return false;
  1686. } else if (k == opts.keyCode.UP && activeMasksetIndex > 0) {
  1687. activeMasksetIndex--;
  1688. determineActiveMask("multiMaskScope", elmasks);
  1689. return false;
  1690. }
  1691. if (e.ctrlKey || e.shiftKey || e.altKey) {
  1692. return true;
  1693. }
  1694. } else if (e.type == "keypress" && (e.ctrlKey || e.shiftKey || e.altKey)) {
  1695. return true;
  1696. }
  1697. $.each(elmasks, function (ndx, lmnt) {
  1698. if (e.type == "keydown") {
  1699. k = e.keyCode;
  1700. if (k == opts.keyCode.BACKSPACE && lmnt._valueGet().length < caretPos.begin) {
  1701. return;
  1702. } else if (k == opts.keyCode.TAB) {
  1703. goDetermine = false;
  1704. } else if (k == opts.keyCode.RIGHT) {
  1705. mcaret(lmnt, caretPos.begin + 1, caretPos.end + 1);
  1706. goDetermine = false;
  1707. return;
  1708. } else if (k == opts.keyCode.LEFT) {
  1709. mcaret(lmnt, caretPos.begin - 1, caretPos.end - 1);
  1710. goDetermine = false;
  1711. return;
  1712. }
  1713. }
  1714. if ($.inArray(e.type, ["click"]) != -1) {
  1715. mcaret(lmnt, TranslatePosition(caretPos.begin), TranslatePosition(caretPos.end));
  1716. if (caretPos.begin != caretPos.end) {
  1717. goDetermine = false;
  1718. return;
  1719. }
  1720. }
  1721. if ($.inArray(e.type, ["keydown"]) != -1 && caretPos.begin != caretPos.end) {
  1722. mcaret(lmnt, caretPos.begin, caretPos.end);
  1723. }
  1724. $(lmnt).triggerHandler(e);
  1725. });
  1726. if (goDetermine) {
  1727. setTimeout(function () {
  1728. determineActiveMask(e.type, elmasks);
  1729. }, 0);
  1730. }
  1731. });
  1732. $el.bind(PasteEventType + " dragdrop drop setvalue", function (e) {
  1733. var caretPos = mcaret(el);
  1734. setTimeout(function () {
  1735. $.each(elmasks, function (ndx, lmnt) {
  1736. lmnt._valueSet(el.value);
  1737. $(lmnt).triggerHandler(e);
  1738. });
  1739. setTimeout(function () {
  1740. determineActiveMask(e.type, elmasks);
  1741. }, 0);
  1742. }, 0);
  1743. });
  1744. PatchValhookMulti(el.type);
  1745. }
  1746. //action object
  1747. if (actionObj != undefined) {
  1748. switch (actionObj["action"]) {
  1749. case "isComplete":
  1750. $el = $(actionObj["el"]);
  1751. var imdata = $el.data('_inputmask-multi'),
  1752. activeMask = imdata["elmasks"][imdata["activeMasksetIndex"]];
  1753. return $(activeMask).inputmask("isComplete");
  1754. case "unmaskedvalue":
  1755. $el = actionObj["$input"];
  1756. var imdata = $el.data('_inputmask-multi'),
  1757. activeMask = imdata["elmasks"][imdata["activeMasksetIndex"]];
  1758. return $(activeMask).inputmask("unmaskedvalue");
  1759. case "mask":
  1760. mask(actionObj["el"]);
  1761. break;
  1762. case "format": //TODO
  1763. $el = $({});
  1764. $el.data('_inputmask', {
  1765. 'maskset': maskset,
  1766. 'opts': opts,
  1767. 'isRTL': opts.numericInput
  1768. });
  1769. if (opts.numericInput) {
  1770. isRTL = true;
  1771. }
  1772. var valueBuffer = actionObj["value"].split('');
  1773. checkVal($el, false, false, isRTL ? valueBuffer.reverse() : valueBuffer, true);
  1774. return isRTL ? getBuffer().reverse().join('') : getBuffer().join('');
  1775. case "isValid": //TODO
  1776. $el = $({});
  1777. $el.data('_inputmask', {
  1778. 'maskset': maskset,
  1779. 'opts': opts,
  1780. 'isRTL': opts.numericInput
  1781. });
  1782. if (opts.numericInput) {
  1783. isRTL = true;
  1784. }
  1785. var valueBuffer = actionObj["value"].split('');
  1786. checkVal($el, false, true, isRTL ? valueBuffer.reverse() : valueBuffer);
  1787. return isComplete(getBuffer());
  1788. case "getemptymask": //TODO
  1789. $el = $(actionObj["el"]);
  1790. maskset = $el.data('_inputmask')['maskset'];
  1791. opts = $el.data('_inputmask')['opts'];
  1792. return getBufferTemplate();
  1793. case "remove": //TODO
  1794. var el = actionObj["el"];
  1795. $el = $(el);
  1796. maskset = $el.data('_inputmask')['maskset'];
  1797. opts = $el.data('_inputmask')['opts'];
  1798. //writeout the unmaskedvalue
  1799. el._valueSet(unmaskedvalue($el));
  1800. //unbind all events
  1801. $el.unbind(".inputmask");
  1802. $el.removeClass('focus.inputmask');
  1803. //clear data
  1804. $el.removeData('_inputmask');
  1805. //restore the value property
  1806. var valueProperty;
  1807. if (Object.getOwnPropertyDescriptor)
  1808. valueProperty = Object.getOwnPropertyDescriptor(el, "value");
  1809. if (valueProperty && valueProperty.get) {
  1810. if (el._valueGet) {
  1811. Object.defineProperty(el, "value", {
  1812. get: el._valueGet,
  1813. set: el._valueSet
  1814. });
  1815. }
  1816. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  1817. if (el._valueGet) {
  1818. el.__defineGetter__("value", el._valueGet);
  1819. el.__defineSetter__("value", el._valueSet);
  1820. }
  1821. }
  1822. try { //try catch needed for IE7 as it does not supports deleting fns
  1823. delete el._valueGet;
  1824. delete el._valueSet;
  1825. } catch (e) {
  1826. el._valueGet = undefined;
  1827. el._valueSet = undefined;
  1828. }
  1829. break;
  1830. }
  1831. }
  1832. };
  1833. $.extend($.inputmask.defaults, {
  1834. //multi-masks
  1835. multi: false, //do not alter - internal use
  1836. nojumps: false, //do not jump over fixed parts in the mask
  1837. nojumpsThreshold: 0, //start nojumps as of
  1838. determineActiveMasksetIndex: undefined //override determineActiveMasksetIndex - args => eventType, elmasks - return int
  1839. });
  1840. $.inputmask._fn = $.fn.inputmask;
  1841. $.fn.inputmask = function (fn, options) {
  1842. if (typeof fn === "string") {
  1843. if ($.inputmask._fn("_detectScope", options, undefined, undefined, fn))
  1844. return $.inputmask._fn.call(this, fn, options, multiMaskScope, "_inputmask-multi");
  1845. else return $.inputmask._fn.call(this, fn, options);
  1846. } else if (typeof fn == "object") {
  1847. opts = $.extend(true, {}, $.inputmask.defaults, fn);
  1848. if ($.inputmask._fn("_detectScope", fn))
  1849. return $.inputmask._fn.call(this, fn, options, multiMaskScope, "_inputmask-multi");
  1850. else return $.inputmask._fn.call(this, fn, options);
  1851. } else if (fn == undefined)
  1852. return $.inputmask._fn.call(this, fn, options);
  1853. };
  1854. }
  1855. })(jQuery);
  1856. /*
  1857. Input Mask plugin extensions
  1858. http://github.com/RobinHerbots/jquery.inputmask
  1859. Copyright (c) 2010 - 2014 Robin Herbots
  1860. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1861. Version: 3.0.31
  1862. Optional extensions on the jquery.inputmask base
  1863. */
  1864. (function ($) {
  1865. //extra definitions
  1866. $.extend($.inputmask.defaults.definitions, {
  1867. 'A': {
  1868. validator: "[A-Za-z]",
  1869. cardinality: 1,
  1870. casing: "upper" //auto uppercasing
  1871. },
  1872. '#': {
  1873. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1874. cardinality: 1,
  1875. casing: "upper"
  1876. }
  1877. });
  1878. $.extend($.inputmask.defaults.aliases, {
  1879. 'url': {
  1880. mask: "ir",
  1881. placeholder: "",
  1882. separator: "",
  1883. defaultPrefix: "http://",
  1884. regex: {
  1885. urlpre1: new RegExp("[fh]"),
  1886. urlpre2: new RegExp("(ft|ht)"),
  1887. urlpre3: new RegExp("(ftp|htt)"),
  1888. urlpre4: new RegExp("(ftp:|http|ftps)"),
  1889. urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"),
  1890. urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"),
  1891. urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"),
  1892. urlpre8: new RegExp("(ftp://|ftps://|http://|https://)")
  1893. },
  1894. definitions: {
  1895. 'i': {
  1896. validator: function (chrs, buffer, pos, strict, opts) {
  1897. return true;
  1898. },
  1899. cardinality: 8,
  1900. prevalidator: (function () {
  1901. var result = [], prefixLimit = 8;
  1902. for (var i = 0; i < prefixLimit; i++) {
  1903. result[i] = (function () {
  1904. var j = i;
  1905. return {
  1906. validator: function (chrs, buffer, pos, strict, opts) {
  1907. if (opts.regex["urlpre" + (j + 1)]) {
  1908. var tmp = chrs, k;
  1909. if (((j + 1) - chrs.length) > 0) {
  1910. tmp = buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp;
  1911. }
  1912. var isValid = opts.regex["urlpre" + (j + 1)].test(tmp);
  1913. if (!strict && !isValid) {
  1914. pos = pos - j;
  1915. for (k = 0; k < opts.defaultPrefix.length; k++) {
  1916. buffer[pos] = opts.defaultPrefix[k]; pos++;
  1917. }
  1918. for (k = 0; k < tmp.length - 1; k++) {
  1919. buffer[pos] = tmp[k]; pos++;
  1920. }
  1921. return { "pos": pos };
  1922. }
  1923. return isValid;
  1924. } else {
  1925. return false;
  1926. }
  1927. }, cardinality: j
  1928. };
  1929. })();
  1930. }
  1931. return result;
  1932. })()
  1933. },
  1934. "r": {
  1935. validator: ".",
  1936. cardinality: 50
  1937. }
  1938. },
  1939. insertMode: false,
  1940. autoUnmask: false
  1941. },
  1942. "ip": { //ip-address mask
  1943. mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
  1944. definitions: {
  1945. 'i': {
  1946. validator: function (chrs, buffer, pos, strict, opts) {
  1947. if (pos - 1 > -1 && buffer[pos - 1] != ".") {
  1948. chrs = buffer[pos - 1] + chrs;
  1949. if (pos - 2 > -1 && buffer[pos - 2] != ".") {
  1950. chrs = buffer[pos - 2] + chrs;
  1951. } else chrs = "0" + chrs;
  1952. } else chrs = "00" + chrs;
  1953. return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
  1954. },
  1955. cardinality: 1
  1956. }
  1957. }
  1958. },
  1959. "email": {
  1960. mask: "*{1,20}[.*{1,20}][.*{1,20}][.*{1,20}]@*{1,20}.*{2,6}[.*{1,2}]",
  1961. greedy: false
  1962. }
  1963. });
  1964. })(jQuery);
  1965. /*
  1966. Input Mask plugin extensions
  1967. http://github.com/RobinHerbots/jquery.inputmask
  1968. Copyright (c) 2010 - 2014 Robin Herbots
  1969. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1970. Version: 3.0.31
  1971. Optional extensions on the jquery.inputmask base
  1972. */
  1973. (function ($) {
  1974. //date & time aliases
  1975. $.extend($.inputmask.defaults.definitions, {
  1976. 'h': { //hours
  1977. validator: "[01][0-9]|2[0-3]",
  1978. cardinality: 2,
  1979. prevalidator: [{ validator: "[0-2]", cardinality: 1 }]
  1980. },
  1981. 's': { //seconds || minutes
  1982. validator: "[0-5][0-9]",
  1983. cardinality: 2,
  1984. prevalidator: [{ validator: "[0-5]", cardinality: 1 }]
  1985. },
  1986. 'd': { //basic day
  1987. validator: "0[1-9]|[12][0-9]|3[01]",
  1988. cardinality: 2,
  1989. prevalidator: [{ validator: "[0-3]", cardinality: 1 }]
  1990. },
  1991. 'm': { //basic month
  1992. validator: "0[1-9]|1[012]",
  1993. cardinality: 2,
  1994. prevalidator: [{ validator: "[01]", cardinality: 1 }]
  1995. },
  1996. 'y': { //basic year
  1997. validator: "(19|20)\\d{2}",
  1998. cardinality: 4,
  1999. prevalidator: [
  2000. { validator: "[12]", cardinality: 1 },
  2001. { validator: "(19|20)", cardinality: 2 },
  2002. { validator: "(19|20)\\d", cardinality: 3 }
  2003. ]
  2004. }
  2005. });
  2006. $.extend($.inputmask.defaults.aliases, {
  2007. 'dd/mm/yyyy': {
  2008. mask: "1/2/y",
  2009. placeholder: "dd/mm/yyyy",
  2010. regex: {
  2011. val1pre: new RegExp("[0-3]"), //daypre
  2012. val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), //day
  2013. val2pre: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])"); }, //monthpre
  2014. 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]))"); }//month
  2015. },
  2016. leapday: "29/02/",
  2017. separator: '/',
  2018. yearrange: { minyear: 1900, maxyear: 2099 },
  2019. isInYearRange: function (chrs, minyear, maxyear) {
  2020. if (isNaN(chrs)) return false;
  2021. var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length)));
  2022. var enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
  2023. return (!isNaN(enteredyear) ? minyear <= enteredyear && enteredyear <= maxyear : false) ||
  2024. (!isNaN(enteredyear2) ? minyear <= enteredyear2 && enteredyear2 <= maxyear : false);
  2025. },
  2026. determinebaseyear: function (minyear, maxyear, hint) {
  2027. var currentyear = (new Date()).getFullYear();
  2028. if (minyear > currentyear) return minyear;
  2029. if (maxyear < currentyear) {
  2030. var maxYearPrefix = maxyear.toString().slice(0, 2);
  2031. var maxYearPostfix = maxyear.toString().slice(2, 4);
  2032. while (maxyear < maxYearPrefix + hint) {
  2033. maxYearPrefix--;
  2034. }
  2035. var maxxYear = maxYearPrefix + maxYearPostfix;
  2036. return minyear > maxxYear ? minyear : maxxYear;
  2037. }
  2038. return currentyear;
  2039. },
  2040. onKeyUp: function (e, buffer, opts) {
  2041. var $input = $(this);
  2042. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2043. var today = new Date();
  2044. $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString());
  2045. }
  2046. },
  2047. definitions: {
  2048. '1': { //val1 ~ day or month
  2049. validator: function (chrs, buffer, pos, strict, opts) {
  2050. var isValid = opts.regex.val1.test(chrs);
  2051. if (!strict && !isValid) {
  2052. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  2053. isValid = opts.regex.val1.test("0" + chrs.charAt(0));
  2054. if (isValid) {
  2055. buffer[pos - 1] = "0";
  2056. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "pos": pos, "c": chrs.charAt(0) };
  2057. }
  2058. }
  2059. }
  2060. return isValid;
  2061. },
  2062. cardinality: 2,
  2063. prevalidator: [{
  2064. validator: function (chrs, buffer, pos, strict, opts) {
  2065. if (!isNaN(buffer[pos + 1])) chrs += buffer[pos + 1];
  2066. var isValid = chrs.length == 1 ? opts.regex.val1pre.test(chrs) : opts.regex.val1.test(chrs);
  2067. if (!strict && !isValid) {
  2068. isValid = opts.regex.val1.test("0" + chrs);
  2069. if (isValid) {
  2070. buffer[pos] = "0";
  2071. pos++;
  2072. return { "pos": pos };
  2073. }
  2074. }
  2075. return isValid;
  2076. }, cardinality: 1
  2077. }]
  2078. },
  2079. '2': { //val2 ~ day or month
  2080. validator: function (chrs, buffer, pos, strict, opts) {
  2081. var frontValue = (opts.mask.indexOf("2") == opts.mask.length - 1) ? buffer.join('').substr(5, 3) : buffer.join('').substr(0, 3);
  2082. if (frontValue.indexOf(opts.placeholder[0]) != -1) frontValue = "01" + opts.separator;
  2083. var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
  2084. if (!strict && !isValid) {
  2085. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  2086. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
  2087. if (isValid) {
  2088. buffer[pos - 1] = "0";
  2089. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "pos": pos, "c": chrs.charAt(0) };
  2090. }
  2091. }
  2092. }
  2093. //check leap yeap
  2094. if ((opts.mask.indexOf("2") == opts.mask.length - 1) && isValid) {
  2095. var dayMonthValue = buffer.join('').substr(4, 4) + chrs;
  2096. if (dayMonthValue != opts.leapday)
  2097. return true;
  2098. else {
  2099. var year = parseInt(buffer.join('').substr(0, 4), 10); //detect leap year
  2100. if (year % 4 === 0)
  2101. if (year % 100 === 0)
  2102. if (year % 400 === 0)
  2103. return true;
  2104. else return false;
  2105. else return true;
  2106. else return false;
  2107. }
  2108. }
  2109. return isValid;
  2110. },
  2111. cardinality: 2,
  2112. prevalidator: [{
  2113. validator: function (chrs, buffer, pos, strict, opts) {
  2114. if (!isNaN(buffer[pos + 1])) chrs += buffer[pos + 1];
  2115. var frontValue = (opts.mask.indexOf("2") == opts.mask.length - 1) ? buffer.join('').substr(5, 3) : buffer.join('').substr(0, 3);
  2116. if (frontValue.indexOf(opts.placeholder[0]) != -1) frontValue = "01" + opts.separator;
  2117. var isValid = chrs.length == 1 ? opts.regex.val2pre(opts.separator).test(frontValue + chrs) : opts.regex.val2(opts.separator).test(frontValue + chrs);
  2118. if (!strict && !isValid) {
  2119. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
  2120. if (isValid) {
  2121. buffer[pos] = "0";
  2122. pos++;
  2123. return { "pos": pos };
  2124. }
  2125. }
  2126. return isValid;
  2127. }, cardinality: 1
  2128. }]
  2129. },
  2130. 'y': { //year
  2131. validator: function (chrs, buffer, pos, strict, opts) {
  2132. if (opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  2133. var dayMonthValue = buffer.join('').substr(0, 6);
  2134. if (dayMonthValue != opts.leapday)
  2135. return true;
  2136. else {
  2137. var year = parseInt(chrs, 10);//detect leap year
  2138. if (year % 4 === 0)
  2139. if (year % 100 === 0)
  2140. if (year % 400 === 0)
  2141. return true;
  2142. else return false;
  2143. else return true;
  2144. else return false;
  2145. }
  2146. } else return false;
  2147. },
  2148. cardinality: 4,
  2149. prevalidator: [
  2150. {
  2151. validator: function (chrs, buffer, pos, strict, opts) {
  2152. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2153. if (!strict && !isValid) {
  2154. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 1);
  2155. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2156. if (isValid) {
  2157. buffer[pos++] = yearPrefix[0];
  2158. return { "pos": pos };
  2159. }
  2160. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 2);
  2161. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2162. if (isValid) {
  2163. buffer[pos++] = yearPrefix[0];
  2164. buffer[pos++] = yearPrefix[1];
  2165. return { "pos": pos };
  2166. }
  2167. }
  2168. return isValid;
  2169. },
  2170. cardinality: 1
  2171. },
  2172. {
  2173. validator: function (chrs, buffer, pos, strict, opts) {
  2174. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2175. if (!strict && !isValid) {
  2176. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  2177. isValid = opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear);
  2178. if (isValid) {
  2179. buffer[pos++] = yearPrefix[1];
  2180. return { "pos": pos };
  2181. }
  2182. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  2183. if (opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  2184. var dayMonthValue = buffer.join('').substr(0, 6);
  2185. if (dayMonthValue != opts.leapday)
  2186. isValid = true;
  2187. else {
  2188. var year = parseInt(chrs, 10);//detect leap year
  2189. if (year % 4 === 0)
  2190. if (year % 100 === 0)
  2191. if (year % 400 === 0)
  2192. isValid = true;
  2193. else isValid = false;
  2194. else isValid = true;
  2195. else isValid = false;
  2196. }
  2197. } else isValid = false;
  2198. if (isValid) {
  2199. buffer[pos - 1] = yearPrefix[0];
  2200. buffer[pos++] = yearPrefix[1];
  2201. buffer[pos++] = chrs[0];
  2202. return { "refreshFromBuffer": { start: pos - 3, end: pos }, "pos": pos };
  2203. }
  2204. }
  2205. return isValid;
  2206. }, cardinality: 2
  2207. },
  2208. {
  2209. validator: function (chrs, buffer, pos, strict, opts) {
  2210. return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2211. }, cardinality: 3
  2212. }
  2213. ]
  2214. }
  2215. },
  2216. insertMode: false,
  2217. autoUnmask: false
  2218. },
  2219. 'mm/dd/yyyy': {
  2220. placeholder: "mm/dd/yyyy",
  2221. alias: "dd/mm/yyyy", //reuse functionality of dd/mm/yyyy alias
  2222. regex: {
  2223. 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])"); }, //daypre
  2224. 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)"); }, //day
  2225. val1pre: new RegExp("[01]"), //monthpre
  2226. val1: new RegExp("0[1-9]|1[012]") //month
  2227. },
  2228. leapday: "02/29/",
  2229. onKeyUp: function (e, buffer, opts) {
  2230. var $input = $(this);
  2231. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2232. var today = new Date();
  2233. $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
  2234. }
  2235. }
  2236. },
  2237. 'yyyy/mm/dd': {
  2238. mask: "y/1/2",
  2239. placeholder: "yyyy/mm/dd",
  2240. alias: "mm/dd/yyyy",
  2241. leapday: "/02/29",
  2242. onKeyUp: function (e, buffer, opts) {
  2243. var $input = $(this);
  2244. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2245. var today = new Date();
  2246. $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString());
  2247. }
  2248. }
  2249. },
  2250. 'dd.mm.yyyy': {
  2251. mask: "1.2.y",
  2252. placeholder: "dd.mm.yyyy",
  2253. leapday: "29.02.",
  2254. separator: '.',
  2255. alias: "dd/mm/yyyy"
  2256. },
  2257. 'dd-mm-yyyy': {
  2258. mask: "1-2-y",
  2259. placeholder: "dd-mm-yyyy",
  2260. leapday: "29-02-",
  2261. separator: '-',
  2262. alias: "dd/mm/yyyy"
  2263. },
  2264. 'mm.dd.yyyy': {
  2265. mask: "1.2.y",
  2266. placeholder: "mm.dd.yyyy",
  2267. leapday: "02.29.",
  2268. separator: '.',
  2269. alias: "mm/dd/yyyy"
  2270. },
  2271. 'mm-dd-yyyy': {
  2272. mask: "1-2-y",
  2273. placeholder: "mm-dd-yyyy",
  2274. leapday: "02-29-",
  2275. separator: '-',
  2276. alias: "mm/dd/yyyy"
  2277. },
  2278. 'yyyy.mm.dd': {
  2279. mask: "y.1.2",
  2280. placeholder: "yyyy.mm.dd",
  2281. leapday: ".02.29",
  2282. separator: '.',
  2283. alias: "yyyy/mm/dd"
  2284. },
  2285. 'yyyy-mm-dd': {
  2286. mask: "y-1-2",
  2287. placeholder: "yyyy-mm-dd",
  2288. leapday: "-02-29",
  2289. separator: '-',
  2290. alias: "yyyy/mm/dd"
  2291. },
  2292. 'datetime': {
  2293. mask: "1/2/y h:s",
  2294. placeholder: "dd/mm/yyyy hh:mm",
  2295. alias: "dd/mm/yyyy",
  2296. regex: {
  2297. hrspre: new RegExp("[012]"), //hours pre
  2298. hrs24: new RegExp("2[0-4]|1[3-9]"),
  2299. hrs: new RegExp("[01][0-9]|2[0-4]"), //hours
  2300. ampm: new RegExp("^[a|p|A|P][m|M]")
  2301. },
  2302. timeseparator: ':',
  2303. hourFormat: "24", // or 12
  2304. definitions: {
  2305. 'h': { //hours
  2306. validator: function (chrs, buffer, pos, strict, opts) {
  2307. if (opts.hourFormat == "24") {
  2308. if (parseInt(chrs, 10) == 24) {
  2309. buffer[pos - 1] = "0";
  2310. buffer[pos] = "0";
  2311. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "c": "0" };
  2312. }
  2313. }
  2314. var isValid = opts.regex.hrs.test(chrs);
  2315. if (!strict && !isValid) {
  2316. if (chrs.charAt(1) == opts.timeseparator || "-.:".indexOf(chrs.charAt(1)) != -1) {
  2317. isValid = opts.regex.hrs.test("0" + chrs.charAt(0));
  2318. if (isValid) {
  2319. buffer[pos - 1] = "0";
  2320. buffer[pos] = chrs.charAt(0);
  2321. pos++;
  2322. return { "refreshFromBuffer": { start: pos - 2, end: pos }, "pos": pos, "c": opts.timeseparator };
  2323. }
  2324. }
  2325. }
  2326. if (isValid && opts.hourFormat !== "24" && opts.regex.hrs24.test(chrs)) {
  2327. var tmp = parseInt(chrs, 10);
  2328. if (tmp == 24) {
  2329. buffer[pos + 5] = "a";
  2330. buffer[pos + 6] = "m";
  2331. } else {
  2332. buffer[pos + 5] = "p";
  2333. buffer[pos + 6] = "m";
  2334. }
  2335. tmp = tmp - 12;
  2336. if (tmp < 10) {
  2337. buffer[pos] = tmp.toString();
  2338. buffer[pos - 1] = "0";
  2339. } else {
  2340. buffer[pos] = tmp.toString().charAt(1);
  2341. buffer[pos - 1] = tmp.toString().charAt(0);
  2342. }
  2343. return { "refreshFromBuffer": { start: pos - 1, end: pos + 6 }, "c": buffer[pos] };
  2344. }
  2345. return isValid;
  2346. },
  2347. cardinality: 2,
  2348. prevalidator: [{
  2349. validator: function (chrs, buffer, pos, strict, opts) {
  2350. var isValid = opts.regex.hrspre.test(chrs);
  2351. if (!strict && !isValid) {
  2352. isValid = opts.regex.hrs.test("0" + chrs);
  2353. if (isValid) {
  2354. buffer[pos] = "0";
  2355. pos++;
  2356. return { "pos": pos };
  2357. }
  2358. }
  2359. return isValid;
  2360. }, cardinality: 1
  2361. }]
  2362. },
  2363. 't': { //am/pm
  2364. validator: function (chrs, buffer, pos, strict, opts) {
  2365. return opts.regex.ampm.test(chrs + "m");
  2366. },
  2367. casing: "lower",
  2368. cardinality: 1
  2369. }
  2370. },
  2371. insertMode: false,
  2372. autoUnmask: false
  2373. },
  2374. 'datetime12': {
  2375. mask: "1/2/y h:s t\\m",
  2376. placeholder: "dd/mm/yyyy hh:mm xm",
  2377. alias: "datetime",
  2378. hourFormat: "12"
  2379. },
  2380. 'hh:mm t': {
  2381. mask: "h:s t\\m",
  2382. placeholder: "hh:mm xm",
  2383. alias: "datetime",
  2384. hourFormat: "12"
  2385. },
  2386. 'h:s t': {
  2387. mask: "h:s t\\m",
  2388. placeholder: "hh:mm xm",
  2389. alias: "datetime",
  2390. hourFormat: "12"
  2391. },
  2392. 'hh:mm:ss': {
  2393. mask: "h:s:s",
  2394. autoUnmask: false
  2395. },
  2396. 'hh:mm': {
  2397. mask: "h:s",
  2398. autoUnmask: false
  2399. },
  2400. 'date': {
  2401. alias: "dd/mm/yyyy" // "mm/dd/yyyy"
  2402. },
  2403. 'mm/yyyy': {
  2404. mask: "1/y",
  2405. placeholder: "mm/yyyy",
  2406. leapday: "donotuse",
  2407. separator: '/',
  2408. alias: "mm/dd/yyyy"
  2409. }
  2410. });
  2411. })(jQuery);
  2412. /*
  2413. Input Mask plugin extensions
  2414. http://github.com/RobinHerbots/jquery.inputmask
  2415. Copyright (c) 2010 - 2014 Robin Herbots
  2416. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2417. Version: 3.0.31
  2418. Optional extensions on the jquery.inputmask base
  2419. */
  2420. (function ($) {
  2421. //number aliases
  2422. $.extend($.inputmask.defaults.aliases, {
  2423. 'numeric': {
  2424. mask: function (opts) {
  2425. if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
  2426. opts.integerDigits = opts.repeat;
  2427. }
  2428. opts.repeat = 0;
  2429. var mask = opts.prefix;
  2430. mask += "[+]";
  2431. mask += "~{1," + opts.integerDigits + "}";
  2432. if (opts.digits != undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
  2433. if (opts.digitsOptional)
  2434. mask += "[" + opts.radixPoint + "~{" + opts.digits + "}]";
  2435. else mask += opts.radixPoint + "~{" + opts.digits + "}";
  2436. }
  2437. mask += opts.suffix;
  2438. return mask;
  2439. },
  2440. placeholder: "",
  2441. greedy: false,
  2442. digits: "*", //number of fractionalDigits
  2443. digitsOptional: true,
  2444. groupSeparator: "",//",", // | "."
  2445. radixPoint: ".",
  2446. groupSize: 3,
  2447. autoGroup: false,
  2448. allowPlus: true,
  2449. allowMinus: true,
  2450. integerDigits: "+", //number of integerDigits
  2451. defaultValue: "",
  2452. prefix: "",
  2453. suffix: "",
  2454. skipRadixDance: false, //disable radixpoint caret positioning
  2455. getLastValidPosition: function (maskset, closestTo, opts) {
  2456. var lastValidPosition = -1, valids = maskset["validPositions"];
  2457. for (var posNdx in valids) {
  2458. var psNdx = parseInt(posNdx);
  2459. if (psNdx > lastValidPosition) lastValidPosition = psNdx;
  2460. }
  2461. if (closestTo != undefined) {
  2462. var buffer = maskset["buffer"];
  2463. if (opts.skipRadixDance === false && opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1)
  2464. lastValidPosition = $.inArray(opts.radixPoint, buffer);
  2465. }
  2466. return lastValidPosition;
  2467. },
  2468. rightAlign: true,
  2469. postFormat: function (buffer, pos, reformatOnly, opts) {
  2470. var needsRefresh = false;
  2471. if (opts.groupSeparator == "") return { pos: pos };
  2472. var cbuf = buffer.slice();
  2473. if (!reformatOnly) {
  2474. cbuf.splice(pos, 0, "?"); //set position indicator
  2475. }
  2476. var bufVal = cbuf.join('');
  2477. if (opts.autoGroup || (reformatOnly && bufVal.indexOf(opts.groupSeparator) != -1)) {
  2478. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
  2479. bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), '');
  2480. var radixSplit = bufVal.split(opts.radixPoint);
  2481. bufVal = radixSplit[0];
  2482. if (bufVal != (opts.prefix + "?0")) {
  2483. needsRefresh = true;
  2484. var reg = new RegExp('([-\+]?[\\d\?]+)([\\d\?]{' + opts.groupSize + '})');
  2485. while (reg.test(bufVal)) {
  2486. bufVal = bufVal.replace(reg, '$1' + opts.groupSeparator + '$2');
  2487. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  2488. }
  2489. }
  2490. if (radixSplit.length > 1)
  2491. bufVal += opts.radixPoint + radixSplit[1];
  2492. }
  2493. buffer.length = bufVal.length; //align the length
  2494. for (var i = 0, l = bufVal.length; i < l; i++) {
  2495. buffer[i] = bufVal.charAt(i);
  2496. }
  2497. var newPos = $.inArray("?", buffer);
  2498. if (!reformatOnly) buffer.splice(newPos, 1);
  2499. return { pos: reformatOnly ? pos : newPos, "refreshFromBuffer": needsRefresh };
  2500. },
  2501. onKeyDown: function (e, buffer, opts) {
  2502. var $input = $(this), input = this;
  2503. if (opts.autoGroup && e.keyCode == opts.keyCode.DELETE || e.keyCode == opts.keyCode.BACKSPACE) {
  2504. return opts.postFormat(buffer, 0, true, opts);
  2505. }
  2506. },
  2507. regex: {
  2508. integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
  2509. },
  2510. definitions: {
  2511. '~': {
  2512. validator: function (chrs, buffer, pos, strict, opts) {
  2513. if (!strict && chrs === "-") {
  2514. var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
  2515. if (matchRslt.length > 0) {
  2516. if (buffer[matchRslt.index] == "+") {
  2517. buffer.splice(matchRslt.index, 1);
  2518. return { "pos": matchRslt.index, "c": "-", "refreshFromBuffer": true, "caret": pos };
  2519. } else if (buffer[matchRslt.index] == "-") {
  2520. buffer.splice(matchRslt.index, 1);
  2521. return { "refreshFromBuffer": true, "caret": pos - 1 };
  2522. } else {
  2523. return { "pos": matchRslt.index, "c": "-", "caret": pos + 1 };
  2524. }
  2525. }
  2526. }
  2527. var isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
  2528. if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
  2529. return opts.postFormat(buffer, pos, (chrs == "-" || chrs == "+") ? true : false, opts);
  2530. }
  2531. return isValid;
  2532. },
  2533. cardinality: 1,
  2534. prevalidator: null
  2535. },
  2536. '+': {
  2537. validator: function (chrs, buffer, pos, strict, opts) {
  2538. var signed = "[";
  2539. if (opts.allowMinus === true) signed += "-";
  2540. if (opts.allowPlus === true) signed += "\+";
  2541. signed += "]";
  2542. var isValid = new RegExp(signed).test(chrs);
  2543. return isValid;
  2544. },
  2545. cardinality: 1,
  2546. prevalidator: null
  2547. }
  2548. },
  2549. insertMode: true,
  2550. autoUnmask: false
  2551. },
  2552. 'decimal': {
  2553. alias: "numeric"
  2554. },
  2555. 'integer': {
  2556. alias: "numeric",
  2557. digits: "0"
  2558. }
  2559. });
  2560. })(jQuery);
  2561. /*
  2562. Input Mask plugin extensions
  2563. http://github.com/RobinHerbots/jquery.inputmask
  2564. Copyright (c) 2010 - 2014 Robin Herbots
  2565. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2566. Version: 3.0.31
  2567. Regex extensions on the jquery.inputmask base
  2568. Allows for using regular expressions as a mask
  2569. */
  2570. (function ($) {
  2571. $.extend($.inputmask.defaults.aliases, { // $(selector).inputmask("Regex", { regex: "[0-9]*"}
  2572. 'Regex': {
  2573. mask: "r",
  2574. greedy: false,
  2575. repeat: "*",
  2576. regex: null,
  2577. regexTokens: null,
  2578. //Thx to https://github.com/slevithan/regex-colorizer for the tokenizer regex
  2579. tokenizer: /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g,
  2580. quantifierFilter: /[0-9]+[^,]/,
  2581. isComplete: function(buffer, opts){
  2582. return new RegExp(opts.regex).test(buffer.join(''));
  2583. },
  2584. definitions: {
  2585. 'r': {
  2586. validator: function (chrs, buffer, pos, strict, opts) {
  2587. function regexToken(isGroup, isQuantifier) {
  2588. this.matches = [];
  2589. this.isGroup = isGroup || false;
  2590. this.isQuantifier = isQuantifier || false;
  2591. this.quantifier = { min: 1, max: 1 };
  2592. this.repeaterPart = undefined;
  2593. }
  2594. function analyseRegex() {
  2595. var currentToken = new regexToken(), match, m, opengroups = [];
  2596. opts.regexTokens = [];
  2597. // The tokenizer regex does most of the tokenization grunt work
  2598. while (match = opts.tokenizer.exec(opts.regex)) {
  2599. m = match[0];
  2600. switch (m.charAt(0)) {
  2601. case "(": // Group opening
  2602. opengroups.push(new regexToken(true));
  2603. break;
  2604. case ")": // Group closing
  2605. var groupToken = opengroups.pop();
  2606. if (opengroups.length > 0) {
  2607. opengroups[opengroups.length - 1]["matches"].push(groupToken);
  2608. } else {
  2609. currentToken.matches.push(groupToken);
  2610. }
  2611. break;
  2612. case "{": case "+": case "*": //Quantifier
  2613. var quantifierToken = new regexToken(false, true);
  2614. m = m.replace(/[{}]/g, "");
  2615. var mq = m.split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = mq.length == 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
  2616. quantifierToken.quantifier = { min: mq0, max: mq1 };
  2617. if (opengroups.length > 0) {
  2618. var matches = opengroups[opengroups.length - 1]["matches"];
  2619. match = matches.pop();
  2620. if (!match["isGroup"]) {
  2621. var groupToken = new regexToken(true);
  2622. groupToken.matches.push(match);
  2623. match = groupToken;
  2624. }
  2625. matches.push(match);
  2626. matches.push(quantifierToken);
  2627. } else {
  2628. match = currentToken.matches.pop();
  2629. if (!match["isGroup"]) {
  2630. var groupToken = new regexToken(true);
  2631. groupToken.matches.push(match);
  2632. match = groupToken;
  2633. }
  2634. currentToken.matches.push(match);
  2635. currentToken.matches.push(quantifierToken);
  2636. }
  2637. break;
  2638. default:
  2639. if (opengroups.length > 0) {
  2640. opengroups[opengroups.length - 1]["matches"].push(m);
  2641. } else {
  2642. currentToken.matches.push(m);
  2643. }
  2644. break;
  2645. }
  2646. }
  2647. if (currentToken.matches.length > 0)
  2648. opts.regexTokens.push(currentToken);
  2649. };
  2650. function validateRegexToken(token, fromGroup) {
  2651. var isvalid = false;
  2652. if (fromGroup) {
  2653. regexPart += "(";
  2654. openGroupCount++;
  2655. }
  2656. for (var mndx = 0; mndx < token["matches"].length; mndx++) {
  2657. var matchToken = token["matches"][mndx];
  2658. if (matchToken["isGroup"] == true) {
  2659. isvalid = validateRegexToken(matchToken, true);
  2660. } else if (matchToken["isQuantifier"] == true) {
  2661. var crrntndx = $.inArray(matchToken, token["matches"]),
  2662. matchGroup = token["matches"][crrntndx - 1];
  2663. var regexPartBak = regexPart;
  2664. if (isNaN(matchToken.quantifier.max)) {
  2665. while (matchToken["repeaterPart"] && matchToken["repeaterPart"] != regexPart && matchToken["repeaterPart"].length > regexPart.length) {
  2666. isvalid = validateRegexToken(matchGroup, true);
  2667. if (isvalid) break;
  2668. }
  2669. isvalid = isvalid || validateRegexToken(matchGroup, true);
  2670. if (isvalid) matchToken["repeaterPart"] = regexPart;
  2671. regexPart = regexPartBak + matchToken.quantifier.max;
  2672. } else {
  2673. for (var i = 0, qm = matchToken.quantifier.max - 1; i < qm; i++) {
  2674. isvalid = validateRegexToken(matchGroup, true);
  2675. if (isvalid) break;
  2676. }
  2677. regexPart = regexPartBak + "{" + matchToken.quantifier.min + "," + matchToken.quantifier.max + "}";
  2678. }
  2679. } else if (matchToken["matches"] != undefined) {
  2680. for (var k = 0; k < matchToken.length; k++) {
  2681. isvalid = validateRegexToken(matchToken[k], fromGroup);
  2682. if (isvalid) break;
  2683. }
  2684. } else {
  2685. var testExp;
  2686. if (matchToken[0] == "[") {
  2687. testExp = regexPart;
  2688. testExp += matchToken;
  2689. for (var j = 0; j < openGroupCount; j++) {
  2690. testExp += ")";
  2691. }
  2692. var exp = new RegExp("^(" + testExp + ")$");
  2693. isvalid = exp.test(bufferStr);
  2694. } else {
  2695. for (var l = 0, tl = matchToken.length; l < tl; l++) {
  2696. if (matchToken[l] == "\\") continue;
  2697. testExp = regexPart;
  2698. testExp += matchToken.substr(0, l + 1);
  2699. testExp = testExp.replace(/\|$/, "");
  2700. for (var j = 0; j < openGroupCount; j++) {
  2701. testExp += ")";
  2702. }
  2703. var exp = new RegExp("^(" + testExp + ")$");
  2704. isvalid = exp.test(bufferStr);
  2705. if (isvalid) break;
  2706. }
  2707. }
  2708. regexPart += matchToken;
  2709. }
  2710. if (isvalid) break;
  2711. }
  2712. if (fromGroup) {
  2713. regexPart += ")";
  2714. openGroupCount--;
  2715. }
  2716. return isvalid;
  2717. }
  2718. if (opts.regexTokens == null) {
  2719. analyseRegex();
  2720. }
  2721. var cbuffer = buffer.slice(), regexPart = "", isValid = false, openGroupCount = 0;
  2722. cbuffer.splice(pos, 0, chrs);
  2723. var bufferStr = cbuffer.join('');
  2724. for (var i = 0; i < opts.regexTokens.length; i++) {
  2725. var regexToken = opts.regexTokens[i];
  2726. isValid = validateRegexToken(regexToken, regexToken["isGroup"]);
  2727. if (isValid) break;
  2728. }
  2729. return isValid;
  2730. },
  2731. cardinality: 1
  2732. }
  2733. }
  2734. }
  2735. });
  2736. })(jQuery);
  2737. /*
  2738. Input Mask plugin extensions
  2739. http://github.com/RobinHerbots/jquery.inputmask
  2740. Copyright (c) 2010 - 2014 Robin Herbots
  2741. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2742. Version: 3.0.31
  2743. Phone extension.
  2744. When using this extension make sure you specify the correct url to get the masks
  2745. $(selector).inputmask("phone", {
  2746. url: "Scripts/jquery.inputmask/phone-codes/phone-codes.json",
  2747. onKeyValidation: function () { //show some metadata in the console
  2748. console.log($(this).inputmask("getmetadata")["name_en"]);
  2749. }
  2750. });
  2751. */
  2752. (function ($) {
  2753. $.extend($.inputmask.defaults.aliases, {
  2754. 'phone': {
  2755. url: "phone-codes/phone-codes.json",
  2756. mask: function (opts) {
  2757. opts.definitions = {
  2758. 'p': {
  2759. validator: function () { return false; },
  2760. cardinality: 1
  2761. },
  2762. '#': {
  2763. validator: "[0-9]",
  2764. cardinality: 1
  2765. }
  2766. };
  2767. var maskList = [];
  2768. $.ajax({
  2769. url: opts.url,
  2770. async: false,
  2771. dataType: 'json',
  2772. success: function (response) {
  2773. maskList = response;
  2774. }
  2775. });
  2776. maskList.splice(0, 0, "+p(ppp)ppp-pppp");
  2777. return maskList;
  2778. },
  2779. nojumps: true,
  2780. nojumpsThreshold: 1
  2781. },
  2782. 'phonebe': {
  2783. url: "phone-codes/phone-be.json",
  2784. mask: function (opts) {
  2785. opts.definitions = {
  2786. 'p': {
  2787. validator: function () { return false; },
  2788. cardinality: 1
  2789. },
  2790. '#': {
  2791. validator: "[0-9]",
  2792. cardinality: 1
  2793. }
  2794. };
  2795. var maskList = [];
  2796. $.ajax({
  2797. url: opts.url,
  2798. async: false,
  2799. dataType: 'json',
  2800. success: function (response) {
  2801. maskList = response;
  2802. }
  2803. });
  2804. maskList.splice(0, 0, "+32(ppp)ppp-pppp");
  2805. return maskList;
  2806. },
  2807. nojumps: true,
  2808. nojumpsThreshold: 4
  2809. }
  2810. });
  2811. })(jQuery);