jquery.inputmask.bundle.js 162 KB

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