jquery.inputmask.bundle.js 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150
  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.50
  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. if (k == opts.keyCode.BACKSPACE)
  907. k = opts.keyCode.DELETE;
  908. else if (k == opts.keyCode.DELETE)
  909. k = opts.keyCode.BACKSPACE;
  910. if (isRTL) {
  911. var pend = pos.end;
  912. pos.end = pos.begin;
  913. pos.begin = pend;
  914. }
  915. }
  916. if (k == opts.keyCode.BACKSPACE && pos.end - pos.begin <= 1)
  917. pos.begin = seekPrevious(pos.begin);
  918. else if (k == opts.keyCode.DELETE && pos.begin == pos.end)
  919. pos.end++;
  920. stripValidPositions(pos.begin, pos.end);
  921. var firstMaskedPos = getLastValidPosition(pos.begin);
  922. if (firstMaskedPos < pos.begin) {
  923. getMaskSet()["p"] = seekNext(firstMaskedPos);
  924. } else {
  925. getMaskSet()["p"] = pos.begin;
  926. }
  927. }
  928. function handleOnKeyResult(input, keyResult, caretPos) {
  929. if (keyResult && keyResult["refreshFromBuffer"]) {
  930. var refresh = keyResult["refreshFromBuffer"];
  931. refreshFromBuffer(refresh === true ? refresh : refresh["start"], refresh["end"]);
  932. resetMaskSet(true);
  933. writeBuffer(input, getBuffer());
  934. caret(input, keyResult.caret || caretPos.begin, keyResult.caret || caretPos.end);
  935. }
  936. }
  937. function keydownEvent(e) {
  938. //Safari 5.1.x - modal dialog fires keypress twice workaround
  939. skipKeyPressEvent = false;
  940. var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
  941. //backspace, delete, and escape get special treatment
  942. if (k == opts.keyCode.BACKSPACE || k == opts.keyCode.DELETE || (iphone && k == 127) || e.ctrlKey && k == 88) { //backspace/delete
  943. e.preventDefault(); //stop default action but allow propagation
  944. if (k == 88) valueOnFocus = getBuffer().join('');
  945. handleRemove(input, k, pos);
  946. writeBuffer(input, getBuffer(), getMaskSet()["p"]);
  947. if (input._valueGet() == getBufferTemplate().join(''))
  948. $input.trigger('cleared');
  949. if (opts.showTooltip) { //update tooltip
  950. $input.prop("title", getMaskSet()["mask"]);
  951. }
  952. } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
  953. setTimeout(function () {
  954. var caretPos = seekNext(getLastValidPosition());
  955. if (!opts.insertMode && caretPos == getMaskLength() && !e.shiftKey) caretPos--;
  956. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
  957. }, 0);
  958. } else if ((k == opts.keyCode.HOME && !e.shiftKey) || k == opts.keyCode.PAGE_UP) { //Home or page_up
  959. caret(input, 0, e.shiftKey ? pos.begin : 0);
  960. } else if (k == opts.keyCode.ESCAPE || (k == 90 && e.ctrlKey)) { //escape && undo
  961. checkVal(input, true, false, valueOnFocus.split(''));
  962. $input.click();
  963. } else if (k == opts.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) { //insert
  964. opts.insertMode = !opts.insertMode;
  965. caret(input, !opts.insertMode && pos.begin == getMaskLength() ? pos.begin - 1 : pos.begin);
  966. } else if (opts.insertMode == false && !e.shiftKey) {
  967. if (k == opts.keyCode.RIGHT) {
  968. setTimeout(function () {
  969. var caretPos = caret(input);
  970. caret(input, caretPos.begin);
  971. }, 0);
  972. } else if (k == opts.keyCode.LEFT) {
  973. setTimeout(function () {
  974. var caretPos = caret(input);
  975. caret(input, isRTL ? caretPos.begin + 1 : caretPos.begin - 1);
  976. }, 0);
  977. }
  978. }
  979. var currentCaretPos = caret(input);
  980. var keydownResult = opts.onKeyDown.call(this, e, getBuffer(), opts);
  981. handleOnKeyResult(input, keydownResult, currentCaretPos);
  982. ignorable = $.inArray(k, opts.ignorables) != -1;
  983. }
  984. function keypressEvent(e, checkval, k, writeOut, strict, ndx) {
  985. //Safari 5.1.x - modal dialog fires keypress twice workaround
  986. if (k == undefined && skipKeyPressEvent) return false;
  987. skipKeyPressEvent = true;
  988. var input = this, $input = $(input);
  989. e = e || window.event;
  990. var k = checkval ? k : (e.which || e.charCode || e.keyCode);
  991. if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) {
  992. return true;
  993. } else {
  994. if (k) {
  995. //special treat the decimal separator
  996. if (checkval !== true && k == 46 && e.shiftKey == false && opts.radixPoint == ",") k = 44;
  997. var pos, forwardPosition, c = String.fromCharCode(k);
  998. if (checkval) {
  999. var pcaret = strict ? ndx : getLastValidPosition() + 1;
  1000. pos = { begin: pcaret, end: pcaret };
  1001. } else {
  1002. pos = caret(input);
  1003. }
  1004. //should we clear a possible selection??
  1005. var isSlctn = isSelection(pos.begin, pos.end);
  1006. if (isSlctn) {
  1007. getMaskSet()["undoPositions"] = $.extend(true, {}, getMaskSet()["validPositions"]); //init undobuffer for recovery when not valid
  1008. handleRemove(input, opts.keyCode.DELETE, pos);
  1009. if (!opts.insertMode) { //preserve some space
  1010. opts.insertMode = !opts.insertMode;
  1011. setValidPosition(pos.begin, strict);
  1012. opts.insertMode = !opts.insertMode;
  1013. }
  1014. isSlctn = !opts.multi;
  1015. }
  1016. getMaskSet()["writeOutBuffer"] = true;
  1017. var p = isRTL && !isSlctn ? pos.end : pos.begin;
  1018. var valResult = isValid(p, c, strict);
  1019. if (valResult !== false) {
  1020. if (valResult !== true) {
  1021. p = valResult.pos != undefined ? valResult.pos : p; //set new position from isValid
  1022. c = valResult.c != undefined ? valResult.c : c; //set new char from isValid
  1023. }
  1024. resetMaskSet(true);
  1025. if (valResult.caret != undefined)
  1026. forwardPosition = valResult.caret;
  1027. else {
  1028. var vps = getMaskSet()["validPositions"];
  1029. if (vps[p + 1] != undefined && getTests(p + 1, vps[p].locator.slice(), p).length > 1)
  1030. forwardPosition = p + 1;
  1031. else
  1032. forwardPosition = seekNext(p);
  1033. }
  1034. getMaskSet()["p"] = forwardPosition; //needed for checkval
  1035. }
  1036. if (writeOut !== false) {
  1037. var self = this;
  1038. setTimeout(function () { opts.onKeyValidation.call(self, valResult, opts); }, 0);
  1039. if (getMaskSet()["writeOutBuffer"] && valResult !== false) {
  1040. var buffer = getBuffer();
  1041. writeBuffer(input, buffer, checkval ? undefined : opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
  1042. if (checkval !== true) {
  1043. setTimeout(function () { //timeout needed for IE
  1044. if (isComplete(buffer) === true)
  1045. $input.trigger("complete");
  1046. skipInputEvent = true;
  1047. $input.trigger("input");
  1048. }, 0);
  1049. }
  1050. } else if (isSlctn) {
  1051. getMaskSet()["buffer"] = undefined;
  1052. getMaskSet()["validPositions"] = getMaskSet()["undoPositions"];
  1053. }
  1054. } else if (isSlctn) {
  1055. getMaskSet()["buffer"] = undefined;
  1056. getMaskSet()["validPositions"] = getMaskSet()["undoPositions"];
  1057. }
  1058. if (opts.showTooltip) { //update tooltip
  1059. $input.prop("title", getMaskSet()["mask"]);
  1060. }
  1061. //needed for IE8 and below
  1062. if (e && checkval != true) {
  1063. e.preventDefault ? e.preventDefault() : e.returnValue = false;
  1064. var currentCaretPos = caret(input);
  1065. var keypressResult = opts.onKeyPress.call(this, e, getBuffer(), opts);
  1066. handleOnKeyResult(input, keypressResult, currentCaretPos);
  1067. }
  1068. var temp;
  1069. for (var i in getMaskSet().validPositions) {
  1070. temp += " " + i;
  1071. }
  1072. }
  1073. }
  1074. }
  1075. function keyupEvent(e) {
  1076. var $input = $(this), input = this, k = e.keyCode, buffer = getBuffer();
  1077. var currentCaretPos = caret(input);
  1078. var keyupResult = opts.onKeyUp.call(this, e, buffer, opts);
  1079. handleOnKeyResult(input, keyupResult, currentCaretPos);
  1080. if (k == opts.keyCode.TAB && opts.showMaskOnFocus) {
  1081. if ($input.hasClass('focus-inputmask') && input._valueGet().length == 0) {
  1082. resetMaskSet();
  1083. buffer = getBuffer();
  1084. writeBuffer(input, buffer);
  1085. caret(input, 0);
  1086. valueOnFocus = getBuffer().join('');
  1087. } else {
  1088. writeBuffer(input, buffer);
  1089. caret(input, TranslatePosition(0), TranslatePosition(getMaskLength()));
  1090. }
  1091. }
  1092. }
  1093. function pasteEvent(e) {
  1094. if (skipInputEvent === true && e.type == "input") {
  1095. skipInputEvent = false;
  1096. return true;
  1097. }
  1098. var input = this, $input = $(input), inputValue = input._valueGet();
  1099. //paste event for IE8 and lower I guess ;-)
  1100. if (e.type == "propertychange" && input._valueGet().length <= getMaskLength()) {
  1101. return true;
  1102. } else if (e.type == "paste") {
  1103. if (window.clipboardData && window.clipboardData.getData) { // IE
  1104. inputValue = window.clipboardData.getData('Text');
  1105. } else if (e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) {
  1106. inputValue = e.originalEvent.clipboardData.getData('text/plain');
  1107. }
  1108. }
  1109. var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, inputValue, opts) : inputValue;
  1110. checkVal(input, true, false, pasteValue.split(''), true);
  1111. $input.click();
  1112. if (isComplete(getBuffer()) === true)
  1113. $input.trigger("complete");
  1114. return false;
  1115. }
  1116. function mobileInputEvent(e) {
  1117. if (skipInputEvent === true && e.type == "input") {
  1118. skipInputEvent = false;
  1119. return true;
  1120. }
  1121. var input = this;
  1122. //backspace in chrome32 only fires input event - detect & treat
  1123. var caretPos = caret(input),
  1124. currentValue = input._valueGet();
  1125. currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*"), "");
  1126. //correct caretposition for chrome
  1127. if (caretPos.begin > currentValue.length) {
  1128. caret(input, currentValue.length);
  1129. caretPos = caret(input);
  1130. }
  1131. if ((getBuffer().length - currentValue.length) == 1 && currentValue.charAt(caretPos.begin) != getBuffer()[caretPos.begin]
  1132. && currentValue.charAt(caretPos.begin + 1) != getBuffer()[caretPos.begin]
  1133. && !isMask(caretPos.begin)) {
  1134. e.keyCode = opts.keyCode.BACKSPACE;
  1135. keydownEvent.call(input, e);
  1136. }
  1137. e.preventDefault();
  1138. }
  1139. function mask(el) {
  1140. $el = $(el);
  1141. if ($el.is(":input") && $el.attr("type") != "number") {
  1142. //store tests & original buffer in the input element - used to get the unmasked value
  1143. $el.data('_inputmask', {
  1144. 'maskset': maskset,
  1145. 'opts': opts,
  1146. 'isRTL': false
  1147. });
  1148. //show tooltip
  1149. if (opts.showTooltip) {
  1150. $el.prop("title", getMaskSet()["mask"]);
  1151. }
  1152. patchValueProperty(el);
  1153. if (el.dir == "rtl" || opts.rightAlign)
  1154. $el.css("text-align", "right");
  1155. if (el.dir == "rtl" || opts.numericInput) {
  1156. el.dir = "ltr";
  1157. $el.removeAttr("dir");
  1158. var inputData = $el.data('_inputmask');
  1159. inputData['isRTL'] = true;
  1160. $el.data('_inputmask', inputData);
  1161. isRTL = true;
  1162. }
  1163. //unbind all events - to make sure that no other mask will interfere when re-masking
  1164. $el.unbind(".inputmask");
  1165. $el.removeClass('focus-inputmask');
  1166. //bind events
  1167. $el.closest('form').bind("submit", function () { //trigger change on submit if any
  1168. if (valueOnFocus != getBuffer().join('')) {
  1169. $el.change();
  1170. }
  1171. }).bind('reset', function () {
  1172. setTimeout(function () {
  1173. $el.trigger("setvalue");
  1174. }, 0);
  1175. });
  1176. $el.bind("mouseenter.inputmask", function () {
  1177. var $input = $(this), input = this;
  1178. if (!$input.hasClass('focus-inputmask') && opts.showMaskOnHover) {
  1179. if (input._valueGet() != getBuffer().join('')) {
  1180. writeBuffer(input, getBuffer());
  1181. }
  1182. }
  1183. }).bind("blur.inputmask", function () {
  1184. var $input = $(this), input = this;
  1185. if ($input.data('_inputmask')) {
  1186. var nptValue = input._valueGet(), buffer = getBuffer();
  1187. $input.removeClass('focus-inputmask');
  1188. if (valueOnFocus != getBuffer().join('')) {
  1189. $input.change();
  1190. }
  1191. if (opts.clearMaskOnLostFocus && nptValue != '') {
  1192. if (nptValue == getBufferTemplate().join(''))
  1193. input._valueSet('');
  1194. else { //clearout optional tail of the mask
  1195. clearOptionalTail(input);
  1196. }
  1197. }
  1198. if (isComplete(buffer) === false) {
  1199. $input.trigger("incomplete");
  1200. if (opts.clearIncomplete) {
  1201. resetMaskSet();
  1202. if (opts.clearMaskOnLostFocus)
  1203. input._valueSet('');
  1204. else {
  1205. buffer = getBufferTemplate().slice();
  1206. writeBuffer(input, buffer);
  1207. }
  1208. }
  1209. }
  1210. }
  1211. }).bind("focus.inputmask", function () {
  1212. var $input = $(this), input = this, nptValue = input._valueGet();
  1213. if (opts.showMaskOnFocus && !$input.hasClass('focus-inputmask') && (!opts.showMaskOnHover || (opts.showMaskOnHover && nptValue == ''))) {
  1214. if (input._valueGet() != getBuffer().join('')) {
  1215. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
  1216. }
  1217. }
  1218. $input.addClass('focus-inputmask');
  1219. valueOnFocus = getBuffer().join('');
  1220. }).bind("mouseleave.inputmask", function () {
  1221. var $input = $(this), input = this;
  1222. if (opts.clearMaskOnLostFocus) {
  1223. if (!$input.hasClass('focus-inputmask') && input._valueGet() != $input.attr("placeholder")) {
  1224. if (input._valueGet() == getBufferTemplate().join('') || input._valueGet() == '')
  1225. input._valueSet('');
  1226. else { //clearout optional tail of the mask
  1227. clearOptionalTail(input);
  1228. }
  1229. }
  1230. }
  1231. }).bind("click.inputmask", function () {
  1232. var input = this;
  1233. if ($(input).is(":focus")) {
  1234. setTimeout(function () {
  1235. var selectedCaret = caret(input);
  1236. if (selectedCaret.begin == selectedCaret.end) {
  1237. var clickPosition = isRTL ? TranslatePosition(selectedCaret.begin) : selectedCaret.begin,
  1238. lvp = getLastValidPosition(clickPosition),
  1239. lastPosition = seekNext(lvp);
  1240. if (clickPosition < lastPosition) {
  1241. if (isMask(clickPosition))
  1242. caret(input, clickPosition);
  1243. else caret(input, seekNext(clickPosition));
  1244. } else
  1245. caret(input, lastPosition);
  1246. }
  1247. }, 0);
  1248. }
  1249. }).bind('dblclick.inputmask', function () {
  1250. var input = this;
  1251. setTimeout(function () {
  1252. caret(input, 0, seekNext(getLastValidPosition()));
  1253. }, 0);
  1254. }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent
  1255. ).bind('setvalue.inputmask', function () {
  1256. var input = this;
  1257. checkVal(input, true);
  1258. valueOnFocus = getBuffer().join('');
  1259. if (input._valueGet() == getBufferTemplate().join(''))
  1260. input._valueSet('');
  1261. }).bind('complete.inputmask', opts.oncomplete
  1262. ).bind('incomplete.inputmask', opts.onincomplete
  1263. ).bind('cleared.inputmask', opts.oncleared);
  1264. $el.bind("keydown.inputmask", keydownEvent
  1265. ).bind("keypress.inputmask", keypressEvent
  1266. ).bind("keyup.inputmask", keyupEvent);
  1267. if (android || androidfirefox || androidchrome || kindle) {
  1268. if (PasteEventType == "input") {
  1269. $el.unbind(PasteEventType + ".inputmask");
  1270. }
  1271. $el.bind("input.inputmask", mobileInputEvent);
  1272. }
  1273. if (msie1x)
  1274. $el.bind("input.inputmask", pasteEvent);
  1275. //apply mask
  1276. var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) : el._valueGet();
  1277. checkVal(el, true, false, initialValue.split(''), true);
  1278. valueOnFocus = getBuffer().join('');
  1279. // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
  1280. var activeElement;
  1281. try {
  1282. activeElement = document.activeElement;
  1283. } catch (e) {
  1284. }
  1285. if (activeElement === el) { //position the caret when in focus
  1286. $el.addClass('focus-inputmask');
  1287. caret(el, seekNext(getLastValidPosition()));
  1288. } else {
  1289. if (isComplete(getBuffer()) === false) {
  1290. if (opts.clearIncomplete)
  1291. resetMaskSet();
  1292. }
  1293. if (opts.clearMaskOnLostFocus) {
  1294. if (getBuffer().join('') == getBufferTemplate().join('')) {
  1295. el._valueSet('');
  1296. } else {
  1297. clearOptionalTail(el);
  1298. }
  1299. } else {
  1300. writeBuffer(el, getBuffer());
  1301. }
  1302. }
  1303. installEventRuler(el);
  1304. }
  1305. }
  1306. //action object
  1307. if (actionObj != undefined) {
  1308. switch (actionObj["action"]) {
  1309. case "isComplete":
  1310. $el = $(actionObj["el"]);
  1311. maskset = $el.data('_inputmask')['maskset'];
  1312. opts = $el.data('_inputmask')['opts'];
  1313. return isComplete(actionObj["buffer"]);
  1314. case "unmaskedvalue":
  1315. $el = actionObj["$input"];
  1316. maskset = $el.data('_inputmask')['maskset'];
  1317. opts = $el.data('_inputmask')['opts'];
  1318. isRTL = actionObj["$input"].data('_inputmask')['isRTL'];
  1319. return unmaskedvalue(actionObj["$input"], actionObj["skipDatepickerCheck"]);
  1320. case "mask":
  1321. valueOnFocus = getBuffer().join('');
  1322. mask(actionObj["el"]);
  1323. break;
  1324. case "format":
  1325. $el = $({});
  1326. $el.data('_inputmask', {
  1327. 'maskset': maskset,
  1328. 'opts': opts,
  1329. 'isRTL': opts.numericInput
  1330. });
  1331. if (opts.numericInput) {
  1332. isRTL = true;
  1333. }
  1334. var valueBuffer = actionObj["value"].split('');
  1335. checkVal($el, false, false, isRTL ? valueBuffer.reverse() : valueBuffer, true);
  1336. return isRTL ? getBuffer().reverse().join('') : getBuffer().join('');
  1337. case "isValid":
  1338. $el = $({});
  1339. $el.data('_inputmask', {
  1340. 'maskset': maskset,
  1341. 'opts': opts,
  1342. 'isRTL': opts.numericInput
  1343. });
  1344. if (opts.numericInput) {
  1345. isRTL = true;
  1346. }
  1347. var valueBuffer = actionObj["value"].split('');
  1348. checkVal($el, false, true, isRTL ? valueBuffer.reverse() : valueBuffer);
  1349. var buffer = getBuffer();
  1350. var rl = determineLastRequiredPosition();
  1351. buffer.length = rl;
  1352. return isComplete(buffer) && actionObj["value"] == buffer.join('');
  1353. case "getemptymask":
  1354. $el = $(actionObj["el"]);
  1355. maskset = $el.data('_inputmask')['maskset'];
  1356. opts = $el.data('_inputmask')['opts'];
  1357. return getBufferTemplate();
  1358. case "remove":
  1359. var el = actionObj["el"];
  1360. $el = $(el);
  1361. maskset = $el.data('_inputmask')['maskset'];
  1362. opts = $el.data('_inputmask')['opts'];
  1363. //writeout the unmaskedvalue
  1364. el._valueSet(unmaskedvalue($el));
  1365. //unbind all events
  1366. $el.unbind(".inputmask");
  1367. $el.removeClass('focus-inputmask');
  1368. //clear data
  1369. $el.removeData('_inputmask');
  1370. //restore the value property
  1371. var valueProperty;
  1372. if (Object.getOwnPropertyDescriptor)
  1373. valueProperty = Object.getOwnPropertyDescriptor(el, "value");
  1374. if (valueProperty && valueProperty.get) {
  1375. if (el._valueGet) {
  1376. Object.defineProperty(el, "value", {
  1377. get: el._valueGet,
  1378. set: el._valueSet
  1379. });
  1380. }
  1381. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  1382. if (el._valueGet) {
  1383. el.__defineGetter__("value", el._valueGet);
  1384. el.__defineSetter__("value", el._valueSet);
  1385. }
  1386. }
  1387. try { //try catch needed for IE7 as it does not supports deleting fns
  1388. delete el._valueGet;
  1389. delete el._valueSet;
  1390. } catch (e) {
  1391. el._valueGet = undefined;
  1392. el._valueSet = undefined;
  1393. }
  1394. break;
  1395. }
  1396. }
  1397. };
  1398. $.inputmask = {
  1399. //options default
  1400. defaults: {
  1401. placeholder: "_",
  1402. optionalmarker: { start: "[", end: "]" },
  1403. quantifiermarker: { start: "{", end: "}" },
  1404. groupmarker: { start: "(", end: ")" },
  1405. alternatormarker: "|",
  1406. escapeChar: "\\",
  1407. mask: null,
  1408. oncomplete: $.noop, //executes when the mask is complete
  1409. onincomplete: $.noop, //executes when the mask is incomplete and focus is lost
  1410. oncleared: $.noop, //executes when the mask is cleared
  1411. repeat: 0, //repetitions of the mask: * ~ forever, otherwise specify an integer
  1412. greedy: true, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
  1413. autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
  1414. clearMaskOnLostFocus: true,
  1415. insertMode: true, //insert the input or overwrite the input
  1416. clearIncomplete: false, //clear the incomplete input on blur
  1417. aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
  1418. alias: null,
  1419. onKeyUp: $.noop, //callback to implement autocomplete on certain keys for example
  1420. onKeyPress: $.noop, //callback to implement autocomplete on certain keys for example
  1421. onKeyDown: $.noop, //callback to implement autocomplete on certain keys for example
  1422. onBeforeMask: undefined, //executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
  1423. onBeforePaste: undefined, //executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
  1424. onUnMask: undefined, //executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
  1425. showMaskOnFocus: true, //show the mask-placeholder when the input has focus
  1426. showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
  1427. onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
  1428. skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
  1429. showTooltip: false, //show the activemask as tooltip
  1430. numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
  1431. rightAlign: false, //align to the right
  1432. //numeric basic properties
  1433. radixPoint: "", //".", // | ","
  1434. //numeric basic properties
  1435. nojumps: false, //do not jump over fixed parts in the mask
  1436. nojumpsThreshold: 0, //start nojumps as of
  1437. definitions: {
  1438. '9': {
  1439. validator: "[0-9]",
  1440. cardinality: 1,
  1441. definitionSymbol: "*"
  1442. },
  1443. 'a': {
  1444. validator: "[A-Za-z\u0410-\u044F\u0401\u0451]",
  1445. cardinality: 1,
  1446. definitionSymbol: "*"
  1447. },
  1448. '*': {
  1449. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1450. cardinality: 1
  1451. }
  1452. },
  1453. keyCode: {
  1454. 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,
  1455. 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
  1456. },
  1457. //specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
  1458. 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],
  1459. isComplete: undefined //override for isComplete - args => buffer, opts - return true || false
  1460. },
  1461. masksCache: {},
  1462. escapeRegex: function (str) {
  1463. var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
  1464. return str.replace(new RegExp('(\\' + specials.join('|\\') + ')', 'gim'), '\\$1');
  1465. },
  1466. format: function (value, options) {
  1467. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1468. resolveAlias(opts.alias, options, opts);
  1469. return maskScope({ "action": "format", "value": value }, generateMaskSet(opts), opts);
  1470. },
  1471. isValid: function (value, options) {
  1472. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1473. resolveAlias(opts.alias, options, opts);
  1474. return maskScope({ "action": "isValid", "value": value }, generateMaskSet(opts), opts);
  1475. }
  1476. };
  1477. $.fn.inputmask = function (fn, options, targetScope, targetData, msk) {
  1478. targetScope = targetScope || maskScope;
  1479. targetData = targetData || "_inputmask";
  1480. function importAttributeOptions(npt, opts) {
  1481. var $npt = $(npt);
  1482. for (var option in opts) {
  1483. var optionData = $npt.data("inputmask-" + option.toLowerCase());
  1484. if (optionData != undefined)
  1485. opts[option] = optionData;
  1486. }
  1487. return opts;
  1488. }
  1489. var opts = $.extend(true, {}, $.inputmask.defaults, options),
  1490. maskset;
  1491. if (typeof fn === "string") {
  1492. switch (fn) {
  1493. case "mask":
  1494. //resolve possible aliases given by options
  1495. resolveAlias(opts.alias, options, opts);
  1496. maskset = generateMaskSet(opts);
  1497. if (maskset.length == 0) { return this; }
  1498. return this.each(function () {
  1499. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, $.isArray(maskset) && targetScope === maskScope ? maskset[0] : maskset), importAttributeOptions(this, opts));
  1500. });
  1501. case "unmaskedvalue":
  1502. var $input = $(this);
  1503. if ($input.data(targetData)) {
  1504. return targetScope({ "action": "unmaskedvalue", "$input": $input });
  1505. } else return $input.val();
  1506. case "remove":
  1507. return this.each(function () {
  1508. var $input = $(this);
  1509. if ($input.data(targetData)) {
  1510. targetScope({ "action": "remove", "el": this });
  1511. }
  1512. });
  1513. case "getemptymask": //return the default (empty) mask value, usefull for setting the default value in validation
  1514. if (this.data(targetData)) {
  1515. return targetScope({ "action": "getemptymask", "el": this });
  1516. }
  1517. else return "";
  1518. case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
  1519. return this.data(targetData) ? !this.data(targetData)['opts'].autoUnmask : false;
  1520. case "isComplete":
  1521. if (this.data(targetData)) {
  1522. return targetScope({ "action": "isComplete", "buffer": this[0]._valueGet().split(''), "el": this });
  1523. } else return true;
  1524. case "getmetadata": //return mask metadata if exists
  1525. if (this.data(targetData)) {
  1526. maskset = this.data(targetData)['maskset'];
  1527. return maskset['metadata'];
  1528. }
  1529. else return undefined;
  1530. case "_detectScope":
  1531. resolveAlias(opts.alias, options, opts);
  1532. if (msk != undefined && !resolveAlias(msk, options, opts) && $.inArray(msk, ["mask", "unmaskedvalue", "remove", "getemptymask", "hasMaskedValue", "isComplete", "getmetadata", "_detectScope"]) == -1) {
  1533. opts.mask = msk;
  1534. }
  1535. if ($.isFunction(opts.mask)) {
  1536. opts.mask = opts.mask.call(this, opts);
  1537. }
  1538. return $.isArray(opts.mask);
  1539. default:
  1540. resolveAlias(opts.alias, options, opts);
  1541. //check if the fn is an alias
  1542. if (!resolveAlias(fn, options, opts)) {
  1543. //maybe fn is a mask so we try
  1544. //set mask
  1545. opts.mask = fn;
  1546. }
  1547. maskset = generateMaskSet(opts);
  1548. if (maskset == undefined) { return this; }
  1549. return this.each(function () {
  1550. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, $.isArray(maskset) && targetScope === maskScope ? maskset[0] : maskset), importAttributeOptions(this, opts));
  1551. });
  1552. }
  1553. } else if (typeof fn == "object") {
  1554. opts = $.extend(true, {}, $.inputmask.defaults, fn);
  1555. resolveAlias(opts.alias, fn, opts); //resolve aliases
  1556. maskset = generateMaskSet(opts);
  1557. if (maskset == undefined) { return this; }
  1558. return this.each(function () {
  1559. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, $.isArray(maskset) && targetScope === maskScope ? maskset[0] : maskset), importAttributeOptions(this, opts));
  1560. });
  1561. } else if (fn == undefined) {
  1562. //look for data-inputmask atribute - the attribute should only contain optipns
  1563. return this.each(function () {
  1564. var attrOptions = $(this).attr("data-inputmask");
  1565. if (attrOptions && attrOptions != "") {
  1566. try {
  1567. attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
  1568. var dataoptions = $.parseJSON("{" + attrOptions + "}");
  1569. $.extend(true, dataoptions, options);
  1570. opts = $.extend(true, {}, $.inputmask.defaults, dataoptions);
  1571. resolveAlias(opts.alias, dataoptions, opts);
  1572. opts.alias = undefined;
  1573. $(this).inputmask("mask", opts, targetScope);
  1574. } catch (ex) { } //need a more relax parseJSON
  1575. }
  1576. });
  1577. }
  1578. };
  1579. }
  1580. })(jQuery);
  1581. /**
  1582. * @license Input Mask plugin for jquery
  1583. * http://github.com/RobinHerbots/jquery.inputmask
  1584. * Copyright (c) 2010 - 2014 Robin Herbots
  1585. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1586. * Version: 3.0.50
  1587. */
  1588. (function ($) {
  1589. if ($.fn.inputmask != undefined) {
  1590. function multiMaskScope(actionObj, masksets, opts) {
  1591. function isInputEventSupported(eventName) {
  1592. var el = document.createElement('input'),
  1593. eventName = 'on' + eventName,
  1594. isSupported = (eventName in el);
  1595. if (!isSupported) {
  1596. el.setAttribute(eventName, 'return;');
  1597. isSupported = typeof el[eventName] == 'function';
  1598. }
  1599. el = null;
  1600. return isSupported;
  1601. }
  1602. var PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange",
  1603. isRTL, el, $el, elmasks, activeMasksetIndex;
  1604. function PatchValhookMulti(type) {
  1605. if ($.valHooks[type] == undefined || $.valHooks[type].inputmaskmultipatch != true) {
  1606. var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) { return elem.value; };
  1607. var valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
  1608. elem.value = value;
  1609. return elem;
  1610. };
  1611. $.valHooks[type] = {
  1612. get: function (elem) {
  1613. var $elem = $(elem);
  1614. if ($elem.data('_inputmask-multi')) {
  1615. var data = $elem.data('_inputmask-multi');
  1616. return valueGet(data["elmasks"][data["activeMasksetIndex"]]);
  1617. } else return valueGet(elem);
  1618. },
  1619. set: function (elem, value) {
  1620. var $elem = $(elem);
  1621. var result = valueSet(elem, value);
  1622. if ($elem.data('_inputmask-multi')) $elem.triggerHandler('setvalue');
  1623. return result;
  1624. },
  1625. inputmaskmultipatch: true
  1626. };
  1627. }
  1628. }
  1629. function mcaret(input, begin, end) {
  1630. var npt = input.jquery && input.length > 0 ? input[0] : input, range;
  1631. if (typeof begin == 'number') {
  1632. begin = TranslatePosition(begin);
  1633. end = TranslatePosition(end);
  1634. end = (typeof end == 'number') ? end : begin;
  1635. //store caret for multi scope
  1636. if (npt != el) {
  1637. var data = $(npt).data('_inputmask') || {};
  1638. data["caret"] = { "begin": begin, "end": end };
  1639. $(npt).data('_inputmask', data);
  1640. }
  1641. if (!$(npt).is(":visible")) {
  1642. return;
  1643. }
  1644. npt.scrollLeft = npt.scrollWidth;
  1645. if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
  1646. if (npt.setSelectionRange) {
  1647. npt.selectionStart = begin;
  1648. npt.selectionEnd = end;
  1649. } else if (npt.createTextRange) {
  1650. range = npt.createTextRange();
  1651. range.collapse(true);
  1652. range.moveEnd('character', end);
  1653. range.moveStart('character', begin);
  1654. range.select();
  1655. }
  1656. } else {
  1657. var data = $(npt).data('_inputmask');
  1658. if (!$(npt).is(":visible") && data && data["caret"] != undefined) {
  1659. begin = data["caret"]["begin"];
  1660. end = data["caret"]["end"];
  1661. } else if (npt.setSelectionRange) {
  1662. begin = npt.selectionStart;
  1663. end = npt.selectionEnd;
  1664. } else if (document.selection && document.selection.createRange) {
  1665. range = document.selection.createRange();
  1666. begin = 0 - range.duplicate().moveStart('character', -100000);
  1667. end = begin + range.text.length;
  1668. }
  1669. begin = TranslatePosition(begin);
  1670. end = TranslatePosition(end);
  1671. return { "begin": begin, "end": end };
  1672. }
  1673. }
  1674. function TranslatePosition(pos) {
  1675. if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
  1676. var bffrLght = el.value.length;
  1677. pos = bffrLght - pos;
  1678. }
  1679. return pos;
  1680. }
  1681. function determineActiveMask(eventType, elmasks) {
  1682. if (eventType != "multiMaskScope") {
  1683. if ($.isFunction(opts.determineActiveMasksetIndex))
  1684. activeMasksetIndex = opts.determineActiveMasksetIndex.call($el, eventType, elmasks);
  1685. else {
  1686. var lpc = -1, cp = -1, lvp = -1;;
  1687. $.each(elmasks, function (ndx, lmsk) {
  1688. var data = $(lmsk).data('_inputmask');
  1689. var maskset = data["maskset"];
  1690. var lastValidPosition = -1, validPositionCount = 0, caretPos = mcaret(lmsk).begin;
  1691. for (var posNdx in maskset["validPositions"]) {
  1692. var psNdx = parseInt(posNdx);
  1693. if (psNdx > lastValidPosition) lastValidPosition = psNdx;
  1694. validPositionCount++;
  1695. }
  1696. if (validPositionCount > lpc
  1697. || (validPositionCount == lpc && cp > caretPos && lvp > lastValidPosition)
  1698. || (validPositionCount == lpc && cp == caretPos && lvp < lastValidPosition)
  1699. ) {
  1700. //console.log("lvp " + lastValidPosition + " vpc " + validPositionCount + " caret " + caretPos + " ams " + ndx);
  1701. lpc = validPositionCount;
  1702. cp = caretPos;
  1703. activeMasksetIndex = ndx;
  1704. lvp = lastValidPosition;
  1705. }
  1706. });
  1707. }
  1708. var data = $el.data('_inputmask-multi') || { "activeMasksetIndex": 0, "elmasks": elmasks };
  1709. data["activeMasksetIndex"] = activeMasksetIndex;
  1710. $el.data('_inputmask-multi', data);
  1711. }
  1712. if ($.inArray(eventType, ["focus"]) == -1 && el.value != elmasks[activeMasksetIndex]._valueGet()) {
  1713. var value = $(elmasks[activeMasksetIndex]).val() == "" ? elmasks[activeMasksetIndex]._valueGet() : $(elmasks[activeMasksetIndex]).val();
  1714. el.value = value;
  1715. }
  1716. if ($.inArray(eventType, ["blur", "focus"]) == -1) {
  1717. if ($(elmasks[activeMasksetIndex]).hasClass("focus-inputmask")) {
  1718. var activeCaret = mcaret(elmasks[activeMasksetIndex]);
  1719. mcaret(el, activeCaret.begin, activeCaret.end);
  1720. }
  1721. }
  1722. }
  1723. opts.multi = true;
  1724. function mask(npt) {
  1725. el = npt;
  1726. $el = $(el);
  1727. isRTL = el.dir == "rtl" || opts.numericInput;
  1728. activeMasksetIndex = 0;
  1729. elmasks = $.map(masksets, function (msk, ndx) {
  1730. var elMaskStr = '<input type="text" ';
  1731. if ($el.attr("value")) elMaskStr += 'value="' + $el.attr("value") + '" ';
  1732. if ($el.attr("dir")) elMaskStr += 'dir="' + $el.attr("dir") + '" ';
  1733. elMaskStr += '/>';
  1734. var elmask = $(elMaskStr)[0];
  1735. $(elmask).inputmask($.extend({}, opts, { mask: msk.mask }));
  1736. return elmask;
  1737. });
  1738. $el.data('_inputmask-multi', { "activeMasksetIndex": 0, "elmasks": elmasks });
  1739. if (el.dir == "rtl" || opts.rightAlign)
  1740. $el.css("text-align", "right");
  1741. el.dir = "ltr";
  1742. $el.removeAttr("dir");
  1743. if ($el.attr("value") != "") {
  1744. determineActiveMask("init", elmasks);
  1745. }
  1746. $el.bind("mouseenter blur focus mouseleave click dblclick keydown keypress keypress", function (e) {
  1747. var caretPos = mcaret(el), k, goDetermine = true;
  1748. if (e.type == "keydown") {
  1749. k = e.keyCode;
  1750. if (k == opts.keyCode.DOWN && activeMasksetIndex < elmasks.length - 1) {
  1751. activeMasksetIndex++;
  1752. determineActiveMask("multiMaskScope", elmasks);
  1753. return false;
  1754. } else if (k == opts.keyCode.UP && activeMasksetIndex > 0) {
  1755. activeMasksetIndex--;
  1756. determineActiveMask("multiMaskScope", elmasks);
  1757. return false;
  1758. }
  1759. if (e.ctrlKey || e.shiftKey || e.altKey) {
  1760. return true;
  1761. }
  1762. } else if (e.type == "keypress" && (e.ctrlKey || e.shiftKey || e.altKey)) {
  1763. return true;
  1764. }
  1765. $.each(elmasks, function (ndx, lmnt) {
  1766. if (e.type == "keydown") {
  1767. k = e.keyCode;
  1768. if (k == opts.keyCode.BACKSPACE && lmnt._valueGet().length < caretPos.begin) {
  1769. return;
  1770. } else if (k == opts.keyCode.TAB) {
  1771. goDetermine = false;
  1772. } else if (k == opts.keyCode.RIGHT) {
  1773. mcaret(lmnt, caretPos.begin + 1, caretPos.end + 1);
  1774. goDetermine = false;
  1775. return;
  1776. } else if (k == opts.keyCode.LEFT) {
  1777. mcaret(lmnt, caretPos.begin - 1, caretPos.end - 1);
  1778. goDetermine = false;
  1779. return;
  1780. }
  1781. }
  1782. if ($.inArray(e.type, ["click"]) != -1) {
  1783. mcaret(lmnt, TranslatePosition(caretPos.begin), TranslatePosition(caretPos.end));
  1784. if (caretPos.begin != caretPos.end) {
  1785. goDetermine = false;
  1786. return;
  1787. }
  1788. }
  1789. if ($.inArray(e.type, ["keydown"]) != -1 && caretPos.begin != caretPos.end) {
  1790. mcaret(lmnt, caretPos.begin, caretPos.end);
  1791. }
  1792. $(lmnt).triggerHandler(e);
  1793. });
  1794. if (goDetermine) {
  1795. setTimeout(function () {
  1796. determineActiveMask(e.type, elmasks);
  1797. }, 0);
  1798. }
  1799. });
  1800. $el.bind(PasteEventType + " dragdrop drop setvalue", function (e) {
  1801. var caretPos = mcaret(el);
  1802. setTimeout(function () {
  1803. $.each(elmasks, function (ndx, lmnt) {
  1804. lmnt._valueSet(el.value);
  1805. $(lmnt).triggerHandler(e);
  1806. });
  1807. setTimeout(function () {
  1808. determineActiveMask(e.type, elmasks);
  1809. }, 0);
  1810. }, 0);
  1811. });
  1812. PatchValhookMulti(el.type);
  1813. }
  1814. //action object
  1815. if (actionObj != undefined) {
  1816. switch (actionObj["action"]) {
  1817. case "isComplete":
  1818. $el = $(actionObj["el"]);
  1819. var imdata = $el.data('_inputmask-multi'),
  1820. activeMask = imdata["elmasks"][imdata["activeMasksetIndex"]];
  1821. return $(activeMask).inputmask("isComplete");
  1822. case "unmaskedvalue":
  1823. $el = actionObj["$input"];
  1824. var imdata = $el.data('_inputmask-multi'),
  1825. activeMask = imdata["elmasks"][imdata["activeMasksetIndex"]];
  1826. return $(activeMask).inputmask("unmaskedvalue");
  1827. case "mask":
  1828. mask(actionObj["el"]);
  1829. break;
  1830. case "format": //TODO
  1831. $el = $({});
  1832. $el.data('_inputmask', {
  1833. 'maskset': maskset,
  1834. 'opts': opts,
  1835. 'isRTL': opts.numericInput
  1836. });
  1837. if (opts.numericInput) {
  1838. isRTL = true;
  1839. }
  1840. var valueBuffer = actionObj["value"].split('');
  1841. checkVal($el, false, false, isRTL ? valueBuffer.reverse() : valueBuffer, true);
  1842. return isRTL ? getBuffer().reverse().join('') : getBuffer().join('');
  1843. case "isValid": //TODO
  1844. $el = $({});
  1845. $el.data('_inputmask', {
  1846. 'maskset': maskset,
  1847. 'opts': opts,
  1848. 'isRTL': opts.numericInput
  1849. });
  1850. if (opts.numericInput) {
  1851. isRTL = true;
  1852. }
  1853. var valueBuffer = actionObj["value"].split('');
  1854. checkVal($el, false, true, isRTL ? valueBuffer.reverse() : valueBuffer);
  1855. return isComplete(getBuffer());
  1856. case "getemptymask": //TODO
  1857. $el = $(actionObj["el"]);
  1858. maskset = $el.data('_inputmask')['maskset'];
  1859. opts = $el.data('_inputmask')['opts'];
  1860. return getBufferTemplate();
  1861. case "remove": //TODO
  1862. var el = actionObj["el"];
  1863. $el = $(el);
  1864. maskset = $el.data('_inputmask')['maskset'];
  1865. opts = $el.data('_inputmask')['opts'];
  1866. //writeout the unmaskedvalue
  1867. el._valueSet(unmaskedvalue($el));
  1868. //unbind all events
  1869. $el.unbind(".inputmask");
  1870. $el.removeClass('focus-inputmask');
  1871. //clear data
  1872. $el.removeData('_inputmask');
  1873. //restore the value property
  1874. var valueProperty;
  1875. if (Object.getOwnPropertyDescriptor)
  1876. valueProperty = Object.getOwnPropertyDescriptor(el, "value");
  1877. if (valueProperty && valueProperty.get) {
  1878. if (el._valueGet) {
  1879. Object.defineProperty(el, "value", {
  1880. get: el._valueGet,
  1881. set: el._valueSet
  1882. });
  1883. }
  1884. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  1885. if (el._valueGet) {
  1886. el.__defineGetter__("value", el._valueGet);
  1887. el.__defineSetter__("value", el._valueSet);
  1888. }
  1889. }
  1890. try { //try catch needed for IE7 as it does not supports deleting fns
  1891. delete el._valueGet;
  1892. delete el._valueSet;
  1893. } catch (e) {
  1894. el._valueGet = undefined;
  1895. el._valueSet = undefined;
  1896. }
  1897. break;
  1898. }
  1899. }
  1900. };
  1901. $.extend($.inputmask.defaults, {
  1902. //multi-masks
  1903. multi: false, //do not alter - internal use
  1904. determineActiveMasksetIndex: undefined //override determineActiveMasksetIndex - args => eventType, elmasks - return int
  1905. });
  1906. $.inputmask._fn = $.fn.inputmask;
  1907. $.fn.inputmask = function (fn, options) {
  1908. if (typeof fn === "string") {
  1909. if ($.inputmask._fn("_detectScope", options, undefined, undefined, fn))
  1910. return $.inputmask._fn.call(this, fn, options, multiMaskScope, "_inputmask-multi");
  1911. else return $.inputmask._fn.call(this, fn, options);
  1912. } else if (typeof fn == "object") {
  1913. if ($.inputmask._fn("_detectScope", fn))
  1914. return $.inputmask._fn.call(this, fn, options, multiMaskScope, "_inputmask-multi");
  1915. else return $.inputmask._fn.call(this, fn, options);
  1916. } else if (fn == undefined)
  1917. return $.inputmask._fn.call(this, fn, options);
  1918. };
  1919. }
  1920. })(jQuery);
  1921. /*
  1922. Input Mask plugin extensions
  1923. http://github.com/RobinHerbots/jquery.inputmask
  1924. Copyright (c) 2010 - 2014 Robin Herbots
  1925. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1926. Version: 3.0.50
  1927. Optional extensions on the jquery.inputmask base
  1928. */
  1929. (function ($) {
  1930. //extra definitions
  1931. $.extend($.inputmask.defaults.definitions, {
  1932. 'A': {
  1933. validator: "[A-Za-z]",
  1934. cardinality: 1,
  1935. casing: "upper" //auto uppercasing
  1936. },
  1937. '#': {
  1938. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1939. cardinality: 1,
  1940. casing: "upper"
  1941. }
  1942. });
  1943. $.extend($.inputmask.defaults.aliases, {
  1944. 'url': {
  1945. mask: "ir",
  1946. placeholder: "",
  1947. separator: "",
  1948. defaultPrefix: "http://",
  1949. regex: {
  1950. urlpre1: new RegExp("[fh]"),
  1951. urlpre2: new RegExp("(ft|ht)"),
  1952. urlpre3: new RegExp("(ftp|htt)"),
  1953. urlpre4: new RegExp("(ftp:|http|ftps)"),
  1954. urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"),
  1955. urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"),
  1956. urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"),
  1957. urlpre8: new RegExp("(ftp://|ftps://|http://|https://)")
  1958. },
  1959. definitions: {
  1960. 'i': {
  1961. validator: function (chrs, maskset, pos, strict, opts) {
  1962. return true;
  1963. },
  1964. cardinality: 8,
  1965. prevalidator: (function () {
  1966. var result = [], prefixLimit = 8;
  1967. for (var i = 0; i < prefixLimit; i++) {
  1968. result[i] = (function () {
  1969. var j = i;
  1970. return {
  1971. validator: function (chrs, maskset, pos, strict, opts) {
  1972. if (opts.regex["urlpre" + (j + 1)]) {
  1973. var tmp = chrs, k;
  1974. if (((j + 1) - chrs.length) > 0) {
  1975. tmp = maskset.buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp;
  1976. }
  1977. var isValid = opts.regex["urlpre" + (j + 1)].test(tmp);
  1978. if (!strict && !isValid) {
  1979. pos = pos - j;
  1980. for (k = 0; k < opts.defaultPrefix.length; k++) {
  1981. maskset.buffer[pos] = opts.defaultPrefix[k]; pos++;
  1982. }
  1983. for (k = 0; k < tmp.length - 1; k++) {
  1984. maskset.buffer[pos] = tmp[k]; pos++;
  1985. }
  1986. return { "pos": pos };
  1987. }
  1988. return isValid;
  1989. } else {
  1990. return false;
  1991. }
  1992. }, cardinality: j
  1993. };
  1994. })();
  1995. }
  1996. return result;
  1997. })()
  1998. },
  1999. "r": {
  2000. validator: ".",
  2001. cardinality: 50
  2002. }
  2003. },
  2004. insertMode: false,
  2005. autoUnmask: false
  2006. },
  2007. "ip": { //ip-address mask
  2008. mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
  2009. definitions: {
  2010. 'i': {
  2011. validator: function (chrs, maskset, pos, strict, opts) {
  2012. if (pos - 1 > -1 && maskset.buffer[pos - 1] != ".") {
  2013. chrs = maskset.buffer[pos - 1] + chrs;
  2014. if (pos - 2 > -1 && maskset.buffer[pos - 2] != ".") {
  2015. chrs = maskset.buffer[pos - 2] + chrs;
  2016. } else chrs = "0" + chrs;
  2017. } else chrs = "00" + chrs;
  2018. return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
  2019. },
  2020. cardinality: 1
  2021. }
  2022. }
  2023. },
  2024. "email": {
  2025. mask: "*{1,20}[.*{1,20}][.*{1,20}][.*{1,20}]@*{1,20}.*{2,6}[.*{1,2}]",
  2026. greedy: false,
  2027. onBeforePaste: function (pastedValue, opts) {
  2028. pastedValue = pastedValue.toLowerCase();
  2029. return pastedValue.replace("mailto:", "");
  2030. },
  2031. definitions: {
  2032. '*': {
  2033. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  2034. cardinality: 1,
  2035. casing: "lower"
  2036. }
  2037. }
  2038. }
  2039. });
  2040. })(jQuery);
  2041. /*
  2042. Input Mask plugin extensions
  2043. http://github.com/RobinHerbots/jquery.inputmask
  2044. Copyright (c) 2010 - 2014 Robin Herbots
  2045. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2046. Version: 3.0.50
  2047. Optional extensions on the jquery.inputmask base
  2048. */
  2049. (function ($) {
  2050. //date & time aliases
  2051. $.extend($.inputmask.defaults.definitions, {
  2052. 'h': { //hours
  2053. validator: "[01][0-9]|2[0-3]",
  2054. cardinality: 2,
  2055. prevalidator: [{ validator: "[0-2]", cardinality: 1 }]
  2056. },
  2057. 's': { //seconds || minutes
  2058. validator: "[0-5][0-9]",
  2059. cardinality: 2,
  2060. prevalidator: [{ validator: "[0-5]", cardinality: 1 }]
  2061. },
  2062. 'd': { //basic day
  2063. validator: "0[1-9]|[12][0-9]|3[01]",
  2064. cardinality: 2,
  2065. prevalidator: [{ validator: "[0-3]", cardinality: 1 }]
  2066. },
  2067. 'm': { //basic month
  2068. validator: "0[1-9]|1[012]",
  2069. cardinality: 2,
  2070. prevalidator: [{ validator: "[01]", cardinality: 1 }]
  2071. },
  2072. 'y': { //basic year
  2073. validator: "(19|20)\\d{2}",
  2074. cardinality: 4,
  2075. prevalidator: [
  2076. { validator: "[12]", cardinality: 1 },
  2077. { validator: "(19|20)", cardinality: 2 },
  2078. { validator: "(19|20)\\d", cardinality: 3 }
  2079. ]
  2080. }
  2081. });
  2082. $.extend($.inputmask.defaults.aliases, {
  2083. 'dd/mm/yyyy': {
  2084. mask: "1/2/y",
  2085. placeholder: "dd/mm/yyyy",
  2086. regex: {
  2087. val1pre: new RegExp("[0-3]"), //daypre
  2088. val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), //day
  2089. val2pre: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])"); }, //monthpre
  2090. 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
  2091. },
  2092. leapday: "29/02/",
  2093. separator: '/',
  2094. yearrange: { minyear: 1900, maxyear: 2099 },
  2095. isInYearRange: function (chrs, minyear, maxyear) {
  2096. if (isNaN(chrs)) return false;
  2097. var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length)));
  2098. var enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
  2099. return (!isNaN(enteredyear) ? minyear <= enteredyear && enteredyear <= maxyear : false) ||
  2100. (!isNaN(enteredyear2) ? minyear <= enteredyear2 && enteredyear2 <= maxyear : false);
  2101. },
  2102. determinebaseyear: function (minyear, maxyear, hint) {
  2103. var currentyear = (new Date()).getFullYear();
  2104. if (minyear > currentyear) return minyear;
  2105. if (maxyear < currentyear) {
  2106. var maxYearPrefix = maxyear.toString().slice(0, 2);
  2107. var maxYearPostfix = maxyear.toString().slice(2, 4);
  2108. while (maxyear < maxYearPrefix + hint) {
  2109. maxYearPrefix--;
  2110. }
  2111. var maxxYear = maxYearPrefix + maxYearPostfix;
  2112. return minyear > maxxYear ? minyear : maxxYear;
  2113. }
  2114. return currentyear;
  2115. },
  2116. onKeyUp: function (e, buffer, opts) {
  2117. var $input = $(this);
  2118. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2119. var today = new Date();
  2120. $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString());
  2121. }
  2122. },
  2123. definitions: {
  2124. '1': { //val1 ~ day or month
  2125. validator: function (chrs, maskset, pos, strict, opts) {
  2126. var isValid = opts.regex.val1.test(chrs);
  2127. if (!strict && !isValid) {
  2128. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  2129. isValid = opts.regex.val1.test("0" + chrs.charAt(0));
  2130. if (isValid) {
  2131. maskset.buffer[pos - 1] = "0";
  2132. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "pos": pos, "c": chrs.charAt(0) };
  2133. }
  2134. }
  2135. }
  2136. return isValid;
  2137. },
  2138. cardinality: 2,
  2139. prevalidator: [{
  2140. validator: function (chrs, maskset, pos, strict, opts) {
  2141. if (!isNaN(maskset.buffer[pos + 1])) chrs += maskset.buffer[pos + 1];
  2142. var isValid = chrs.length == 1 ? opts.regex.val1pre.test(chrs) : opts.regex.val1.test(chrs);
  2143. if (!strict && !isValid) {
  2144. isValid = opts.regex.val1.test("0" + chrs);
  2145. if (isValid) {
  2146. maskset.buffer[pos] = "0";
  2147. pos++;
  2148. return { "pos": pos };
  2149. }
  2150. }
  2151. return isValid;
  2152. }, cardinality: 1
  2153. }]
  2154. },
  2155. '2': { //val2 ~ day or month
  2156. validator: function (chrs, maskset, pos, strict, opts) {
  2157. var frontValue = (opts.mask.indexOf("2") == opts.mask.length - 1) ? maskset.buffer.join('').substr(5, 3) : maskset.buffer.join('').substr(0, 3);
  2158. if (frontValue.indexOf(opts.placeholder[0]) != -1) frontValue = "01" + opts.separator;
  2159. var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
  2160. if (!strict && !isValid) {
  2161. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  2162. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
  2163. if (isValid) {
  2164. maskset.buffer[pos - 1] = "0";
  2165. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "pos": pos, "c": chrs.charAt(0) };
  2166. }
  2167. }
  2168. }
  2169. //check leap yeap
  2170. if ((opts.mask.indexOf("2") == opts.mask.length - 1) && isValid) {
  2171. var dayMonthValue = maskset.buffer.join('').substr(4, 4) + chrs;
  2172. if (dayMonthValue != opts.leapday)
  2173. return true;
  2174. else {
  2175. var year = parseInt(maskset.buffer.join('').substr(0, 4), 10); //detect leap year
  2176. if (year % 4 === 0)
  2177. if (year % 100 === 0)
  2178. if (year % 400 === 0)
  2179. return true;
  2180. else return false;
  2181. else return true;
  2182. else return false;
  2183. }
  2184. }
  2185. return isValid;
  2186. },
  2187. cardinality: 2,
  2188. prevalidator: [{
  2189. validator: function (chrs, maskset, pos, strict, opts) {
  2190. if (!isNaN(maskset.buffer[pos + 1])) chrs += maskset.buffer[pos + 1];
  2191. var frontValue = (opts.mask.indexOf("2") == opts.mask.length - 1) ? maskset.buffer.join('').substr(5, 3) : maskset.buffer.join('').substr(0, 3);
  2192. if (frontValue.indexOf(opts.placeholder[0]) != -1) frontValue = "01" + opts.separator;
  2193. var isValid = chrs.length == 1 ? opts.regex.val2pre(opts.separator).test(frontValue + chrs) : opts.regex.val2(opts.separator).test(frontValue + chrs);
  2194. if (!strict && !isValid) {
  2195. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
  2196. if (isValid) {
  2197. maskset.buffer[pos] = "0";
  2198. pos++;
  2199. return { "pos": pos };
  2200. }
  2201. }
  2202. return isValid;
  2203. }, cardinality: 1
  2204. }]
  2205. },
  2206. 'y': { //year
  2207. validator: function (chrs, maskset, pos, strict, opts) {
  2208. if (opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  2209. var dayMonthValue = maskset.buffer.join('').substr(0, 6);
  2210. if (dayMonthValue != opts.leapday)
  2211. return true;
  2212. else {
  2213. var year = parseInt(chrs, 10);//detect leap year
  2214. if (year % 4 === 0)
  2215. if (year % 100 === 0)
  2216. if (year % 400 === 0)
  2217. return true;
  2218. else return false;
  2219. else return true;
  2220. else return false;
  2221. }
  2222. } else return false;
  2223. },
  2224. cardinality: 4,
  2225. prevalidator: [
  2226. {
  2227. validator: function (chrs, maskset, pos, strict, opts) {
  2228. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2229. if (!strict && !isValid) {
  2230. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 1);
  2231. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2232. if (isValid) {
  2233. maskset.buffer[pos++] = yearPrefix[0];
  2234. return { "pos": pos };
  2235. }
  2236. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 2);
  2237. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2238. if (isValid) {
  2239. maskset.buffer[pos++] = yearPrefix[0];
  2240. maskset.buffer[pos++] = yearPrefix[1];
  2241. return { "pos": pos };
  2242. }
  2243. }
  2244. return isValid;
  2245. },
  2246. cardinality: 1
  2247. },
  2248. {
  2249. validator: function (chrs, maskset, pos, strict, opts) {
  2250. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2251. if (!strict && !isValid) {
  2252. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  2253. isValid = opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear);
  2254. if (isValid) {
  2255. maskset.buffer[pos++] = yearPrefix[1];
  2256. return { "pos": pos };
  2257. }
  2258. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  2259. if (opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  2260. var dayMonthValue = maskset.buffer.join('').substr(0, 6);
  2261. if (dayMonthValue != opts.leapday)
  2262. isValid = true;
  2263. else {
  2264. var year = parseInt(chrs, 10);//detect leap year
  2265. if (year % 4 === 0)
  2266. if (year % 100 === 0)
  2267. if (year % 400 === 0)
  2268. isValid = true;
  2269. else isValid = false;
  2270. else isValid = true;
  2271. else isValid = false;
  2272. }
  2273. } else isValid = false;
  2274. if (isValid) {
  2275. maskset.buffer[pos - 1] = yearPrefix[0];
  2276. maskset.buffer[pos++] = yearPrefix[1];
  2277. maskset.buffer[pos++] = chrs[0];
  2278. return { "refreshFromBuffer": { start: pos - 3, end: pos }, "pos": pos };
  2279. }
  2280. }
  2281. return isValid;
  2282. }, cardinality: 2
  2283. },
  2284. {
  2285. validator: function (chrs, maskset, pos, strict, opts) {
  2286. return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2287. }, cardinality: 3
  2288. }
  2289. ]
  2290. }
  2291. },
  2292. insertMode: false,
  2293. autoUnmask: false
  2294. },
  2295. 'mm/dd/yyyy': {
  2296. placeholder: "mm/dd/yyyy",
  2297. alias: "dd/mm/yyyy", //reuse functionality of dd/mm/yyyy alias
  2298. regex: {
  2299. 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
  2300. 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
  2301. val1pre: new RegExp("[01]"), //monthpre
  2302. val1: new RegExp("0[1-9]|1[012]") //month
  2303. },
  2304. leapday: "02/29/",
  2305. onKeyUp: function (e, buffer, opts) {
  2306. var $input = $(this);
  2307. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2308. var today = new Date();
  2309. $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
  2310. }
  2311. }
  2312. },
  2313. 'yyyy/mm/dd': {
  2314. mask: "y/1/2",
  2315. placeholder: "yyyy/mm/dd",
  2316. alias: "mm/dd/yyyy",
  2317. leapday: "/02/29",
  2318. onKeyUp: function (e, buffer, opts) {
  2319. var $input = $(this);
  2320. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2321. var today = new Date();
  2322. $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString());
  2323. }
  2324. }
  2325. },
  2326. 'dd.mm.yyyy': {
  2327. mask: "1.2.y",
  2328. placeholder: "dd.mm.yyyy",
  2329. leapday: "29.02.",
  2330. separator: '.',
  2331. alias: "dd/mm/yyyy"
  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. 'mm.dd.yyyy': {
  2341. mask: "1.2.y",
  2342. placeholder: "mm.dd.yyyy",
  2343. leapday: "02.29.",
  2344. separator: '.',
  2345. alias: "mm/dd/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. 'yyyy.mm.dd': {
  2355. mask: "y.1.2",
  2356. placeholder: "yyyy.mm.dd",
  2357. leapday: ".02.29",
  2358. separator: '.',
  2359. alias: "yyyy/mm/dd"
  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. 'datetime': {
  2369. mask: "1/2/y h:s",
  2370. placeholder: "dd/mm/yyyy hh:mm",
  2371. alias: "dd/mm/yyyy",
  2372. regex: {
  2373. hrspre: new RegExp("[012]"), //hours pre
  2374. hrs24: new RegExp("2[0-4]|1[3-9]"),
  2375. hrs: new RegExp("[01][0-9]|2[0-4]"), //hours
  2376. ampm: new RegExp("^[a|p|A|P][m|M]")
  2377. },
  2378. timeseparator: ':',
  2379. hourFormat: "24", // or 12
  2380. definitions: {
  2381. 'h': { //hours
  2382. validator: function (chrs, maskset, pos, strict, opts) {
  2383. if (opts.hourFormat == "24") {
  2384. if (parseInt(chrs, 10) == 24) {
  2385. maskset.buffer[pos - 1] = "0";
  2386. maskset.buffer[pos] = "0";
  2387. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "c": "0" };
  2388. }
  2389. }
  2390. var isValid = opts.regex.hrs.test(chrs);
  2391. if (!strict && !isValid) {
  2392. if (chrs.charAt(1) == opts.timeseparator || "-.:".indexOf(chrs.charAt(1)) != -1) {
  2393. isValid = opts.regex.hrs.test("0" + chrs.charAt(0));
  2394. if (isValid) {
  2395. maskset.buffer[pos - 1] = "0";
  2396. maskset.buffer[pos] = chrs.charAt(0);
  2397. pos++;
  2398. return { "refreshFromBuffer": { start: pos - 2, end: pos }, "pos": pos, "c": opts.timeseparator };
  2399. }
  2400. }
  2401. }
  2402. if (isValid && opts.hourFormat !== "24" && opts.regex.hrs24.test(chrs)) {
  2403. var tmp = parseInt(chrs, 10);
  2404. if (tmp == 24) {
  2405. maskset.buffer[pos + 5] = "a";
  2406. maskset.buffer[pos + 6] = "m";
  2407. } else {
  2408. maskset.buffer[pos + 5] = "p";
  2409. maskset.buffer[pos + 6] = "m";
  2410. }
  2411. tmp = tmp - 12;
  2412. if (tmp < 10) {
  2413. maskset.buffer[pos] = tmp.toString();
  2414. maskset.buffer[pos - 1] = "0";
  2415. } else {
  2416. maskset.buffer[pos] = tmp.toString().charAt(1);
  2417. maskset.buffer[pos - 1] = tmp.toString().charAt(0);
  2418. }
  2419. return { "refreshFromBuffer": { start: pos - 1, end: pos + 6 }, "c": maskset.buffer[pos] };
  2420. }
  2421. return isValid;
  2422. },
  2423. cardinality: 2,
  2424. prevalidator: [{
  2425. validator: function (chrs, maskset, pos, strict, opts) {
  2426. var isValid = opts.regex.hrspre.test(chrs);
  2427. if (!strict && !isValid) {
  2428. isValid = opts.regex.hrs.test("0" + chrs);
  2429. if (isValid) {
  2430. maskset.buffer[pos] = "0";
  2431. pos++;
  2432. return { "pos": pos };
  2433. }
  2434. }
  2435. return isValid;
  2436. }, cardinality: 1
  2437. }]
  2438. },
  2439. 't': { //am/pm
  2440. validator: function (chrs, maskset, pos, strict, opts) {
  2441. return opts.regex.ampm.test(chrs + "m");
  2442. },
  2443. casing: "lower",
  2444. cardinality: 1
  2445. }
  2446. },
  2447. insertMode: false,
  2448. autoUnmask: false
  2449. },
  2450. 'datetime12': {
  2451. mask: "1/2/y h:s t\\m",
  2452. placeholder: "dd/mm/yyyy hh:mm xm",
  2453. alias: "datetime",
  2454. hourFormat: "12"
  2455. },
  2456. 'hh:mm t': {
  2457. mask: "h:s t\\m",
  2458. placeholder: "hh:mm xm",
  2459. alias: "datetime",
  2460. hourFormat: "12"
  2461. },
  2462. 'h:s t': {
  2463. mask: "h:s t\\m",
  2464. placeholder: "hh:mm xm",
  2465. alias: "datetime",
  2466. hourFormat: "12"
  2467. },
  2468. 'hh:mm:ss': {
  2469. mask: "h:s:s",
  2470. autoUnmask: false
  2471. },
  2472. 'hh:mm': {
  2473. mask: "h:s",
  2474. autoUnmask: false
  2475. },
  2476. 'date': {
  2477. alias: "dd/mm/yyyy" // "mm/dd/yyyy"
  2478. },
  2479. 'mm/yyyy': {
  2480. mask: "1/y",
  2481. placeholder: "mm/yyyy",
  2482. leapday: "donotuse",
  2483. separator: '/',
  2484. alias: "mm/dd/yyyy"
  2485. }
  2486. });
  2487. })(jQuery);
  2488. /*
  2489. Input Mask plugin extensions
  2490. http://github.com/RobinHerbots/jquery.inputmask
  2491. Copyright (c) 2010 - 2014 Robin Herbots
  2492. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2493. Version: 3.0.50
  2494. Optional extensions on the jquery.inputmask base
  2495. */
  2496. (function ($) {
  2497. //number aliases
  2498. $.extend($.inputmask.defaults.aliases, {
  2499. 'numeric': {
  2500. mask: function (opts) {
  2501. if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
  2502. opts.integerDigits = opts.repeat;
  2503. }
  2504. opts.repeat = 0;
  2505. opts.autoGroup = opts.autoGroup && opts.groupSeparator != "";
  2506. if (opts.autoGroup && isFinite(opts.integerDigits)) {
  2507. var seps = Math.floor(opts.integerDigits / opts.groupSize);
  2508. var mod = opts.integerDigits % opts.groupSize;
  2509. opts.integerDigits += mod == 0 ? seps - 1 : seps;
  2510. }
  2511. opts.definitions[":"].placeholder = opts.radixPoint;
  2512. var mask = opts.prefix;
  2513. mask += "[+]";
  2514. mask += "~{1," + opts.integerDigits + "}";
  2515. if (opts.digits != undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
  2516. if (opts.digitsOptional)
  2517. mask += "[" + ":" + "~{" + opts.digits + "}]";
  2518. else mask += ":" + "~{" + opts.digits + "}";
  2519. }
  2520. mask += opts.suffix;
  2521. return mask;
  2522. },
  2523. placeholder: "",
  2524. greedy: false,
  2525. digits: "*", //number of fractionalDigits
  2526. digitsOptional: true,
  2527. groupSeparator: "",//",", // | "."
  2528. radixPoint: ".",
  2529. groupSize: 3,
  2530. autoGroup: false,
  2531. allowPlus: true,
  2532. allowMinus: true,
  2533. integerDigits: "+", //number of integerDigits
  2534. prefix: "",
  2535. suffix: "",
  2536. rightAlign: true,
  2537. postFormat: function (buffer, pos, reformatOnly, opts) {
  2538. var needsRefresh = false;
  2539. if (opts.groupSeparator == "" || ($.inArray(opts.radixPoint, buffer) != -1 && pos > $.inArray(opts.radixPoint, buffer))) return { pos: pos };
  2540. var cbuf = buffer.slice();
  2541. if (!reformatOnly) {
  2542. cbuf.splice(pos, 0, "?"); //set position indicator
  2543. }
  2544. var bufVal = cbuf.join('');
  2545. if (opts.autoGroup || (reformatOnly && bufVal.indexOf(opts.groupSeparator) != -1)) {
  2546. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
  2547. needsRefresh = bufVal.indexOf(opts.groupSeparator) == 0;
  2548. bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), '');
  2549. var radixSplit = bufVal.split(opts.radixPoint);
  2550. bufVal = radixSplit[0];
  2551. if (bufVal != (opts.prefix + "?0") && bufVal.length > (opts.groupSize + opts.prefix.length)) {
  2552. needsRefresh = true;
  2553. var reg = new RegExp('([-\+]?[\\d\?]+)([\\d\?]{' + opts.groupSize + '})');
  2554. while (reg.test(bufVal)) {
  2555. bufVal = bufVal.replace(reg, '$1' + opts.groupSeparator + '$2');
  2556. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  2557. }
  2558. }
  2559. if (radixSplit.length > 1)
  2560. bufVal += opts.radixPoint + radixSplit[1];
  2561. }
  2562. buffer.length = bufVal.length; //align the length
  2563. for (var i = 0, l = bufVal.length; i < l; i++) {
  2564. buffer[i] = bufVal.charAt(i);
  2565. }
  2566. var newPos = $.inArray("?", buffer);
  2567. if (!reformatOnly) buffer.splice(newPos, 1);
  2568. return { pos: reformatOnly ? pos : newPos, "refreshFromBuffer": needsRefresh };
  2569. },
  2570. onKeyDown: function (e, buffer, opts) {
  2571. if (opts.autoGroup && (e.keyCode == opts.keyCode.DELETE || e.keyCode == opts.keyCode.BACKSPACE)) {
  2572. return opts.postFormat(buffer, 0, true, opts);
  2573. }
  2574. },
  2575. onKeyPress: function (e, buffer, opts) {
  2576. var k = (e.which || e.charCode || e.keyCode);
  2577. if (k == 46 && e.shiftKey == false && opts.radixPoint == ",") k = 44;
  2578. if (opts.autoGroup && String.fromCharCode(k) == opts.radixPoint) {
  2579. var refresh = opts.postFormat(buffer, 0, true, opts);
  2580. refresh.caret = $.inArray(opts.radixPoint, buffer) + 1;
  2581. return refresh;
  2582. }
  2583. },
  2584. regex: {
  2585. integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
  2586. },
  2587. negationhandler: function (chrs, buffer, pos, strict, opts) {
  2588. if (!strict && opts.allowMinus && chrs === "-") {
  2589. var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
  2590. if (matchRslt.length > 0) {
  2591. if (buffer[matchRslt.index] == "+") {
  2592. return { "pos": matchRslt.index, "c": "-", "remove": matchRslt.index, "caret": pos };
  2593. } else if (buffer[matchRslt.index] == "-") {
  2594. return { "remove": matchRslt.index, "caret": pos - 1 };
  2595. } else {
  2596. return { "pos": matchRslt.index, "c": "-", "caret": pos + 1 };
  2597. }
  2598. }
  2599. }
  2600. return false;
  2601. },
  2602. definitions: {
  2603. '~': {
  2604. validator: function (chrs, maskset, pos, strict, opts) {
  2605. var isValid = opts.negationhandler(chrs, maskset.buffer, pos, strict, opts);
  2606. if (!isValid) {
  2607. isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
  2608. if (isValid === true) isValid = { pos: pos };
  2609. if (isValid != false && !strict) {
  2610. //handle 0 for integerpart
  2611. var matchRslt = maskset.buffer.join('').match(opts.regex.integerPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  2612. if (matchRslt) {
  2613. if (matchRslt["0"][0].indexOf("0") == 0 && pos >= opts.prefix.length) {
  2614. if (radixPosition == -1 || (pos <= radixPosition && maskset["validPositions"][radixPosition] == undefined)) {
  2615. maskset.buffer.splice(matchRslt.index, 1);
  2616. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index;
  2617. $.extend(isValid, { "pos": pos, "remove": matchRslt.index });
  2618. } else if (pos > matchRslt.index && pos <= radixPosition) {
  2619. maskset.buffer.splice(matchRslt.index, 1);
  2620. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index;
  2621. $.extend(isValid, { "pos": pos, "remove": matchRslt.index });
  2622. }
  2623. } else if (chrs == "0" && pos <= matchRslt.index) {
  2624. return false;
  2625. }
  2626. }
  2627. //handle overwrite when fixed precision
  2628. if (opts.digitsOptional === false && pos > radixPosition) {
  2629. return { "pos": pos, "remove": pos };
  2630. }
  2631. }
  2632. if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
  2633. isValid = $.extend(isValid, opts.postFormat(maskset.buffer, pos, false, opts));
  2634. }
  2635. }
  2636. return isValid;
  2637. },
  2638. cardinality: 1,
  2639. prevalidator: null
  2640. },
  2641. '+': {
  2642. validator: function (chrs, maskset, pos, strict, opts) {
  2643. var signed = "[";
  2644. if (opts.allowMinus === true) signed += "-";
  2645. if (opts.allowPlus === true) signed += "\+";
  2646. signed += "]";
  2647. var isValid = new RegExp(signed).test(chrs);
  2648. return isValid;
  2649. },
  2650. cardinality: 1,
  2651. prevalidator: null
  2652. },
  2653. ':': {
  2654. validator: function (chrs, maskset, pos, strict, opts) {
  2655. var isValid = opts.negationhandler(chrs, maskset.buffer, pos, strict, opts);
  2656. if (!isValid) {
  2657. var radix = "[" + $.inputmask.escapeRegex.call(this, opts.radixPoint) + "]";
  2658. isValid = new RegExp(radix).test(chrs);
  2659. }
  2660. return isValid;
  2661. },
  2662. cardinality: 1,
  2663. prevalidator: null,
  2664. placeholder: "" //radixpoint will be set in the mask function
  2665. }
  2666. },
  2667. insertMode: true,
  2668. autoUnmask: false,
  2669. onUnMask: function (maskedValue, unmaskedValue, opts) {
  2670. var processValue = maskedValue.replace(opts.prefix, "");
  2671. processValue = processValue.replace(opts.suffix, "");
  2672. processValue = processValue.replace(new RegExp(opts.groupSeparator, "g"), "");
  2673. processValue = processValue.replace(opts.radixPoint, ".");
  2674. return Number(processValue);
  2675. },
  2676. isComplete: function (buffer, opts) {
  2677. var maskedValue = buffer.join(''), bufClone = buffer.slice();
  2678. //verify separator positions
  2679. opts.postFormat(bufClone, 0, true, opts);
  2680. if (bufClone.join('') != maskedValue) return false;
  2681. var processValue = maskedValue.replace(opts.prefix, "");
  2682. processValue = processValue.replace(opts.suffix, "");
  2683. processValue = processValue.replace(new RegExp(opts.groupSeparator, "g"), "");
  2684. processValue = processValue.replace(opts.radixPoint, ".");
  2685. return isFinite(processValue);
  2686. },
  2687. onBeforeMask: function (initialValue, opts) {
  2688. return isFinite(initialValue) ? initialValue.toString().replace(".", opts.radixPoint) : initialValue;
  2689. }
  2690. },
  2691. 'decimal': {
  2692. alias: "numeric"
  2693. },
  2694. 'integer': {
  2695. alias: "numeric",
  2696. digits: "0"
  2697. }
  2698. });
  2699. })(jQuery);
  2700. /*
  2701. Input Mask plugin extensions
  2702. http://github.com/RobinHerbots/jquery.inputmask
  2703. Copyright (c) 2010 - 2014 Robin Herbots
  2704. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2705. Version: 3.0.50
  2706. Regex extensions on the jquery.inputmask base
  2707. Allows for using regular expressions as a mask
  2708. */
  2709. (function ($) {
  2710. $.extend($.inputmask.defaults.aliases, { // $(selector).inputmask("Regex", { regex: "[0-9]*"}
  2711. 'Regex': {
  2712. mask: "r",
  2713. greedy: false,
  2714. repeat: "*",
  2715. regex: null,
  2716. regexTokens: null,
  2717. //Thx to https://github.com/slevithan/regex-colorizer for the tokenizer regex
  2718. 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,
  2719. quantifierFilter: /[0-9]+[^,]/,
  2720. isComplete: function(buffer, opts){
  2721. return new RegExp(opts.regex).test(buffer.join(''));
  2722. },
  2723. definitions: {
  2724. 'r': {
  2725. validator: function (chrs, maskset, pos, strict, opts) {
  2726. function regexToken(isGroup, isQuantifier) {
  2727. this.matches = [];
  2728. this.isGroup = isGroup || false;
  2729. this.isQuantifier = isQuantifier || false;
  2730. this.quantifier = { min: 1, max: 1 };
  2731. this.repeaterPart = undefined;
  2732. }
  2733. function analyseRegex() {
  2734. var currentToken = new regexToken(), match, m, opengroups = [];
  2735. opts.regexTokens = [];
  2736. // The tokenizer regex does most of the tokenization grunt work
  2737. while (match = opts.tokenizer.exec(opts.regex)) {
  2738. m = match[0];
  2739. switch (m.charAt(0)) {
  2740. case "(": // Group opening
  2741. opengroups.push(new regexToken(true));
  2742. break;
  2743. case ")": // Group closing
  2744. var groupToken = opengroups.pop();
  2745. if (opengroups.length > 0) {
  2746. opengroups[opengroups.length - 1]["matches"].push(groupToken);
  2747. } else {
  2748. currentToken.matches.push(groupToken);
  2749. }
  2750. break;
  2751. case "{": case "+": case "*": //Quantifier
  2752. var quantifierToken = new regexToken(false, true);
  2753. m = m.replace(/[{}]/g, "");
  2754. 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]));
  2755. quantifierToken.quantifier = { min: mq0, max: mq1 };
  2756. if (opengroups.length > 0) {
  2757. var matches = opengroups[opengroups.length - 1]["matches"];
  2758. match = matches.pop();
  2759. if (!match["isGroup"]) {
  2760. var groupToken = new regexToken(true);
  2761. groupToken.matches.push(match);
  2762. match = groupToken;
  2763. }
  2764. matches.push(match);
  2765. matches.push(quantifierToken);
  2766. } else {
  2767. match = currentToken.matches.pop();
  2768. if (!match["isGroup"]) {
  2769. var groupToken = new regexToken(true);
  2770. groupToken.matches.push(match);
  2771. match = groupToken;
  2772. }
  2773. currentToken.matches.push(match);
  2774. currentToken.matches.push(quantifierToken);
  2775. }
  2776. break;
  2777. default:
  2778. if (opengroups.length > 0) {
  2779. opengroups[opengroups.length - 1]["matches"].push(m);
  2780. } else {
  2781. currentToken.matches.push(m);
  2782. }
  2783. break;
  2784. }
  2785. }
  2786. if (currentToken.matches.length > 0)
  2787. opts.regexTokens.push(currentToken);
  2788. };
  2789. function validateRegexToken(token, fromGroup) {
  2790. var isvalid = false;
  2791. if (fromGroup) {
  2792. regexPart += "(";
  2793. openGroupCount++;
  2794. }
  2795. for (var mndx = 0; mndx < token["matches"].length; mndx++) {
  2796. var matchToken = token["matches"][mndx];
  2797. if (matchToken["isGroup"] == true) {
  2798. isvalid = validateRegexToken(matchToken, true);
  2799. } else if (matchToken["isQuantifier"] == true) {
  2800. var crrntndx = $.inArray(matchToken, token["matches"]),
  2801. matchGroup = token["matches"][crrntndx - 1];
  2802. var regexPartBak = regexPart;
  2803. if (isNaN(matchToken.quantifier.max)) {
  2804. while (matchToken["repeaterPart"] && matchToken["repeaterPart"] != regexPart && matchToken["repeaterPart"].length > regexPart.length) {
  2805. isvalid = validateRegexToken(matchGroup, true);
  2806. if (isvalid) break;
  2807. }
  2808. isvalid = isvalid || validateRegexToken(matchGroup, true);
  2809. if (isvalid) matchToken["repeaterPart"] = regexPart;
  2810. regexPart = regexPartBak + matchToken.quantifier.max;
  2811. } else {
  2812. for (var i = 0, qm = matchToken.quantifier.max - 1; i < qm; i++) {
  2813. isvalid = validateRegexToken(matchGroup, true);
  2814. if (isvalid) break;
  2815. }
  2816. regexPart = regexPartBak + "{" + matchToken.quantifier.min + "," + matchToken.quantifier.max + "}";
  2817. }
  2818. } else if (matchToken["matches"] != undefined) {
  2819. for (var k = 0; k < matchToken.length; k++) {
  2820. isvalid = validateRegexToken(matchToken[k], fromGroup);
  2821. if (isvalid) break;
  2822. }
  2823. } else {
  2824. var testExp;
  2825. if (matchToken[0] == "[") {
  2826. testExp = regexPart;
  2827. testExp += matchToken;
  2828. for (var j = 0; j < openGroupCount; j++) {
  2829. testExp += ")";
  2830. }
  2831. var exp = new RegExp("^(" + testExp + ")$");
  2832. isvalid = exp.test(bufferStr);
  2833. } else {
  2834. for (var l = 0, tl = matchToken.length; l < tl; l++) {
  2835. if (matchToken[l] == "\\") continue;
  2836. testExp = regexPart;
  2837. testExp += matchToken.substr(0, l + 1);
  2838. testExp = testExp.replace(/\|$/, "");
  2839. for (var j = 0; j < openGroupCount; j++) {
  2840. testExp += ")";
  2841. }
  2842. var exp = new RegExp("^(" + testExp + ")$");
  2843. isvalid = exp.test(bufferStr);
  2844. if (isvalid) break;
  2845. }
  2846. }
  2847. regexPart += matchToken;
  2848. }
  2849. if (isvalid) break;
  2850. }
  2851. if (fromGroup) {
  2852. regexPart += ")";
  2853. openGroupCount--;
  2854. }
  2855. return isvalid;
  2856. }
  2857. if (opts.regexTokens == null) {
  2858. analyseRegex();
  2859. }
  2860. var cbuffer = maskset.buffer.slice(), regexPart = "", isValid = false, openGroupCount = 0;
  2861. cbuffer.splice(pos, 0, chrs);
  2862. var bufferStr = cbuffer.join('');
  2863. for (var i = 0; i < opts.regexTokens.length; i++) {
  2864. var regexToken = opts.regexTokens[i];
  2865. isValid = validateRegexToken(regexToken, regexToken["isGroup"]);
  2866. if (isValid) break;
  2867. }
  2868. return isValid;
  2869. },
  2870. cardinality: 1
  2871. }
  2872. }
  2873. }
  2874. });
  2875. })(jQuery);
  2876. /*
  2877. Input Mask plugin extensions
  2878. http://github.com/RobinHerbots/jquery.inputmask
  2879. Copyright (c) 2010 - 2014 Robin Herbots
  2880. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2881. Version: 3.0.50
  2882. Phone extension.
  2883. When using this extension make sure you specify the correct url to get the masks
  2884. $(selector).inputmask("phone", {
  2885. url: "Scripts/jquery.inputmask/phone-codes/phone-codes.json",
  2886. onKeyValidation: function () { //show some metadata in the console
  2887. console.log($(this).inputmask("getmetadata")["name_en"]);
  2888. }
  2889. });
  2890. */
  2891. (function ($) {
  2892. $.extend($.inputmask.defaults.aliases, {
  2893. 'phone': {
  2894. url: "phone-codes/phone-codes.json",
  2895. mask: function (opts) {
  2896. opts.definitions = {
  2897. 'p': {
  2898. validator: function () { return false; },
  2899. cardinality: 1
  2900. },
  2901. '#': {
  2902. validator: "[0-9]",
  2903. cardinality: 1
  2904. }
  2905. };
  2906. var maskList = [];
  2907. $.ajax({
  2908. url: opts.url,
  2909. async: false,
  2910. dataType: 'json',
  2911. success: function (response) {
  2912. maskList = response;
  2913. }
  2914. });
  2915. maskList.splice(0, 0, "+p(ppp)ppp-pppp");
  2916. return maskList;
  2917. },
  2918. nojumps: true,
  2919. nojumpsThreshold: 1
  2920. },
  2921. 'phonebe': {
  2922. url: "phone-codes/phone-be.json",
  2923. mask: function (opts) {
  2924. opts.definitions = {
  2925. 'p': {
  2926. validator: function () { return false; },
  2927. cardinality: 1
  2928. },
  2929. '#': {
  2930. validator: "[0-9]",
  2931. cardinality: 1
  2932. }
  2933. };
  2934. var maskList = [];
  2935. $.ajax({
  2936. url: opts.url,
  2937. async: false,
  2938. dataType: 'json',
  2939. success: function (response) {
  2940. maskList = response;
  2941. }
  2942. });
  2943. maskList.splice(0, 0, "+32(ppp)ppp-pppp");
  2944. return maskList;
  2945. },
  2946. nojumps: true,
  2947. nojumpsThreshold: 4
  2948. }
  2949. });
  2950. })(jQuery);