jquery.inputmask.bundle.js 161 KB

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