jquery.inputmask.bundle.js 165 KB

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