jquery.inputmask.bundle.js 163 KB

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