jquery.inputmask.bundle.js 166 KB

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