jquery.inputmask.bundle.js 161 KB

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