jquery.inputmask.bundle.js 157 KB

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