jquery.inputmask.bundle.js 155 KB

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