jquery.inputmask.bundle.js 161 KB

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