jquery.inputmask.bundle.js 144 KB

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