jquery.inputmask.bundle.js 164 KB

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