jquery.inputmask.bundle.js 155 KB

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