jquery.inputmask.bundle.js 158 KB

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