jquery.inputmask.bundle.js 155 KB

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