jquery.inputmask.bundle.js 162 KB

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