jquery.inputmask.bundle.js 162 KB

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