bootstrapValidator.js 198 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382
  1. /**
  2. * BootstrapValidator (http://bootstrapvalidator.com)
  3. *
  4. * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  5. *
  6. * @version v0.5.0-dev
  7. * @author https://twitter.com/nghuuphuoc
  8. * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
  9. * @license MIT
  10. */
  11. (function($) {
  12. var BootstrapValidator = function(form, options) {
  13. this.$form = $(form);
  14. this.options = $.extend({}, BootstrapValidator.DEFAULT_OPTIONS, options);
  15. this.$invalidFields = $([]); // Array of invalid fields
  16. this.$submitButton = null; // The submit button which is clicked to submit form
  17. // Validating status
  18. this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
  19. this.STATUS_VALIDATING = 'VALIDATING';
  20. this.STATUS_INVALID = 'INVALID';
  21. this.STATUS_VALID = 'VALID';
  22. // Determine the event that is fired when user change the field value
  23. // Most modern browsers supports input event except IE 7, 8.
  24. // IE 9 supports input event but the event is still not fired if I press the backspace key.
  25. // Get IE version
  26. // https://gist.github.com/padolsey/527683/#comment-7595
  27. var ieVersion = (function() {
  28. var v = 3, div = document.createElement('div'), a = div.all || [];
  29. while (div.innerHTML = '<!--[if gt IE '+(++v)+']><br><![endif]-->', a[0]);
  30. return v > 4 ? v : !v;
  31. }());
  32. var el = document.createElement('div');
  33. this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input';
  34. // The flag to indicate that the form is ready to submit when a remote/callback validator returns
  35. this._submitIfValid = null;
  36. // Field elements
  37. this._cacheFields = {};
  38. this._init();
  39. };
  40. // The default options
  41. BootstrapValidator.DEFAULT_OPTIONS = {
  42. // The form CSS class
  43. elementClass: 'bv-form',
  44. // Default invalid message
  45. message: 'This value is not valid',
  46. // The error messages container
  47. // It can be:
  48. // * 'tooltip' if you want to use Bootstrap tooltip to show error messages
  49. // * 'popover' if you want to use Bootstrap popover to show error messages
  50. // * a CSS selector indicating the container
  51. //
  52. // In the first two cases, since the tooltip/popover should be small enough, the plugin only shows only one error message
  53. // You also can define the message container for particular field
  54. container: null,
  55. // The field will not be live validated if its length is less than this number of characters
  56. threshold: null,
  57. // Indicate fields which won't be validated
  58. // By default, the plugin will not validate the following kind of fields:
  59. // - disabled
  60. // - hidden
  61. // - invisible
  62. //
  63. // The setting consists of jQuery filters. Accept 3 formats:
  64. // - A string. Use a comma to separate filter
  65. // - An array. Each element is a filter
  66. // - An array. Each element can be a callback function
  67. // function($field, validator) {
  68. // $field is jQuery object representing the field element
  69. // validator is the BootstrapValidator instance
  70. // return true or false;
  71. // }
  72. //
  73. // The 3 following settings are equivalent:
  74. //
  75. // 1) ':disabled, :hidden, :not(:visible)'
  76. // 2) [':disabled', ':hidden', ':not(:visible)']
  77. // 3) [':disabled', ':hidden', function($field) {
  78. // return !$field.is(':visible');
  79. // }]
  80. excluded: [':disabled', ':hidden', ':not(:visible)'],
  81. // Shows ok/error/loading icons based on the field validity.
  82. // This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
  83. // Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
  84. // In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
  85. //
  86. // Examples:
  87. // - Use Glyphicons icons:
  88. // feedbackIcons: {
  89. // valid: 'glyphicon glyphicon-ok',
  90. // invalid: 'glyphicon glyphicon-remove',
  91. // validating: 'glyphicon glyphicon-refresh'
  92. // }
  93. // - Use FontAwesome icons:
  94. // feedbackIcons: {
  95. // valid: 'fa fa-check',
  96. // invalid: 'fa fa-times',
  97. // validating: 'fa fa-refresh'
  98. // }
  99. feedbackIcons: {
  100. valid: null,
  101. invalid: null,
  102. validating: null
  103. },
  104. // The submit buttons selector
  105. // These buttons will be disabled to prevent the valid form from multiple submissions
  106. submitButtons: '[type="submit"]',
  107. // The custom submit handler
  108. // It will prevent the form from the default submission
  109. //
  110. // submitHandler: function(validator, form, submitButton) {
  111. // - validator is the BootstrapValidator instance
  112. // - form is the jQuery object presenting the current form
  113. // - submitButton is the jQuery object presenting the clicked button
  114. // }
  115. submitHandler: null,
  116. // Live validating option
  117. // Can be one of 3 values:
  118. // - enabled: The plugin validates fields as soon as they are changed
  119. // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
  120. // - submitted: The live validating is enabled after the form is submitted
  121. live: 'enabled',
  122. // Map the field name with validator rules
  123. fields: {}
  124. };
  125. BootstrapValidator.prototype = {
  126. constructor: BootstrapValidator,
  127. /**
  128. * Init form
  129. */
  130. _init: function() {
  131. var that = this,
  132. options = {
  133. excluded: this.$form.attr('data-bv-excluded'),
  134. trigger: this.$form.attr('data-bv-trigger'),
  135. message: this.$form.attr('data-bv-message'),
  136. container: this.$form.attr('data-bv-container'),
  137. submitButtons: this.$form.attr('data-bv-submitbuttons'),
  138. threshold: this.$form.attr('data-bv-threshold'),
  139. live: this.$form.attr('data-bv-live'),
  140. fields: {},
  141. feedbackIcons: {
  142. valid: this.$form.attr('data-bv-feedbackicons-valid'),
  143. invalid: this.$form.attr('data-bv-feedbackicons-invalid'),
  144. validating: this.$form.attr('data-bv-feedbackicons-validating')
  145. }
  146. };
  147. this.$form
  148. // Disable client side validation in HTML 5
  149. .attr('novalidate', 'novalidate')
  150. .addClass(this.options.elementClass)
  151. // Disable the default submission first
  152. .on('submit.bv', function(e) {
  153. e.preventDefault();
  154. that.validate();
  155. })
  156. .on('click.bv', this.options.submitButtons, function() {
  157. that.$submitButton = $(this);
  158. // The user just click the submit button
  159. that._submitIfValid = true;
  160. })
  161. // Find all fields which have either "name" or "data-bv-field" attribute
  162. .find('[name], [data-bv-field]')
  163. .each(function() {
  164. var $field = $(this);
  165. if (that._isExcluded($field)) {
  166. return;
  167. }
  168. var field = $field.attr('name') || $field.attr('data-bv-field'),
  169. opts = that._parseOptions($field);
  170. if (opts) {
  171. $field.attr('data-bv-field', field);
  172. options.fields[field] = $.extend({}, opts, options.fields[field]);
  173. }
  174. });
  175. this.options = $.extend(true, this.options, options);
  176. for (var field in this.options.fields) {
  177. this._initField(field);
  178. }
  179. this.$form.trigger($.Event('init.form.bv'), {
  180. options: this.options
  181. });
  182. },
  183. /**
  184. * Parse the validator options from HTML attributes
  185. *
  186. * @param {jQuery} $field The field element
  187. * @returns {Object}
  188. */
  189. _parseOptions: function($field) {
  190. var field = $field.attr('name') || $field.attr('data-bv-field'),
  191. validators = {},
  192. validator,
  193. v, // Validator name
  194. enabled,
  195. optionName,
  196. optionValue,
  197. html5AttrName,
  198. html5AttrMap;
  199. for (v in $.fn.bootstrapValidator.validators) {
  200. validator = $.fn.bootstrapValidator.validators[v];
  201. enabled = $field.attr('data-bv-' + v.toLowerCase()) + '';
  202. html5AttrMap = ('function' == typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;
  203. if ((html5AttrMap && enabled != 'false')
  204. || (html5AttrMap !== true && ('' == enabled || 'true' == enabled)))
  205. {
  206. // Try to parse the options via attributes
  207. validator.html5Attributes = validator.html5Attributes || { message: 'message' };
  208. validators[v] = $.extend({}, html5AttrMap == true ? {} : html5AttrMap, validators[v]);
  209. for (html5AttrName in validator.html5Attributes) {
  210. optionName = validator.html5Attributes[html5AttrName];
  211. optionValue = $field.attr('data-bv-' + v.toLowerCase() + '-' + html5AttrName);
  212. if (optionValue) {
  213. if ('true' == optionValue) {
  214. optionValue = true;
  215. } else if ('false' == optionValue) {
  216. optionValue = false;
  217. }
  218. validators[v][optionName] = optionValue;
  219. }
  220. }
  221. }
  222. }
  223. var opts = {
  224. feedbackIcons: $field.attr('data-bv-feedbackicons'),
  225. trigger: $field.attr('data-bv-trigger'),
  226. message: $field.attr('data-bv-message'),
  227. container: $field.attr('data-bv-container'),
  228. selector: $field.attr('data-bv-selector'),
  229. threshold: $field.attr('data-bv-threshold'),
  230. validators: validators
  231. },
  232. emptyOptions = $.isEmptyObject(opts), // Check if the field options are set using HTML attributes
  233. emptyValidators = $.isEmptyObject(validators); // Check if the field validators are set using HTML attributes
  234. if (!emptyValidators || (!emptyOptions && this.options.fields[field])) {
  235. opts.validators = validators;
  236. return opts;
  237. } else {
  238. return null;
  239. }
  240. },
  241. /**
  242. * Init field
  243. *
  244. * @param {String} field The field name
  245. */
  246. _initField: function(field) {
  247. if (this.options.fields[field] == null || this.options.fields[field].validators == null) {
  248. return;
  249. }
  250. var fields = this.getFieldElements(field);
  251. // We don't need to validate non-existing fields
  252. if (fields == []) {
  253. delete this.options.fields[field];
  254. return;
  255. }
  256. for (var validatorName in this.options.fields[field].validators) {
  257. if (!$.fn.bootstrapValidator.validators[validatorName]) {
  258. delete this.options.fields[field].validators[validatorName];
  259. }
  260. }
  261. if (this.options.fields[field]['enabled'] == null) {
  262. this.options.fields[field]['enabled'] = true;
  263. }
  264. fields.attr('data-bv-field', field);
  265. for (var i = 0; i < fields.length; i++) {
  266. this._initFieldElement($(fields[i]));
  267. }
  268. },
  269. /**
  270. * Init field element
  271. *
  272. * @param {jQuery} $field The field element
  273. */
  274. _initFieldElement: function($field) {
  275. var that = this,
  276. field = $field.attr('data-bv-field'),
  277. fields = this.getFieldElements(field),
  278. index = fields.index($field),
  279. type = $field.attr('type'),
  280. total = fields.length,
  281. updateAll = (total == 1) || ('radio' == type) || ('checkbox' == type),
  282. $parent = $field.parents('.form-group'),
  283. // Allow user to indicate where the error messages are shown
  284. container = this.options.fields[field].container || this.options.container,
  285. $message = (container && container != 'tooltip' && container != 'popover') ? $(container) : this._getMessageContainer($field);
  286. if (container && container != 'tooltip' && container != 'popover') {
  287. $message.addClass('has-error');
  288. }
  289. // Remove all error messages and feedback icons
  290. $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove();
  291. $parent.find('i[data-bv-icon-for="' + field + '"]').remove();
  292. // Whenever the user change the field value, mark it as not validated yet
  293. var event = ('radio' == type || 'checkbox' == type || 'file' == type || 'SELECT' == $field.get(0).tagName) ? 'change' : this._changeEvent;
  294. $field.off(event + '.update.bv').on(event + '.update.bv', function() {
  295. // Reset the flag
  296. that._submitIfValid = false;
  297. that.updateElementStatus($(this), that.STATUS_NOT_VALIDATED);
  298. });
  299. // Create help block elements for showing the error messages
  300. $field.data('bv.messages', $message);
  301. for (var validatorName in this.options.fields[field].validators) {
  302. $field.data('bv.result.' + validatorName, this.STATUS_NOT_VALIDATED);
  303. if (!updateAll || index == total - 1) {
  304. $('<small/>')
  305. .css('display', 'none')
  306. .addClass('help-block')
  307. .attr('data-bv-validator', validatorName)
  308. .attr('data-bv-for', field)
  309. .html(this.options.fields[field].validators[validatorName].message || this.options.fields[field].message || this.options.message)
  310. .appendTo($message);
  311. }
  312. }
  313. // Prepare the feedback icons
  314. // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
  315. if (this.options.fields[field].feedbackIcons !== false && this.options.fields[field].feedbackIcons !== 'false'
  316. && this.options.feedbackIcons
  317. && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
  318. && (!updateAll || index == total - 1))
  319. {
  320. $parent.removeClass('has-success').removeClass('has-error').addClass('has-feedback');
  321. var $icon = $('<i/>').css('display', 'none').addClass('form-control-feedback').attr('data-bv-icon-for', field).insertAfter($field);
  322. // The feedback icon does not render correctly if there is no label
  323. // https://github.com/twbs/bootstrap/issues/12873
  324. if ($parent.find('label').length == 0) {
  325. $icon.css('top', 0);
  326. }
  327. // Fix feedback icons in input-group
  328. if ($parent.find('.input-group-addon').length != 0) {
  329. $icon.css({
  330. 'top': 0,
  331. 'z-index': 100
  332. });
  333. }
  334. }
  335. // Set live mode
  336. var trigger = this.options.fields[field].trigger || this.options.trigger || event,
  337. events = $.map(trigger.split(' '), function(item) {
  338. return item + '.live.bv';
  339. }).join(' ');
  340. switch (this.options.live) {
  341. case 'submitted':
  342. break;
  343. case 'disabled':
  344. $field.off(events);
  345. break;
  346. case 'enabled':
  347. default:
  348. $field.off(events).on(events, function() {
  349. if (that._exceedThreshold($(this))) {
  350. that.validateFieldElement($(this));
  351. }
  352. });
  353. break;
  354. }
  355. },
  356. /**
  357. * Get the element to place the error messages
  358. *
  359. * @param {jQuery} $field The field element
  360. * @returns {jQuery}
  361. */
  362. _getMessageContainer: function($field) {
  363. var $parent = $field.parent();
  364. if ($parent.hasClass('form-group')) {
  365. return $parent;
  366. }
  367. var cssClasses = $parent.attr('class');
  368. if (!cssClasses) {
  369. return this._getMessageContainer($parent);
  370. }
  371. cssClasses = cssClasses.split(' ');
  372. var n = cssClasses.length;
  373. for (var i = 0; i < n; i++) {
  374. if (/^col-(xs|sm|md|lg)-\d+$/.test(cssClasses[i]) || /^col-(xs|sm|md|lg)-offset-\d+$/.test(cssClasses[i])) {
  375. return $parent;
  376. }
  377. }
  378. return this._getMessageContainer($parent);
  379. },
  380. /**
  381. * Called when all validations are completed
  382. */
  383. _submit: function() {
  384. var isValid = this.isValid(),
  385. eventType = isValid ? 'success.form.bv' : 'error.form.bv',
  386. e = $.Event(eventType);
  387. this.$form.trigger(e);
  388. // Call default handler
  389. // Check if whether the submit button is clicked
  390. if (this.$submitButton) {
  391. isValid ? this._onSuccess(e) : this._onError(e);
  392. }
  393. },
  394. /**
  395. * Check if the field is excluded.
  396. * Returning true means that the field will not be validated
  397. *
  398. * @param {jQuery} $field The field element
  399. * @returns {Boolean}
  400. */
  401. _isExcluded: function($field) {
  402. if (this.options.excluded) {
  403. // Convert to array first
  404. if ('string' == typeof this.options.excluded) {
  405. this.options.excluded = $.map(this.options.excluded.split(','), function(item) {
  406. // Trim the spaces
  407. return $.trim(item);
  408. });
  409. }
  410. var length = this.options.excluded.length;
  411. for (var i = 0; i < length; i++) {
  412. if (('string' == typeof this.options.excluded[i] && $field.is(this.options.excluded[i]))
  413. || ('function' == typeof this.options.excluded[i] && this.options.excluded[i].call(this, $field, this) == true))
  414. {
  415. return true;
  416. }
  417. }
  418. }
  419. return false;
  420. },
  421. /**
  422. * Check if the number of characters of field value exceed the threshold or not
  423. *
  424. * @param {jQuery} $field The field element
  425. * @returns {Boolean}
  426. */
  427. _exceedThreshold: function($field) {
  428. var field = $field.attr('data-bv-field'),
  429. threshold = this.options.fields[field].threshold || this.options.threshold;
  430. if (!threshold) {
  431. return true;
  432. }
  433. var type = $field.attr('type'),
  434. cannotType = ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit'].indexOf(type) != -1;
  435. return (cannotType || $field.val().length >= threshold);
  436. },
  437. // --- Events ---
  438. /**
  439. * The default handler of error.form.bv event.
  440. * It will be called when there is a invalid field
  441. *
  442. * @param {jQuery.Event} e The jQuery event object
  443. */
  444. _onError: function(e) {
  445. if (e.isDefaultPrevented()) {
  446. return;
  447. }
  448. if ('submitted' == this.options.live) {
  449. // Enable live mode
  450. this.options.live = 'enabled';
  451. var that = this;
  452. for (var field in this.options.fields) {
  453. (function(f) {
  454. var fields = that.getFieldElements(f);
  455. if (fields.length) {
  456. var type = $(fields[0]).attr('type'),
  457. event = ('radio' == type || 'checkbox' == type || 'file' == type || 'SELECT' == $(fields[0]).get(0).tagName) ? 'change' : that._changeEvent,
  458. trigger = that.options.fields[field].trigger || that.options.trigger || event,
  459. events = $.map(trigger.split(' '), function(item) {
  460. return item + '.live.bv';
  461. }).join(' ');
  462. for (var i = 0; i < fields.length; i++) {
  463. $(fields[i]).off(events).on(events, function() {
  464. if (that._exceedThreshold($(this))) {
  465. that.validateFieldElement($(this));
  466. }
  467. });
  468. }
  469. }
  470. })(field);
  471. }
  472. }
  473. // Focus to the first invalid field
  474. this.$invalidFields.eq(0).focus();
  475. },
  476. /**
  477. * The default handler of success.form.bv event.
  478. * It will be called when all the fields are valid
  479. *
  480. * @param {jQuery.Event} e The jQuery event object
  481. */
  482. _onSuccess: function(e) {
  483. if (e.isDefaultPrevented()) {
  484. return;
  485. }
  486. // Call the custom submission if enabled
  487. if (this.options.submitHandler && 'function' == typeof this.options.submitHandler) {
  488. // If you want to submit the form inside your submit handler, please call defaultSubmit() method
  489. this.options.submitHandler.call(this, this, this.$form, this.$submitButton);
  490. } else {
  491. this.disableSubmitButtons(true).defaultSubmit();
  492. }
  493. },
  494. /**
  495. * Called after validating a field element
  496. *
  497. * @param {jQuery} $field The field element
  498. */
  499. _onValidateFieldCompleted: function($field) {
  500. var field = $field.attr('data-bv-field'),
  501. validators = this.options.fields[field].validators,
  502. counter = {},
  503. numValidators = 0;
  504. counter[this.STATUS_NOT_VALIDATED] = 0;
  505. counter[this.STATUS_VALIDATING] = 0;
  506. counter[this.STATUS_INVALID] = 0;
  507. counter[this.STATUS_VALID] = 0;
  508. for (var validatorName in validators) {
  509. numValidators++;
  510. var result = $field.data('bv.result.' + validatorName);
  511. if (result) {
  512. counter[result]++;
  513. }
  514. }
  515. var index = this.$invalidFields.index($field);
  516. if (counter[this.STATUS_VALID] == numValidators) {
  517. // Remove from the list of invalid fields
  518. if (index != -1) {
  519. this.$invalidFields.splice(index, 1);
  520. }
  521. this.$form.trigger($.Event('success.field.bv'), {
  522. field: field,
  523. element: $field
  524. });
  525. }
  526. // If all validators are completed and there is at least one validator which doesn't pass
  527. else if (counter[this.STATUS_NOT_VALIDATED] == 0 && counter[this.STATUS_VALIDATING] == 0 && counter[this.STATUS_INVALID] > 0) {
  528. // Add to the list of invalid fields
  529. if (index == -1) {
  530. this.$invalidFields = this.$invalidFields.add($field);
  531. }
  532. this.$form.trigger($.Event('error.field.bv'), {
  533. field: field,
  534. element: $field
  535. });
  536. }
  537. },
  538. // --- Public methods ---
  539. /**
  540. * Retrieve the field elements by given name
  541. *
  542. * @param {String} field The field name
  543. * @returns {null|jQuery[]}
  544. */
  545. getFieldElements: function(field) {
  546. if (!this._cacheFields[field]) {
  547. this._cacheFields[field] = (this.options.fields[field] && this.options.fields[field].selector)
  548. ? $(this.options.fields[field].selector)
  549. : this.$form.find('[name="' + field + '"]');
  550. }
  551. return this._cacheFields[field];
  552. },
  553. /**
  554. * Disable/enable submit buttons
  555. *
  556. * @param {Boolean} disabled Can be true or false
  557. * @returns {BootstrapValidator}
  558. */
  559. disableSubmitButtons: function(disabled) {
  560. if (!disabled) {
  561. this.$form.find(this.options.submitButtons).removeAttr('disabled');
  562. } else if (this.options.live != 'disabled') {
  563. // Don't disable if the live validating mode is disabled
  564. this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
  565. }
  566. return this;
  567. },
  568. /**
  569. * Validate the form
  570. *
  571. * @returns {BootstrapValidator}
  572. */
  573. validate: function() {
  574. if (!this.options.fields) {
  575. return this;
  576. }
  577. this.disableSubmitButtons(true);
  578. for (var field in this.options.fields) {
  579. this.validateField(field);
  580. }
  581. this._submit();
  582. return this;
  583. },
  584. /**
  585. * Validate given field
  586. *
  587. * @param {String} field The field name
  588. * @returns {BootstrapValidator}
  589. */
  590. validateField: function(field) {
  591. var fields = this.getFieldElements(field),
  592. type = fields.attr('type'),
  593. n = (('radio' == type) || ('checkbox' == type)) ? 1 : fields.length;
  594. for (var i = 0; i < n; i++) {
  595. this.validateFieldElement($(fields[i]));
  596. }
  597. return this;
  598. },
  599. /**
  600. * Validate field element
  601. *
  602. * @param {jQuery} $field The field element
  603. * @returns {BootstrapValidator}
  604. */
  605. validateFieldElement: function($field) {
  606. var that = this,
  607. field = $field.attr('data-bv-field'),
  608. fields = this.getFieldElements(field),
  609. type = $field.attr('type'),
  610. updateAll = (fields && fields.length == 1) || ('radio' == type) || ('checkbox' == type),
  611. validators = this.options.fields[field].validators,
  612. validatorName,
  613. validateResult;
  614. if (this.options.fields[field]['enabled'] == false || this._isExcluded($field)) {
  615. return this;
  616. }
  617. for (validatorName in validators) {
  618. if ($field.data('bv.dfs.' + validatorName)) {
  619. $field.data('bv.dfs.' + validatorName).reject();
  620. }
  621. // Don't validate field if it is already done
  622. var result = $field.data('bv.result.' + validatorName);
  623. if (result == this.STATUS_VALID || result == this.STATUS_INVALID) {
  624. this._onValidateFieldCompleted($field);
  625. continue;
  626. }
  627. $field.data('bv.result.' + validatorName, this.STATUS_VALIDATING);
  628. validateResult = $.fn.bootstrapValidator.validators[validatorName].validate(this, $field, validators[validatorName]);
  629. // validateResult can be a $.Deferred object ...
  630. if ('object' == typeof validateResult) {
  631. updateAll ? this.updateStatus(field, this.STATUS_VALIDATING, validatorName)
  632. : this.updateElementStatus($field, this.STATUS_VALIDATING, validatorName);
  633. $field.data('bv.dfs.' + validatorName, validateResult);
  634. validateResult.done(function($f, v, isValid, message) {
  635. // v is validator name
  636. $f.removeData('bv.dfs.' + v);
  637. if (message) {
  638. // Update the error message
  639. $field.data('bv.messages').find('.help-block[data-bv-validator="' + v + '"][data-bv-for="' + $f.attr('data-bv-field') + '"]').html(message);
  640. }
  641. updateAll ? that.updateStatus($f.attr('data-bv-field'), isValid ? that.STATUS_VALID : that.STATUS_INVALID, v)
  642. : that.updateElementStatus($f, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
  643. if (isValid && that._submitIfValid == true) {
  644. // If a remote validator returns true and the form is ready to submit, then do it
  645. that._submit();
  646. }
  647. });
  648. }
  649. // ... or a boolean value
  650. else if ('boolean' == typeof validateResult) {
  651. updateAll ? this.updateStatus(field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName)
  652. : this.updateElementStatus($field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  653. }
  654. }
  655. return this;
  656. },
  657. /**
  658. * Update all validating results of elements which have the same field name
  659. *
  660. * @param {String} field The field name
  661. * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
  662. * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
  663. * @returns {BootstrapValidator}
  664. */
  665. updateStatus: function(field, status, validatorName) {
  666. var fields = this.getFieldElements(field),
  667. type = fields.attr('type'),
  668. n = (('radio' == type) || ('checkbox' == type)) ? 1 : fields.length;
  669. for (var i = 0; i < n; i++) {
  670. this.updateElementStatus($(fields[i]), status, validatorName);
  671. }
  672. return this;
  673. },
  674. /**
  675. * Update validating result of given element
  676. *
  677. * @param {jQuery} $field The field element
  678. * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
  679. * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
  680. * @returns {BootstrapValidator}
  681. */
  682. updateElementStatus: function($field, status, validatorName) {
  683. var that = this,
  684. field = $field.attr('data-bv-field'),
  685. $parent = $field.parents('.form-group'),
  686. $message = $field.data('bv.messages'),
  687. $allErrors = $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]'),
  688. $errors = validatorName ? $allErrors.filter('[data-bv-validator="' + validatorName + '"]') : $allErrors,
  689. $icon = $parent.find('.form-control-feedback[data-bv-icon-for="' + field + '"]'),
  690. container = this.options.fields[field].container || this.options.container,
  691. isValidField = null;
  692. // Update status
  693. if (validatorName) {
  694. $field.data('bv.result.' + validatorName, status);
  695. } else {
  696. for (var v in this.options.fields[field].validators) {
  697. $field.data('bv.result.' + v, status);
  698. }
  699. }
  700. // Show/hide error elements and feedback icons
  701. $errors.attr('data-bv-result', status);
  702. switch (status) {
  703. case this.STATUS_VALIDATING:
  704. isValidField = null;
  705. this.disableSubmitButtons(true);
  706. $parent.removeClass('has-success').removeClass('has-error');
  707. if ($icon) {
  708. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).addClass(this.options.feedbackIcons.validating).show();
  709. }
  710. break;
  711. case this.STATUS_INVALID:
  712. isValidField = false;
  713. this.disableSubmitButtons(true);
  714. $parent.removeClass('has-success').addClass('has-error');
  715. if ($icon) {
  716. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
  717. }
  718. break;
  719. case this.STATUS_VALID:
  720. // If the field is valid (passes all validators)
  721. isValidField = $allErrors.filter(function() {
  722. var v = $(this).attr('data-bv-validator');
  723. return $field.data('bv.result.' + v) != that.STATUS_VALID;
  724. }).length == 0;
  725. this.disableSubmitButtons(this.$submitButton ? !this.isValid() : !isValidField);
  726. if ($icon) {
  727. $icon
  728. .removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).removeClass(this.options.feedbackIcons.valid)
  729. .addClass(isValidField ? this.options.feedbackIcons.valid : this.options.feedbackIcons.invalid)
  730. .show();
  731. }
  732. $parent.removeClass('has-error has-success').addClass(this.isValidContainer($parent) ? 'has-success' : 'has-error');
  733. break;
  734. case this.STATUS_NOT_VALIDATED:
  735. default:
  736. isValidField = null;
  737. this.disableSubmitButtons(false);
  738. $parent.removeClass('has-success').removeClass('has-error');
  739. if ($icon) {
  740. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).hide();
  741. }
  742. break;
  743. }
  744. switch (true) {
  745. // Only show the first error message if it is placed inside a tooltip ...
  746. case ($icon && 'tooltip' == container):
  747. (isValidField === false)
  748. ? $icon.css('cursor', 'pointer').tooltip('destroy').tooltip({
  749. html: true,
  750. placement: 'top',
  751. title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
  752. })
  753. : $icon.css('cursor', '').tooltip('destroy');
  754. break;
  755. // ... or popover
  756. case ($icon && 'popover' == container):
  757. (isValidField === false)
  758. ? $icon.css('cursor', 'pointer').popover('destroy').popover({
  759. content: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html(),
  760. html: true,
  761. placement: 'top',
  762. trigger: 'hover click'
  763. })
  764. : $icon.css('cursor', '').popover('destroy');
  765. break;
  766. default:
  767. (status == this.STATUS_INVALID) ? $errors.show() : $errors.hide();
  768. break;
  769. }
  770. // Trigger an event
  771. this.$form.trigger($.Event('status.field.bv'), {
  772. field: field,
  773. element: $field,
  774. status: status
  775. });
  776. this._onValidateFieldCompleted($field);
  777. return this;
  778. },
  779. /**
  780. * Check the form validity
  781. *
  782. * @returns {Boolean}
  783. */
  784. isValid: function() {
  785. var fields, field, $field,
  786. type, status, validatorName,
  787. n, i;
  788. for (field in this.options.fields) {
  789. if (this.options.fields[field] == null || this.options.fields[field]['enabled'] == false) {
  790. continue;
  791. }
  792. fields = this.getFieldElements(field);
  793. type = fields.attr('type');
  794. n = (('radio' == type) || ('checkbox' == type)) ? 1 : fields.length;
  795. for (i = 0; i < n; i++) {
  796. $field = $(fields[i]);
  797. if (this._isExcluded($field)) {
  798. continue;
  799. }
  800. for (validatorName in this.options.fields[field].validators) {
  801. status = $field.data('bv.result.' + validatorName);
  802. if (status != this.STATUS_VALID) {
  803. return false;
  804. }
  805. }
  806. }
  807. }
  808. return true;
  809. },
  810. /**
  811. * Check if all fields inside a given container are valid.
  812. * It's useful when working with a wizard-like such as tab, collapse
  813. *
  814. * @param {jQuery} $container The container element
  815. * @returns {Boolean}
  816. */
  817. isValidContainer: function($container) {
  818. var that = this, map = {};
  819. $container.find('[data-bv-field]').each(function() {
  820. var field = $(this).attr('data-bv-field');
  821. if (!map[field]) {
  822. map[field] = $(this);
  823. }
  824. });
  825. for (var field in map) {
  826. var $f = map[field];
  827. if ($f.data('bv.messages')
  828. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
  829. .filter(function() {
  830. var v = $(this).attr('data-bv-validator');
  831. return ($f.data('bv.result.' + v) && $f.data('bv.result.' + v) != that.STATUS_VALID);
  832. })
  833. .length != 0)
  834. {
  835. // The field is not valid
  836. return false;
  837. }
  838. }
  839. return true;
  840. },
  841. /**
  842. * Submit the form using default submission.
  843. * It also does not perform any validations when submitting the form
  844. *
  845. * It might be used when you want to submit the form right inside the submitHandler()
  846. */
  847. defaultSubmit: function() {
  848. if (this.$submitButton) {
  849. // Create hidden input to send the submit buttons
  850. $('<input/>')
  851. .attr('type', 'hidden')
  852. .attr('data-bv-submit-hidden', '')
  853. .attr('name', this.$submitButton.attr('name'))
  854. .val(this.$submitButton.val())
  855. .appendTo(this.$form);
  856. }
  857. // Submit form
  858. this.$form.off('submit.bv').submit();
  859. },
  860. // Useful APIs which aren't used internally
  861. /**
  862. * Get the list of invalid fields
  863. *
  864. * @returns {jQuery[]}
  865. */
  866. getInvalidFields: function() {
  867. return this.$invalidFields;
  868. },
  869. /**
  870. * Get the error messages
  871. *
  872. * @param {jQuery|String} [field] The field, which can be
  873. * - a string: The field name
  874. * - a jQuery object representing the field element
  875. * If the field is not defined, the method returns all error messages of all fields
  876. * @returns {String[]}
  877. */
  878. getErrors: function(field) {
  879. var that = this,
  880. messages = [],
  881. $fields = $([]);
  882. switch (true) {
  883. case (field && 'object' == typeof field):
  884. $fields = field;
  885. break;
  886. case (field && 'string' == typeof field):
  887. var f = this.getFieldElements(field);
  888. if (f.length > 0) {
  889. var type = f.attr('type');
  890. $fields = ('radio' == type || 'checkbox' == type) ? $(f[0]) : f;
  891. }
  892. break;
  893. default:
  894. $fields = this.$invalidFields;
  895. break;
  896. }
  897. $fields.each(function() {
  898. messages = messages.concat(
  899. $(this)
  900. .data('bv.messages')
  901. .find('.help-block[data-bv-for="' + $(this).attr('data-bv-field') + '"][data-bv-result="' + that.STATUS_INVALID + '"]')
  902. .map(function() {
  903. return $(this).html()
  904. })
  905. .get()
  906. );
  907. });
  908. return messages;
  909. },
  910. /**
  911. * Add a new field
  912. *
  913. * @param {String} field The field name
  914. * @param {Object} [options] The validator rules
  915. * @returns {BootstrapValidator}
  916. */
  917. addField: function(field, options) {
  918. this.options.fields[field] = options;
  919. var fields = this.getFieldElements(field),
  920. type = fields.attr('type'),
  921. n = (('radio' == type) || ('checkbox' == type)) ? 1 : fields.length;
  922. fields.attr('data-bv-field', field);
  923. for (var i = 0; i < n; i++) {
  924. this.addFieldElement($(fields[i]), options);
  925. }
  926. this.disableSubmitButtons(false);
  927. return this;
  928. },
  929. /**
  930. * Remove a given field
  931. *
  932. * @param {String} field The field name
  933. * @returns {BootstrapValidator}
  934. */
  935. removeField: function(field) {
  936. var fields = this.getFieldElements(field),
  937. type = fields.attr('type'),
  938. n = (('radio' == type) || ('checkbox' == type)) ? 1 : fields.length;
  939. for (var i = 0; i < n; i++) {
  940. this.removeFieldElement($(fields[i]));
  941. }
  942. this.disableSubmitButtons(false);
  943. return this;
  944. },
  945. /**
  946. * Add new field element
  947. *
  948. * @param {jQuery} $field The field element
  949. * @param {Object} [options] The field options
  950. * @returns {BootstrapValidator}
  951. */
  952. addFieldElement: function($field, options) {
  953. var field = $field.attr('data-bv-field') || $field.attr('name'),
  954. type = $field.attr('type');
  955. $field.attr('data-bv-field', field);
  956. // Try to parse the options from HTML attributes
  957. var opts = this._parseOptions($field);
  958. opts = (opts == null) ? options : $.extend(true, options, opts);
  959. this.options.fields[field] = $.extend(true, this.options.fields[field], opts);
  960. // Init the element
  961. delete this._cacheFields[field];
  962. ('checkbox' == type || 'radio' == type) ? this._initField(field) : this._initFieldElement($field);
  963. this.disableSubmitButtons(false);
  964. // Trigger an event
  965. this.$form.trigger($.Event('added.field.bv'), {
  966. field: field,
  967. element: $field,
  968. options: this.options.fields[field]
  969. });
  970. return this;
  971. },
  972. /**
  973. * Remove given field element
  974. *
  975. * @param {jQuery} $field The field element
  976. * @returns {BootstrapValidator}
  977. */
  978. removeFieldElement: function($field) {
  979. var field = $field.attr('data-bv-field') || $field.attr('name'),
  980. type = $field.attr('type');
  981. $field.attr('data-bv-field', field);
  982. // Remove from the list of invalid fields
  983. var index = this.$invalidFields.index($field);
  984. if (index != -1) {
  985. this.$invalidFields.splice(index, 1);
  986. }
  987. // Update the cache
  988. delete this._cacheFields[field];
  989. if ('checkbox' == type || 'radio' == type) {
  990. this._initField(field);
  991. }
  992. this.disableSubmitButtons(false);
  993. // Trigger an event
  994. this.$form.trigger($.Event('removed.field.bv'), {
  995. field: field,
  996. element: $field
  997. });
  998. return this;
  999. },
  1000. /**
  1001. * Reset the form
  1002. *
  1003. * @param {Boolean} [resetFormData] Reset current form data
  1004. * @returns {BootstrapValidator}
  1005. */
  1006. resetForm: function(resetFormData) {
  1007. var field, fields, total, type, validator;
  1008. for (field in this.options.fields) {
  1009. fields = this.getFieldElements(field);
  1010. total = fields.length;
  1011. for (var i = 0; i < total; i++) {
  1012. for (validator in this.options.fields[field].validators) {
  1013. $(fields[i]).removeData('bv.dfs.' + validator);
  1014. }
  1015. }
  1016. // Mark field as not validated yet
  1017. this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  1018. if (resetFormData) {
  1019. type = fields.attr('type');
  1020. ('radio' == type || 'checkbox' == type) ? fields.removeAttr('checked').removeAttr('selected') : fields.val('');
  1021. }
  1022. }
  1023. this.$invalidFields = $([]);
  1024. this.$submitButton = null;
  1025. // Enable submit buttons
  1026. this.disableSubmitButtons(false);
  1027. return this;
  1028. },
  1029. /**
  1030. * Enable/Disable all validators to given field
  1031. *
  1032. * @param {String} field The field name
  1033. * @param {Boolean} enabled Enable/Disable field validators
  1034. * @returns {BootstrapValidator}
  1035. */
  1036. enableFieldValidators: function(field, enabled) {
  1037. this.options.fields[field]['enabled'] = enabled;
  1038. this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  1039. return this;
  1040. },
  1041. /**
  1042. * Destroy the plugin
  1043. * It will remove all error messages, feedback icons and turn off the events
  1044. */
  1045. destroy: function() {
  1046. var field, fields, $field, validator, $icon, container;
  1047. for (field in this.options.fields) {
  1048. fields = this.getFieldElements(field);
  1049. container = this.options.fields[field].container || this.options.container;
  1050. for (var i = 0; i < fields.length; i++) {
  1051. $field = $(fields[i]);
  1052. $field
  1053. // Remove all error messages
  1054. .data('bv.messages')
  1055. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove().end()
  1056. .end()
  1057. .removeData('bv.messages')
  1058. // Remove feedback classes
  1059. .parents('.form-group')
  1060. .removeClass('has-feedback has-error has-success')
  1061. .end()
  1062. // Turn off events
  1063. .off('.bv')
  1064. .removeAttr('data-bv-field');
  1065. // Remove feedback icons, tooltip/popover container
  1066. $icon = $field.parents('.form-group').find('i[data-bv-icon-for="' + field + '"]');
  1067. if ($icon) {
  1068. switch (container) {
  1069. case 'tooltip':
  1070. $icon.tooltip('destroy').remove();
  1071. break;
  1072. case 'popover':
  1073. $icon.popover('destroy').remove();
  1074. break;
  1075. default:
  1076. $icon.remove();
  1077. break;
  1078. }
  1079. }
  1080. for (validator in this.options.fields[field].validators) {
  1081. $field.removeData('bv.result.' + validator).removeData('bv.dfs.' + validator);
  1082. }
  1083. }
  1084. }
  1085. // Enable submit buttons
  1086. this.disableSubmitButtons(false);
  1087. this.$form
  1088. .removeClass(this.options.elementClass)
  1089. .off('.bv')
  1090. .removeData('bootstrapValidator')
  1091. // Remove generated hidden elements
  1092. .find('[data-bv-submit-hidden]').remove();
  1093. }
  1094. };
  1095. // Plugin definition
  1096. $.fn.bootstrapValidator = function(option) {
  1097. var params = arguments;
  1098. return this.each(function() {
  1099. var $this = $(this),
  1100. data = $this.data('bootstrapValidator'),
  1101. options = 'object' == typeof option && option;
  1102. if (!data) {
  1103. data = new BootstrapValidator(this, options);
  1104. $this.data('bootstrapValidator', data);
  1105. }
  1106. // Allow to call plugin method
  1107. if ('string' == typeof option) {
  1108. data[option].apply(data, Array.prototype.slice.call(params, 1));
  1109. }
  1110. });
  1111. };
  1112. // Available validators
  1113. $.fn.bootstrapValidator.validators = {};
  1114. $.fn.bootstrapValidator.Constructor = BootstrapValidator;
  1115. // Helper methods, which can be used in validator class
  1116. $.fn.bootstrapValidator.helpers = {
  1117. /**
  1118. * Validate a date
  1119. *
  1120. * @param {Number} year The full year in 4 digits
  1121. * @param {Number} month The month number
  1122. * @param {Number} day The day number
  1123. * @param {Boolean} [notInFuture] If true, the date must not be in the future
  1124. * @returns {Boolean}
  1125. */
  1126. date: function(year, month, day, notInFuture) {
  1127. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  1128. return false;
  1129. }
  1130. if (year < 1000 || year > 9999 || month == 0 || month > 12) {
  1131. return false;
  1132. }
  1133. var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1134. // Update the number of days in Feb of leap year
  1135. if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
  1136. numDays[1] = 29;
  1137. }
  1138. // Check the day
  1139. if (day < 0 || day > numDays[month - 1]) {
  1140. return false;
  1141. }
  1142. if (notInFuture === true) {
  1143. var currentDate = new Date(),
  1144. currentYear = currentDate.getFullYear(),
  1145. currentMonth = currentDate.getMonth(),
  1146. currentDay = currentDate.getDate();
  1147. return (year < currentYear
  1148. || (year == currentYear && month - 1 < currentMonth)
  1149. || (year == currentYear && month - 1 == currentMonth && day < currentDay));
  1150. }
  1151. return true;
  1152. },
  1153. /**
  1154. * Implement Luhn validation algorithm
  1155. * Credit to https://gist.github.com/ShirtlessKirk/2134376
  1156. *
  1157. * @see http://en.wikipedia.org/wiki/Luhn
  1158. * @param {String} value
  1159. * @returns {Boolean}
  1160. */
  1161. luhn: function(value) {
  1162. var length = value.length,
  1163. mul = 0,
  1164. prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
  1165. sum = 0;
  1166. while (length--) {
  1167. sum += prodArr[mul][parseInt(value.charAt(length), 10)];
  1168. mul ^= 1;
  1169. }
  1170. return (sum % 10 === 0 && sum > 0);
  1171. },
  1172. /**
  1173. * Implement modulus 11, 10 (ISO 7064) algorithm
  1174. *
  1175. * @param {String} value
  1176. * @returns {Boolean}
  1177. */
  1178. mod_11_10: function(value) {
  1179. var check = 5,
  1180. length = value.length;
  1181. for (var i = 0; i < length; i++) {
  1182. check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
  1183. }
  1184. return (check == 1);
  1185. },
  1186. /**
  1187. * Implements Mod 37, 36 (ISO 7064) algorithm
  1188. * Usages:
  1189. * mod_37_36('A12425GABC1234002M')
  1190. * mod_37_36('002006673085', '0123456789')
  1191. *
  1192. * @param {String} value
  1193. * @param {String} alphabet
  1194. * @returns {Boolean}
  1195. */
  1196. mod_37_36: function(value, alphabet) {
  1197. alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1198. var modulus = alphabet.length,
  1199. length = value.length,
  1200. check = Math.floor(modulus / 2);
  1201. for (var i = 0; i < length; i++) {
  1202. check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
  1203. }
  1204. return (check == 1);
  1205. }
  1206. };
  1207. }(window.jQuery));
  1208. ;(function($) {
  1209. $.fn.bootstrapValidator.validators.base64 = {
  1210. /**
  1211. * Return true if the input value is a base 64 encoded string.
  1212. *
  1213. * @param {BootstrapValidator} validator The validator plugin instance
  1214. * @param {jQuery} $field Field element
  1215. * @param {Object} options Can consist of the following keys:
  1216. * - message: The invalid message
  1217. * @returns {Boolean}
  1218. */
  1219. validate: function(validator, $field, options) {
  1220. var value = $field.val();
  1221. if (value == '') {
  1222. return true;
  1223. }
  1224. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
  1225. }
  1226. };
  1227. }(window.jQuery));
  1228. ;(function($) {
  1229. $.fn.bootstrapValidator.validators.between = {
  1230. html5Attributes: {
  1231. message: 'message',
  1232. min: 'min',
  1233. max: 'max',
  1234. inclusive: 'inclusive'
  1235. },
  1236. enableByHtml5: function($field) {
  1237. if ('range' == $field.attr('type')) {
  1238. return {
  1239. min: $field.attr('min'),
  1240. max: $field.attr('max')
  1241. };
  1242. }
  1243. return false;
  1244. },
  1245. /**
  1246. * Return true if the input value is between (strictly or not) two given numbers
  1247. *
  1248. * @param {BootstrapValidator} validator The validator plugin instance
  1249. * @param {jQuery} $field Field element
  1250. * @param {Object} options Can consist of the following keys:
  1251. * - min
  1252. * - max
  1253. * - inclusive [optional]: Can be true or false. Default is true
  1254. * - message: The invalid message
  1255. * @returns {Boolean}
  1256. */
  1257. validate: function(validator, $field, options) {
  1258. var value = $field.val();
  1259. if (value == '') {
  1260. return true;
  1261. }
  1262. value = parseFloat(value);
  1263. return (options.inclusive === true || options.inclusive == undefined)
  1264. ? (value >= options.min && value <= options.max)
  1265. : (value > options.min && value < options.max);
  1266. }
  1267. };
  1268. }(window.jQuery));
  1269. ;(function($) {
  1270. $.fn.bootstrapValidator.validators.callback = {
  1271. /**
  1272. * Return result from the callback method
  1273. *
  1274. * @param {BootstrapValidator} validator The validator plugin instance
  1275. * @param {jQuery} $field Field element
  1276. * @param {Object} options Can consist of the following keys:
  1277. * - callback: The callback method that passes 2 parameters:
  1278. * callback: function(fieldValue, validator) {
  1279. * // fieldValue is the value of field
  1280. * // validator is instance of BootstrapValidator
  1281. * }
  1282. * - message: The invalid message
  1283. * @returns {Boolean|Deferred}
  1284. */
  1285. validate: function(validator, $field, options) {
  1286. var value = $field.val();
  1287. if (options.callback && 'function' == typeof options.callback) {
  1288. var dfd = new $.Deferred(),
  1289. response = options.callback.call(this, value, validator);
  1290. dfd.resolve($field, 'callback', 'boolean' == typeof response ? response : response.valid, 'object' == typeof response && response.message ? response.message : null);
  1291. return dfd;
  1292. }
  1293. return true;
  1294. }
  1295. };
  1296. }(window.jQuery));
  1297. ;(function($) {
  1298. $.fn.bootstrapValidator.validators.choice = {
  1299. html5Attributes: {
  1300. message: 'message',
  1301. min: 'min',
  1302. max: 'max'
  1303. },
  1304. /**
  1305. * Check if the number of checked boxes are less or more than a given number
  1306. *
  1307. * @param {BootstrapValidator} validator The validator plugin instance
  1308. * @param {jQuery} $field Field element
  1309. * @param {Object} options Consists of following keys:
  1310. * - min
  1311. * - max
  1312. * At least one of two keys is required
  1313. * - message: The invalid message
  1314. * @returns {Boolean}
  1315. */
  1316. validate: function(validator, $field, options) {
  1317. var numChoices = $field.is('select')
  1318. ? validator.getFieldElements($field.attr('data-bv-field')).find('option').filter(':selected').length
  1319. : validator.getFieldElements($field.attr('data-bv-field')).filter(':checked').length;
  1320. if ((options.min && numChoices < options.min) || (options.max && numChoices > options.max)) {
  1321. return false;
  1322. }
  1323. return true;
  1324. }
  1325. };
  1326. }(window.jQuery));
  1327. ;(function($) {
  1328. $.fn.bootstrapValidator.validators.creditCard = {
  1329. /**
  1330. * Return true if the input value is valid credit card number
  1331. * Based on https://gist.github.com/DiegoSalazar/4075533
  1332. *
  1333. * @param {BootstrapValidator} validator The validator plugin instance
  1334. * @param {jQuery} $field Field element
  1335. * @param {Object} options Can consist of the following key:
  1336. * - message: The invalid message
  1337. * @returns {Boolean}
  1338. */
  1339. validate: function(validator, $field, options) {
  1340. var value = $field.val();
  1341. if (value == '') {
  1342. return true;
  1343. }
  1344. // Accept only digits, dashes or spaces
  1345. if (/[^0-9-\s]+/.test(value)) {
  1346. return false;
  1347. }
  1348. value = value.replace(/\D/g, '');
  1349. if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
  1350. return false;
  1351. }
  1352. // Validate the card number based on prefix (IIN ranges) and length
  1353. var cards = {
  1354. AMERICAN_EXPRESS: {
  1355. length: [15],
  1356. prefix: ['34', '37']
  1357. },
  1358. DINERS_CLUB: {
  1359. length: [14],
  1360. prefix: ['300', '301', '302', '303', '304', '305', '36']
  1361. },
  1362. DINERS_CLUB_US: {
  1363. length: [16],
  1364. prefix: ['54', '55']
  1365. },
  1366. DISCOVER: {
  1367. length: [16],
  1368. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  1369. '62214', '62215', '62216', '62217', '62218', '62219',
  1370. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  1371. '62290', '62291', '622920', '622921', '622922', '622923',
  1372. '622924', '622925', '644', '645', '646', '647', '648',
  1373. '649', '65']
  1374. },
  1375. JCB: {
  1376. length: [16],
  1377. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  1378. },
  1379. LASER: {
  1380. length: [16, 17, 18, 19],
  1381. prefix: ['6304', '6706', '6771', '6709']
  1382. },
  1383. MAESTRO: {
  1384. length: [12, 13, 14, 15, 16, 17, 18, 19],
  1385. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  1386. },
  1387. MASTERCARD: {
  1388. length: [16],
  1389. prefix: ['51', '52', '53', '54', '55']
  1390. },
  1391. SOLO: {
  1392. length: [16, 18, 19],
  1393. prefix: ['6334', '6767']
  1394. },
  1395. UNIONPAY: {
  1396. length: [16, 17, 18, 19],
  1397. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  1398. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  1399. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  1400. '622920', '622921', '622922', '622923', '622924', '622925']
  1401. },
  1402. VISA: {
  1403. length: [16],
  1404. prefix: ['4']
  1405. }
  1406. };
  1407. var type, i;
  1408. for (type in cards) {
  1409. for (i in cards[type]['prefix']) {
  1410. if (value.substr(0, cards[type]['prefix'][i].length) == cards[type]['prefix'][i] // Check the prefix
  1411. && $.inArray(value.length, cards[type]['length']) != -1) // and length
  1412. {
  1413. return true;
  1414. }
  1415. }
  1416. }
  1417. return false;
  1418. }
  1419. };
  1420. }(window.jQuery));
  1421. ;(function($) {
  1422. $.fn.bootstrapValidator.validators.cusip = {
  1423. /**
  1424. * Validate a CUSIP
  1425. * Examples:
  1426. * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  1427. * - Invalid: 31430F200, 022615AC2
  1428. *
  1429. * @see http://en.wikipedia.org/wiki/CUSIP
  1430. * @param {BootstrapValidator} validator The validator plugin instance
  1431. * @param {jQuery} $field Field element
  1432. * @param {Object} options Can consist of the following keys:
  1433. * - message: The invalid message
  1434. * @returns {Boolean}
  1435. */
  1436. validate: function(validator, $field, options) {
  1437. var value = $field.val();
  1438. if (value == '') {
  1439. return true;
  1440. }
  1441. value = value.toUpperCase();
  1442. if (!/^[0-9A-Z]{9}$/.test(value)) {
  1443. return false;
  1444. }
  1445. var converted = $.map(value.split(''), function(item) {
  1446. var code = item.charCodeAt(0);
  1447. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  1448. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  1449. ? (code - 'A'.charCodeAt(0) + 10)
  1450. : item;
  1451. }),
  1452. length = converted.length,
  1453. sum = 0;
  1454. for (var i = 0; i < length - 1; i++) {
  1455. var num = parseInt(converted[i]);
  1456. if (i % 2 != 0) {
  1457. num *= 2;
  1458. }
  1459. if (num > 9) {
  1460. num -= 9;
  1461. }
  1462. sum += num;
  1463. }
  1464. sum = (10 - (sum % 10)) % 10;
  1465. return sum == converted[length - 1];
  1466. }
  1467. };
  1468. }(window.jQuery));
  1469. ;(function($) {
  1470. $.fn.bootstrapValidator.validators.cvv = {
  1471. html5Attributes: {
  1472. message: 'message',
  1473. ccfield: 'creditCardField'
  1474. },
  1475. /**
  1476. * Return true if the input value is a valid CVV number.
  1477. *
  1478. * @param {BootstrapValidator} validator The validator plugin instance
  1479. * @param {jQuery} $field Field element
  1480. * @param {Object} options Can consist of the following keys:
  1481. * - creditCardField: The credit card number field. It can be null
  1482. * - message: The invalid message
  1483. * @returns {Boolean}
  1484. */
  1485. validate: function(validator, $field, options) {
  1486. var value = $field.val();
  1487. if (value == '') {
  1488. return true;
  1489. }
  1490. if (!/^[0-9]{3,4}$/.test(value)) {
  1491. return false;
  1492. }
  1493. if (!options.creditCardField) {
  1494. return true;
  1495. }
  1496. // Get the credit card number
  1497. var creditCard = validator.getFieldElements(options.creditCardField).val();
  1498. if (creditCard == '') {
  1499. return true;
  1500. }
  1501. creditCard = creditCard.replace(/\D/g, '');
  1502. // Supported credit card types
  1503. var cards = {
  1504. AMERICAN_EXPRESS: {
  1505. length: [15],
  1506. prefix: ['34', '37']
  1507. },
  1508. DINERS_CLUB: {
  1509. length: [14],
  1510. prefix: ['300', '301', '302', '303', '304', '305', '36']
  1511. },
  1512. DINERS_CLUB_US: {
  1513. length: [16],
  1514. prefix: ['54', '55']
  1515. },
  1516. DISCOVER: {
  1517. length: [16],
  1518. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  1519. '62214', '62215', '62216', '62217', '62218', '62219',
  1520. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  1521. '62290', '62291', '622920', '622921', '622922', '622923',
  1522. '622924', '622925', '644', '645', '646', '647', '648',
  1523. '649', '65']
  1524. },
  1525. JCB: {
  1526. length: [16],
  1527. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  1528. },
  1529. LASER: {
  1530. length: [16, 17, 18, 19],
  1531. prefix: ['6304', '6706', '6771', '6709']
  1532. },
  1533. MAESTRO: {
  1534. length: [12, 13, 14, 15, 16, 17, 18, 19],
  1535. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  1536. },
  1537. MASTERCARD: {
  1538. length: [16],
  1539. prefix: ['51', '52', '53', '54', '55']
  1540. },
  1541. SOLO: {
  1542. length: [16, 18, 19],
  1543. prefix: ['6334', '6767']
  1544. },
  1545. UNIONPAY: {
  1546. length: [16, 17, 18, 19],
  1547. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  1548. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  1549. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  1550. '622920', '622921', '622922', '622923', '622924', '622925']
  1551. },
  1552. VISA: {
  1553. length: [16],
  1554. prefix: ['4']
  1555. }
  1556. };
  1557. var type, i, creditCardType = null;
  1558. for (type in cards) {
  1559. for (i in cards[type]['prefix']) {
  1560. if (creditCard.substr(0, cards[type]['prefix'][i].length) == cards[type]['prefix'][i] // Check the prefix
  1561. && $.inArray(creditCard.length, cards[type]['length']) != -1) // and length
  1562. {
  1563. creditCardType = type;
  1564. break;
  1565. }
  1566. }
  1567. }
  1568. return (creditCardType == null)
  1569. ? false
  1570. : (('AMERICAN_EXPRESS' == creditCardType) ? (value.length == 4) : (value.length == 3));
  1571. }
  1572. };
  1573. }(window.jQuery));
  1574. ;(function($) {
  1575. $.fn.bootstrapValidator.validators.date = {
  1576. html5Attributes: {
  1577. message: 'message',
  1578. format: 'format',
  1579. separator: 'separator'
  1580. },
  1581. /**
  1582. * Return true if the input value is valid date
  1583. *
  1584. * @param {BootstrapValidator} validator The validator plugin instance
  1585. * @param {jQuery} $field Field element
  1586. * @param {Object} options Can consist of the following keys:
  1587. * - message: The invalid message
  1588. * - separator: Use to separate the date, month, and year.
  1589. * By default, it is /
  1590. * - format: The date format. Default is MM/DD/YYYY
  1591. * The format can be:
  1592. *
  1593. * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  1594. * ii) date and time:
  1595. * The time can consist of h, m, s parts which are separated by :
  1596. * ii) date, time and A (indicating AM or PM)
  1597. * @returns {Boolean}
  1598. */
  1599. validate: function(validator, $field, options) {
  1600. var value = $field.val();
  1601. if (value == '') {
  1602. return true;
  1603. }
  1604. options.format = options.format || 'MM/DD/YYYY';
  1605. var formats = options.format.split(' '),
  1606. dateFormat = formats[0],
  1607. timeFormat = (formats.length > 1) ? formats[1] : null,
  1608. amOrPm = (formats.length > 2) ? formats[2] : null,
  1609. sections = value.split(' '),
  1610. date = sections[0],
  1611. time = (sections.length > 1) ? sections[1] : null;
  1612. if (formats.length != sections.length) {
  1613. return false;
  1614. }
  1615. // Determine the separator
  1616. var separator = options.separator;
  1617. if (!separator) {
  1618. separator = (date.indexOf('/') != -1) ? '/' : ((date.indexOf('-') != -1) ? '-' : null);
  1619. }
  1620. if (separator == null || date.indexOf(separator) == -1) {
  1621. return false;
  1622. }
  1623. // Determine the date
  1624. date = date.split(separator);
  1625. dateFormat = dateFormat.split(separator);
  1626. var year = date[$.inArray('YYYY', dateFormat)],
  1627. month = date[$.inArray('MM', dateFormat)],
  1628. day = date[$.inArray('DD', dateFormat)];
  1629. // Determine the time
  1630. var minutes = null, hours = null, seconds = null;
  1631. if (timeFormat) {
  1632. timeFormat = timeFormat.split(':'),
  1633. time = time.split(':');
  1634. if (timeFormat.length != time.length) {
  1635. return false;
  1636. }
  1637. hours = time.length > 0 ? time[0] : null;
  1638. minutes = time.length > 1 ? time[1] : null;
  1639. seconds = time.length > 2 ? time[2] : null;
  1640. // Validate seconds
  1641. if (seconds) {
  1642. seconds = parseInt(seconds, 10);
  1643. if (isNaN(seconds) || seconds < 0 || seconds > 60) {
  1644. return false;
  1645. }
  1646. }
  1647. // Validate hours
  1648. if (hours) {
  1649. hours = parseInt(hours, 10);
  1650. if (isNaN(hours) || hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  1651. return false;
  1652. }
  1653. }
  1654. // Validate minutes
  1655. if (minutes) {
  1656. minutes = parseInt(minutes, 10);
  1657. if (isNaN(minutes) || minutes < 0 || minutes > 59) {
  1658. return false;
  1659. }
  1660. }
  1661. }
  1662. // Validate day, month, and year
  1663. day = parseInt(day, 10);
  1664. month = parseInt(month, 10);
  1665. year = parseInt(year, 10);
  1666. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  1667. }
  1668. };
  1669. }(window.jQuery));
  1670. ;(function($) {
  1671. $.fn.bootstrapValidator.validators.different = {
  1672. html5Attributes: {
  1673. message: 'message',
  1674. field: 'field'
  1675. },
  1676. /**
  1677. * Return true if the input value is different with given field's value
  1678. *
  1679. * @param {BootstrapValidator} validator The validator plugin instance
  1680. * @param {jQuery} $field Field element
  1681. * @param {Object} options Consists of the following key:
  1682. * - field: The name of field that will be used to compare with current one
  1683. * - message: The invalid message
  1684. * @returns {Boolean}
  1685. */
  1686. validate: function(validator, $field, options) {
  1687. var value = $field.val();
  1688. if (value == '') {
  1689. return true;
  1690. }
  1691. var compareWith = validator.getFieldElements(options.field);
  1692. if (compareWith == null) {
  1693. return true;
  1694. }
  1695. if (value != compareWith.val()) {
  1696. validator.updateStatus(options.field, validator.STATUS_VALID, 'different');
  1697. return true;
  1698. } else {
  1699. return false;
  1700. }
  1701. }
  1702. };
  1703. }(window.jQuery));
  1704. ;(function($) {
  1705. $.fn.bootstrapValidator.validators.digits = {
  1706. /**
  1707. * Return true if the input value contains digits only
  1708. *
  1709. * @param {BootstrapValidator} validator Validate plugin instance
  1710. * @param {jQuery} $field Field element
  1711. * @param {Object} options
  1712. * @returns {Boolean}
  1713. */
  1714. validate: function(validator, $field, options) {
  1715. var value = $field.val();
  1716. if (value == '') {
  1717. return true;
  1718. }
  1719. return /^\d+$/.test(value);
  1720. }
  1721. }
  1722. }(window.jQuery));
  1723. ;(function($) {
  1724. $.fn.bootstrapValidator.validators.ean = {
  1725. /**
  1726. * Validate EAN (International Article Number)
  1727. * Examples:
  1728. * - Valid: 73513537, 9780471117094, 4006381333931
  1729. * - Invalid: 73513536
  1730. *
  1731. * @see http://en.wikipedia.org/wiki/European_Article_Number
  1732. * @param {BootstrapValidator} validator The validator plugin instance
  1733. * @param {jQuery} $field Field element
  1734. * @param {Object} options Can consist of the following keys:
  1735. * - message: The invalid message
  1736. * @returns {Boolean}
  1737. */
  1738. validate: function(validator, $field, options) {
  1739. var value = $field.val();
  1740. if (value == '') {
  1741. return true;
  1742. }
  1743. if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  1744. return false;
  1745. }
  1746. var length = value.length,
  1747. sum = 0,
  1748. weight = (length == 8) ? [3, 1] : [1, 3];
  1749. for (var i = 0; i < length - 1; i++) {
  1750. sum += parseInt(value.charAt(i)) * weight[i % 2];
  1751. }
  1752. sum = 10 - sum % 10;
  1753. return (sum == value.charAt(length - 1));
  1754. }
  1755. };
  1756. }(window.jQuery));
  1757. ;(function($) {
  1758. $.fn.bootstrapValidator.validators.emailAddress = {
  1759. enableByHtml5: function($field) {
  1760. return ('email' == $field.attr('type'));
  1761. },
  1762. /**
  1763. * Return true if and only if the input value is a valid email address
  1764. *
  1765. * @param {BootstrapValidator} validator Validate plugin instance
  1766. * @param {jQuery} $field Field element
  1767. * @param {Object} options
  1768. * @returns {Boolean}
  1769. */
  1770. validate: function(validator, $field, options) {
  1771. var value = $field.val();
  1772. if (value == '') {
  1773. return true;
  1774. }
  1775. // Email address regular expression
  1776. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  1777. var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  1778. return emailRegExp.test(value);
  1779. }
  1780. }
  1781. }(window.jQuery));
  1782. ;(function($) {
  1783. $.fn.bootstrapValidator.validators.file = {
  1784. html5Attributes: {
  1785. extension: 'extension',
  1786. maxsize: 'maxSize',
  1787. message: 'message',
  1788. type: 'type'
  1789. },
  1790. /**
  1791. * Validate upload file. Use HTML 5 API if the browser supports
  1792. *
  1793. * @param {BootstrapValidator} validator The validator plugin instance
  1794. * @param {jQuery} $field Field element
  1795. * @param {Object} options Can consist of the following keys:
  1796. * - extension: The allowed extensions, separated by a comma
  1797. * - maxSize: The maximum size in bytes
  1798. * - message: The invalid message
  1799. * - type: The allowed MIME type, separated by a comma
  1800. * @returns {Boolean}
  1801. */
  1802. validate: function(validator, $field, options) {
  1803. var value = $field.val();
  1804. if (value == '') {
  1805. return true;
  1806. }
  1807. var ext,
  1808. extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  1809. types = options.type ? options.type.toLowerCase().split(',') : null,
  1810. html5 = (window.File && window.FileList && window.FileReader);
  1811. if (html5) {
  1812. // Get FileList instance
  1813. var files = $field.get(0).files,
  1814. total = files.length;
  1815. for (var i = 0; i < total; i++) {
  1816. // Check file size
  1817. if (options.maxSize && files[i].size > parseInt(options.maxSize)) {
  1818. return false;
  1819. }
  1820. // Check file extension
  1821. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  1822. if (extensions && $.inArray(ext.toLowerCase(), extensions) == -1) {
  1823. return false;
  1824. }
  1825. // Check file type
  1826. if (types && $.inArray(files[i].type.toLowerCase(), types) == -1) {
  1827. return false;
  1828. }
  1829. }
  1830. } else {
  1831. // Check file extension
  1832. ext = value.substr(value.lastIndexOf('.') + 1);
  1833. if (extensions && $.inArray(ext.toLowerCase(), extensions) == -1) {
  1834. return false;
  1835. }
  1836. }
  1837. return true;
  1838. }
  1839. };
  1840. }(window.jQuery));
  1841. ;(function($) {
  1842. $.fn.bootstrapValidator.validators.greaterThan = {
  1843. html5Attributes: {
  1844. message: 'message',
  1845. value: 'value',
  1846. inclusive: 'inclusive'
  1847. },
  1848. enableByHtml5: function($field) {
  1849. var min = $field.attr('min');
  1850. if (min) {
  1851. return {
  1852. value: min
  1853. };
  1854. }
  1855. return false;
  1856. },
  1857. /**
  1858. * Return true if the input value is greater than or equals to given number
  1859. *
  1860. * @param {BootstrapValidator} validator Validate plugin instance
  1861. * @param {jQuery} $field Field element
  1862. * @param {Object} options Can consist of the following keys:
  1863. * - value: The number used to compare to
  1864. * - inclusive [optional]: Can be true or false. Default is true
  1865. * - message: The invalid message
  1866. * @returns {Boolean}
  1867. */
  1868. validate: function(validator, $field, options) {
  1869. var value = $field.val();
  1870. if (value == '') {
  1871. return true;
  1872. }
  1873. value = parseFloat(value);
  1874. return (options.inclusive === true || options.inclusive == undefined) ? (value >= options.value) : (value > options.value);
  1875. }
  1876. }
  1877. }(window.jQuery));
  1878. ;(function($) {
  1879. $.fn.bootstrapValidator.validators.grid = {
  1880. /**
  1881. * Validate GRId (Global Release Identifier)
  1882. * Examples:
  1883. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  1884. * - Invalid: A1-2425G-ABC1234002-Q
  1885. *
  1886. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  1887. * @param {BootstrapValidator} validator The validator plugin instance
  1888. * @param {jQuery} $field Field element
  1889. * @param {Object} options Can consist of the following keys:
  1890. * - message: The invalid message
  1891. * @returns {Boolean}
  1892. */
  1893. validate: function(validator, $field, options) {
  1894. var value = $field.val();
  1895. if (value == '') {
  1896. return true;
  1897. }
  1898. value = value.toUpperCase();
  1899. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  1900. return false;
  1901. }
  1902. value = value.replace(/\s/g, '').replace(/-/g, '');
  1903. if ('GRID:' == value.substr(0, 5)) {
  1904. value = value.substr(5);
  1905. }
  1906. return $.fn.bootstrapValidator.helpers.mod_37_36(value);
  1907. }
  1908. };
  1909. }(window.jQuery));
  1910. ;(function($) {
  1911. $.fn.bootstrapValidator.validators.hex = {
  1912. /**
  1913. * Return true if and only if the input value is a valid hexadecimal number
  1914. *
  1915. * @param {BootstrapValidator} validator The validator plugin instance
  1916. * @param {jQuery} $field Field element
  1917. * @param {Object} options Consist of key:
  1918. * - message: The invalid message
  1919. * @returns {Boolean}
  1920. */
  1921. validate: function(validator, $field, options) {
  1922. var value = $field.val();
  1923. if (value == '') {
  1924. return true;
  1925. }
  1926. return /^[0-9a-fA-F]+$/.test(value);
  1927. }
  1928. };
  1929. }(window.jQuery));
  1930. ;(function($) {
  1931. $.fn.bootstrapValidator.validators.hexColor = {
  1932. enableByHtml5: function($field) {
  1933. return ('color' == $field.attr('type'));
  1934. },
  1935. /**
  1936. * Return true if the input value is a valid hex color
  1937. *
  1938. * @param {BootstrapValidator} validator The validator plugin instance
  1939. * @param {jQuery} $field Field element
  1940. * @param {Object} options Can consist of the following keys:
  1941. * - message: The invalid message
  1942. * @returns {Boolean}
  1943. */
  1944. validate: function(validator, $field, options) {
  1945. var value = $field.val();
  1946. if (value == '') {
  1947. return true;
  1948. }
  1949. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  1950. }
  1951. };
  1952. }(window.jQuery));
  1953. ;(function($) {
  1954. $.fn.bootstrapValidator.validators.iban = {
  1955. html5Attributes: {
  1956. message: 'message',
  1957. country: 'country'
  1958. },
  1959. /**
  1960. * Validate an International Bank Account Number (IBAN)
  1961. * To test it, take the sample IBAN from
  1962. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  1963. *
  1964. * @param {BootstrapValidator} validator The validator plugin instance
  1965. * @param {jQuery} $field Field element
  1966. * @param {Object} options Can consist of the following keys:
  1967. * - message: The invalid message
  1968. * - country: The ISO 3166-1 country code
  1969. * @returns {Boolean}
  1970. */
  1971. validate: function(validator, $field, options) {
  1972. var value = $field.val();
  1973. if (value == '') {
  1974. return true;
  1975. }
  1976. // See
  1977. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  1978. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  1979. var ibanRegex = {
  1980. 'AD': 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  1981. 'AE': 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  1982. 'AL': 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  1983. 'AO': 'AO[0-9]{2}[0-9]{21}', // Angola
  1984. 'AT': 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  1985. 'AZ': 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  1986. 'BA': 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  1987. 'BE': 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  1988. 'BF': 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  1989. 'BG': 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  1990. 'BH': 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  1991. 'BI': 'BI[0-9]{2}[0-9]{12}', // Burundi
  1992. 'BJ': 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  1993. 'BR': 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  1994. 'CH': 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  1995. 'CI': 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  1996. 'CM': 'CM[0-9]{2}[0-9]{23}', // Cameroon
  1997. 'CR': 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  1998. 'CV': 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  1999. 'CY': 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  2000. 'CZ': 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  2001. 'DE': 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  2002. 'DK': 'DK[0-9]{2}[0-9]{14}', // Denmark
  2003. 'DO': 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  2004. 'DZ': 'DZ[0-9]{2}[0-9]{20}', // Algeria
  2005. 'EE': 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  2006. 'ES': 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  2007. 'FI': 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  2008. 'FO': 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  2009. 'FR': 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  2010. 'GB': 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  2011. 'GE': 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  2012. 'GI': 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  2013. 'GL': 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland[
  2014. 'GR': 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  2015. 'GT': 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  2016. 'HR': 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  2017. 'HU': 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  2018. 'IE': 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  2019. 'IL': 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  2020. 'IR': 'IR[0-9]{2}[0-9]{22}', // Iran
  2021. 'IS': 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  2022. 'IT': 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  2023. 'JO': 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  2024. 'KW': 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  2025. 'KZ': 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  2026. 'LB': 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  2027. 'LI': 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  2028. 'LT': 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  2029. 'LU': 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  2030. 'LV': 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  2031. 'MC': 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  2032. 'MD': 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  2033. 'ME': 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  2034. 'MG': 'MG[0-9]{2}[0-9]{23}', // Madagascar
  2035. 'MK': 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  2036. 'ML': 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  2037. 'MR': 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  2038. 'MT': 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  2039. 'MU': 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}',// Mauritius
  2040. 'MZ': 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  2041. 'NL': 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  2042. 'NO': 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  2043. 'PK': 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  2044. 'PL': 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  2045. 'PS': 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  2046. 'PT': 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  2047. 'QA': 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  2048. 'RO': 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  2049. 'RS': 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  2050. 'SA': 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  2051. 'SE': 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  2052. 'SI': 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  2053. 'SK': 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  2054. 'SM': 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  2055. 'SN': 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  2056. 'TN': 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  2057. 'TR': 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  2058. 'VG': 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  2059. };
  2060. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  2061. var country = options.country || value.substr(0, 2);
  2062. if (!ibanRegex[country]) {
  2063. return false;
  2064. }
  2065. if (!(new RegExp('^' + ibanRegex[country] + '$')).test(value)) {
  2066. return false;
  2067. }
  2068. value = value.substr(4) + value.substr(0, 4);
  2069. value = $.map(value.split(''), function(n) {
  2070. var code = n.charCodeAt(0);
  2071. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  2072. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  2073. ? (code - 'A'.charCodeAt(0) + 10)
  2074. : n;
  2075. });
  2076. value = value.join('');
  2077. var temp = parseInt(value.substr(0, 1), 10),
  2078. length = value.length;
  2079. for (var i = 1; i < length; ++i) {
  2080. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  2081. }
  2082. return (temp == 1);
  2083. }
  2084. };
  2085. }(window.jQuery));
  2086. ;(function($) {
  2087. $.fn.bootstrapValidator.validators.id = {
  2088. html5Attributes: {
  2089. message: 'message',
  2090. country: 'country'
  2091. },
  2092. /**
  2093. * Validate identification number in different countries
  2094. *
  2095. * @see http://en.wikipedia.org/wiki/National_identification_number
  2096. * @param {BootstrapValidator} validator The validator plugin instance
  2097. * @param {jQuery} $field Field element
  2098. * @param {Object} options Consist of key:
  2099. * - message: The invalid message
  2100. * - country: The ISO 3166-1 country code
  2101. * @returns {Boolean}
  2102. */
  2103. validate: function(validator, $field, options) {
  2104. var value = $field.val();
  2105. if (value == '') {
  2106. return true;
  2107. }
  2108. var country = options.country || value.substr(0, 2),
  2109. method = ['_', country.toLowerCase()].join('');
  2110. if (this[method] && 'function' == typeof this[method]) {
  2111. return this[method](value);
  2112. }
  2113. return true;
  2114. },
  2115. /**
  2116. * Validate Unique Master Citizen Number which uses in
  2117. * - Bosnia and Herzegovina (country code: BA)
  2118. * - Macedonia (MK)
  2119. * - Montenegro (ME)
  2120. * - Serbia (RS)
  2121. * - Slovenia (SI)
  2122. *
  2123. * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  2124. * @param {String} value The ID
  2125. * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  2126. * @returns {Boolean}
  2127. */
  2128. _validateJMBG: function(value, countryCode) {
  2129. if (!/^\d{13}$/.test(value)) {
  2130. return false;
  2131. }
  2132. var day = parseInt(value.substr(0, 2), 10),
  2133. month = parseInt(value.substr(2, 2), 10),
  2134. year = parseInt(value.substr(4, 3), 10),
  2135. rr = parseInt(value.substr(7, 2), 10),
  2136. k = parseInt(value.substr(12, 1), 10);
  2137. // Validate date of birth
  2138. // FIXME: Validate the year of birth
  2139. if (day > 31 || month > 12) {
  2140. return false;
  2141. }
  2142. // Validate checksum
  2143. var sum = 0;
  2144. for (var i = 0; i < 6; i++) {
  2145. sum += (7 - i) * (parseInt(value.charAt(i)) + parseInt(value.charAt(i + 6)));
  2146. }
  2147. sum = 11 - sum % 11;
  2148. if (sum == 10 || sum == 11) {
  2149. sum = 0;
  2150. }
  2151. if (sum != k) {
  2152. return false;
  2153. }
  2154. // Validate political region
  2155. // rr is the political region of birth, which can be in ranges:
  2156. // 10-19: Bosnia and Herzegovina
  2157. // 20-29: Montenegro
  2158. // 30-39: Croatia (not used anymore)
  2159. // 41-49: Macedonia
  2160. // 50-59: Slovenia (only 50 is used)
  2161. // 70-79: Central Serbia
  2162. // 80-89: Serbian province of Vojvodina
  2163. // 90-99: Kosovo
  2164. switch (countryCode.toUpperCase()) {
  2165. case 'BA':
  2166. return (10 <= rr && rr <= 19);
  2167. case 'MK':
  2168. return (41 <= rr && rr <= 49);
  2169. case 'ME':
  2170. return (20 <= rr && rr <= 29);
  2171. case 'RS':
  2172. return (70 <= rr && rr <= 99);
  2173. case 'SI':
  2174. return (50 <= rr && rr <= 59);
  2175. default:
  2176. return true;
  2177. }
  2178. },
  2179. _ba: function(value) {
  2180. return this._validateJMBG(value, 'BA');
  2181. },
  2182. _mk: function(value) {
  2183. return this._validateJMBG(value, 'MK');
  2184. },
  2185. _me: function(value) {
  2186. return this._validateJMBG(value, 'ME');
  2187. },
  2188. _rs: function(value) {
  2189. return this._validateJMBG(value, 'RS');
  2190. },
  2191. /**
  2192. * Examples: 0101006500006
  2193. */
  2194. _si: function(value) {
  2195. return this._validateJMBG(value, 'SI');
  2196. },
  2197. /**
  2198. * Validate Bulgarian national identification number (EGN)
  2199. * Examples:
  2200. * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  2201. * - Invalid: 8019010008
  2202. *
  2203. * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  2204. * @param {String} value The ID
  2205. * @returns {Boolean}
  2206. */
  2207. _bg: function(value) {
  2208. if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  2209. return false;
  2210. }
  2211. value = value.replace(/\s/g, '');
  2212. // Check the birth date
  2213. var year = parseInt(value.substr(0, 2), 10) + 1900,
  2214. month = parseInt(value.substr(2, 2), 10),
  2215. day = parseInt(value.substr(4, 2), 10);
  2216. if (month > 40) {
  2217. year += 100;
  2218. month -= 40;
  2219. } else if (month > 20) {
  2220. year -= 100;
  2221. month -= 20;
  2222. }
  2223. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2224. return false;
  2225. }
  2226. var sum = 0,
  2227. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2228. for (var i = 0; i < 9; i++) {
  2229. sum += parseInt(value.charAt(i)) * weight[i];
  2230. }
  2231. sum = (sum % 11) % 10;
  2232. return (sum == value.substr(9, 1));
  2233. },
  2234. /**
  2235. * Validate Brazilian national identification number (CPF)
  2236. * Examples:
  2237. * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  2238. * - Invalid: 231.002.999-00
  2239. *
  2240. * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  2241. * @param {String} value The ID
  2242. * @returns {Boolean}
  2243. */
  2244. _br: function(value) {
  2245. if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  2246. return false;
  2247. }
  2248. if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
  2249. return false;
  2250. }
  2251. value = value.replace(/\./g, '').replace(/-/g, '');
  2252. var d1 = 0;
  2253. for (var i = 0; i < 9; i++) {
  2254. d1 += (10 - i) * parseInt(value.charAt(i));
  2255. }
  2256. d1 = 11 - d1 % 11;
  2257. if (d1 == 10 || d1 == 11) {
  2258. d1 = 0;
  2259. }
  2260. if (d1 != value.charAt(9)) {
  2261. return false;
  2262. }
  2263. var d2 = 0;
  2264. for (i = 0; i < 10; i++) {
  2265. d2 += (11 - i) * parseInt(value.charAt(i));
  2266. }
  2267. d2 = 11 - d2 % 11;
  2268. if (d2 == 10 || d2 == 11) {
  2269. d2 = 0;
  2270. }
  2271. return (d2 == value.charAt(10));
  2272. },
  2273. /**
  2274. * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  2275. * Examples:
  2276. * - Valid: 756.1234.5678.95, 7561234567895
  2277. *
  2278. * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  2279. * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  2280. * @param {String} value The ID
  2281. * @returns {Boolean}
  2282. */
  2283. _ch: function(value) {
  2284. if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  2285. return false;
  2286. }
  2287. value = value.replace(/\D/g, '').substr(3);
  2288. var length = value.length,
  2289. sum = 0,
  2290. weight = (length == 8) ? [3, 1] : [1, 3];
  2291. for (var i = 0; i < length - 1; i++) {
  2292. sum += parseInt(value.charAt(i)) * weight[i % 2];
  2293. }
  2294. sum = 10 - sum % 10;
  2295. return (sum == value.charAt(length - 1));
  2296. },
  2297. /**
  2298. * Validate Chilean national identification number (RUN/RUT)
  2299. * Examples:
  2300. * - Valid: 76086428-5, 22060449-7, 12531909-2
  2301. *
  2302. * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  2303. * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  2304. * @param {String} value The ID
  2305. * @returns {Boolean}
  2306. */
  2307. _cl: function(value) {
  2308. if (!/^\d{7,8}[-]{0,1}[0-9K]$/.test(value)) {
  2309. return false;
  2310. }
  2311. value = value.replace(/\D/g, '');
  2312. while (value.length < 9) {
  2313. value = '0' + value;
  2314. }
  2315. var sum = 0,
  2316. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  2317. for (var i = 0; i < 8; i++) {
  2318. sum += parseInt(value.charAt(i)) * weight[i];
  2319. }
  2320. sum = 11 - sum % 11;
  2321. if (sum == 11) {
  2322. sum = 0;
  2323. } else if (sum == 10) {
  2324. sum = 'K';
  2325. }
  2326. return sum == value.charAt(8);
  2327. },
  2328. /**
  2329. * Validate Czech national identification number (RC)
  2330. * Examples:
  2331. * - Valid: 7103192745, 991231123
  2332. * - Invalid: 1103492745, 590312123
  2333. *
  2334. * @param {String} value The ID
  2335. * @returns {Boolean}
  2336. */
  2337. _cz: function(value) {
  2338. if (!/^\d{9,10}$/.test(value)) {
  2339. return false;
  2340. }
  2341. var year = 1900 + parseInt(value.substr(0, 2)),
  2342. month = parseInt(value.substr(2, 2)) % 50 % 20,
  2343. day = parseInt(value.substr(4, 2));
  2344. if (value.length == 9) {
  2345. if (year >= 1980) {
  2346. year -= 100;
  2347. }
  2348. if (year > 1953) {
  2349. return false;
  2350. }
  2351. } else if (year < 1954) {
  2352. year += 100;
  2353. }
  2354. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2355. return false;
  2356. }
  2357. // Check that the birth date is not in the future
  2358. if (value.length == 10) {
  2359. var check = parseInt(value.substr(0, 9), 10) % 11;
  2360. if (year < 1985) {
  2361. check = check % 10;
  2362. }
  2363. return (check == value.substr(9, 1));
  2364. }
  2365. return true;
  2366. },
  2367. /**
  2368. * Validate Danish Personal Identification number (CPR)
  2369. * Examples:
  2370. * - Valid: 2110625629, 211062-5629
  2371. * - Invalid: 511062-5629
  2372. *
  2373. * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  2374. * @param {String} value The ID
  2375. * @returns {Boolean}
  2376. */
  2377. _dk: function(value) {
  2378. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  2379. return false;
  2380. }
  2381. value = value.replace(/-/g, '');
  2382. var day = parseInt(value.substr(0, 2), 10),
  2383. month = parseInt(value.substr(2, 2), 10),
  2384. year = parseInt(value.substr(4, 2), 10);
  2385. switch (true) {
  2386. case ('5678'.indexOf(value.charAt(6)) != -1 && year >= 58):
  2387. year += 1800;
  2388. break;
  2389. case ('0123'.indexOf(value.charAt(6)) != -1):
  2390. case ('49'.indexOf(value.charAt(6)) != -1 && year >= 37):
  2391. year += 1900;
  2392. break;
  2393. default:
  2394. year += 2000;
  2395. break;
  2396. }
  2397. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  2398. },
  2399. /**
  2400. * Validate Estonian Personal Identification Code (isikukood)
  2401. * Examples:
  2402. * - Valid: 37605030299
  2403. *
  2404. * @see http://et.wikipedia.org/wiki/Isikukood
  2405. * @param {String} value The ID
  2406. * @returns {Boolean}
  2407. */
  2408. _ee: function(value) {
  2409. // Use the same format as Lithuanian Personal Code
  2410. return this._lt(value);
  2411. },
  2412. /**
  2413. * Validate Spanish personal identity code (DNI)
  2414. * Support i) DNI (for Spanish citizens) and ii) NIE (for foreign people)
  2415. *
  2416. * Examples:
  2417. * - Valid: i) 54362315K, 54362315-K; ii) X2482300W, X-2482300W, X-2482300-W
  2418. * - Invalid: i) 54362315Z; ii) X-2482300A
  2419. *
  2420. * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  2421. * @param {String} value The ID
  2422. * @returns {Boolean}
  2423. */
  2424. _es: function(value) {
  2425. if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]$/.test(value) // DNI
  2426. && !/^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-Z]$/.test(value)) { // NIE
  2427. return false;
  2428. }
  2429. value = value.replace(/-/g, '');
  2430. var index = 'XYZ'.indexOf(value.charAt(0));
  2431. if (index != -1) {
  2432. // It is NIE number
  2433. value = index + value.substr(1) + '';
  2434. }
  2435. var check = parseInt(value.substr(0, 8), 10);
  2436. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  2437. return (check == value.substr(8, 1));
  2438. },
  2439. /**
  2440. * Validate Finnish Personal Identity Code (HETU)
  2441. * Examples:
  2442. * - Valid: 311280-888Y, 131052-308T
  2443. * - Invalid: 131052-308U, 310252-308Y
  2444. *
  2445. * @param {String} value The ID
  2446. * @returns {Boolean}
  2447. */
  2448. _fi: function(value) {
  2449. if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  2450. return false;
  2451. }
  2452. var day = parseInt(value.substr(0, 2), 10),
  2453. month = parseInt(value.substr(2, 2), 10),
  2454. year = parseInt(value.substr(4, 2), 10),
  2455. centuries = {
  2456. '+': 1800,
  2457. '-': 1900,
  2458. 'A': 2000
  2459. };
  2460. year = centuries[value.charAt(6)] + year;
  2461. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2462. return false;
  2463. }
  2464. var individual = parseInt(value.substr(7, 3));
  2465. if (individual < 2) {
  2466. return false;
  2467. }
  2468. var n = value.substr(0, 6) + value.substr(7, 3) + '';
  2469. n = parseInt(n);
  2470. return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) == value.charAt(10);
  2471. },
  2472. /**
  2473. * Validate Croatian personal identification number (OIB)
  2474. * Examples:
  2475. * - Valid: 33392005961
  2476. * - Invalid: 33392005962
  2477. *
  2478. * @param {String} value The ID
  2479. * @returns {Boolean}
  2480. */
  2481. _hr: function(value) {
  2482. if (!/^[0-9]{11}$/.test(value)) {
  2483. return false;
  2484. }
  2485. return $.fn.bootstrapValidator.helpers.mod_11_10(value);
  2486. },
  2487. /**
  2488. * Validate Irish Personal Public Service Number (PPS)
  2489. * Examples:
  2490. * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  2491. * - Invalid: 6433435E, 6433435VH
  2492. *
  2493. * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  2494. * @param {String} value The ID
  2495. * @returns {Boolean}
  2496. */
  2497. _ie: function(value) {
  2498. if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  2499. return false;
  2500. }
  2501. var getCheckDigit = function(value) {
  2502. while (value.length < 7) {
  2503. value = '0' + value;
  2504. }
  2505. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  2506. sum = 0;
  2507. for (var i = 0; i < 7; i++) {
  2508. sum += parseInt(value.charAt(i)) * (8 - i);
  2509. }
  2510. sum += 9 * alphabet.indexOf(value.substr(7));
  2511. return alphabet[sum % 23];
  2512. };
  2513. // 2013 format
  2514. if (value.length == 9 && ('A' == value.charAt(8) || 'H' == value.charAt(8))) {
  2515. return value.charAt(7) == getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  2516. }
  2517. // The old format
  2518. else {
  2519. return value.charAt(7) == getCheckDigit(value.substr(0, 7));
  2520. }
  2521. },
  2522. /**
  2523. * Validate Iceland national identification number (Kennitala)
  2524. * Examples:
  2525. * - Valid: 120174-3399, 1201743399, 0902862349
  2526. *
  2527. * @see http://en.wikipedia.org/wiki/Kennitala
  2528. * @param {String} value The ID
  2529. * @returns {Boolean}
  2530. */
  2531. _is: function(value) {
  2532. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  2533. return false;
  2534. }
  2535. value = value.replace(/-/g, '');
  2536. var day = parseInt(value.substr(0, 2), 10),
  2537. month = parseInt(value.substr(2, 2), 10),
  2538. year = parseInt(value.substr(4, 2), 10),
  2539. century = parseInt(value.charAt(9));
  2540. year = (century == 9) ? (1900 + year) : ((20 + century) * 100 + year);
  2541. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  2542. return false;
  2543. }
  2544. // Validate the check digit
  2545. var sum = 0,
  2546. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  2547. for (var i = 0; i < 8; i++) {
  2548. sum += parseInt(value.charAt(i)) * weight[i];
  2549. }
  2550. sum = 11 - sum % 11;
  2551. return (sum == value.charAt(8));
  2552. },
  2553. /**
  2554. * Validate Lithuanian Personal Code (Asmens kodas)
  2555. * Examples:
  2556. * - Valid: 38703181745
  2557. * - Invalid: 38703181746, 78703181745, 38703421745
  2558. *
  2559. * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  2560. * @see http://www.adomas.org/midi2007/pcode.html
  2561. * @param {String} value The ID
  2562. * @returns {Boolean}
  2563. */
  2564. _lt: function(value) {
  2565. if (!/^[0-9]{11}$/.test(value)) {
  2566. return false;
  2567. }
  2568. var gender = parseInt(value.charAt(0)),
  2569. year = parseInt(value.substr(1, 2), 10),
  2570. month = parseInt(value.substr(3, 2), 10),
  2571. day = parseInt(value.substr(5, 2), 10),
  2572. century = (gender % 2 == 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  2573. year = century * 100 + year;
  2574. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  2575. return false;
  2576. }
  2577. // Validate the check digit
  2578. var sum = 0,
  2579. weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  2580. for (var i = 0; i < 10; i++) {
  2581. sum += parseInt(value.charAt(i)) * weight[i];
  2582. }
  2583. sum = sum % 11;
  2584. if (sum != 10) {
  2585. return sum == value.charAt(10);
  2586. }
  2587. // Re-calculate the check digit
  2588. sum = 0;
  2589. weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  2590. for (i = 0; i < 10; i++) {
  2591. sum += parseInt(value.charAt(i)) * weight[i];
  2592. }
  2593. sum = sum % 11;
  2594. if (sum == 10) {
  2595. sum = 0;
  2596. }
  2597. return (sum == value.charAt(10));
  2598. },
  2599. /**
  2600. * Validate Latvian Personal Code (Personas kods)
  2601. * Examples:
  2602. * - Valid: 161175-19997, 16117519997
  2603. * - Invalid: 161375-19997
  2604. *
  2605. * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  2606. * @param {String} value The ID
  2607. * @returns {Boolean}
  2608. */
  2609. _lv: function(value) {
  2610. if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  2611. return false;
  2612. }
  2613. value = value.replace(/\D/g, '');
  2614. // Check birth date
  2615. var day = parseInt(value.substr(0, 2)),
  2616. month = parseInt(value.substr(2, 2)),
  2617. year = parseInt(value.substr(4, 2));
  2618. year = year + 1800 + parseInt(value.charAt(6)) * 100;
  2619. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  2620. return false;
  2621. }
  2622. // Check personal code
  2623. var sum = 0,
  2624. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  2625. for (var i = 0; i < 10; i++) {
  2626. sum += parseInt(value.charAt(i)) * weight[i];
  2627. }
  2628. sum = (sum + 1) % 11 % 10;
  2629. return (sum == value.charAt(10));
  2630. },
  2631. /**
  2632. * Validate Dutch national identification number (BSN)
  2633. * Examples:
  2634. * - Valid: 111222333, 941331490, 9413.31.490
  2635. * - Invalid: 111252333
  2636. *
  2637. * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  2638. * @param {String} value The ID
  2639. * @returns {Boolean}
  2640. */
  2641. _nl: function(value) {
  2642. while (value.length < 9) {
  2643. value = '0' + value;
  2644. }
  2645. if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  2646. return false;
  2647. }
  2648. value = value.replace(/\./g, '');
  2649. if (parseInt(value, 10) == 0) {
  2650. return false;
  2651. }
  2652. var sum = 0,
  2653. length = value.length;
  2654. for (var i = 0; i < length - 1; i++) {
  2655. sum += (9 - i) * parseInt(value.charAt(i));
  2656. }
  2657. sum = sum % 11;
  2658. if (sum == 10) {
  2659. sum = 0;
  2660. }
  2661. return (sum == value.charAt(length - 1));
  2662. },
  2663. /**
  2664. * Validate Romanian numerical personal code (CNP)
  2665. * Examples:
  2666. * - Valid: 1630615123457, 1800101221144
  2667. * - Invalid: 8800101221144, 1632215123457, 1630615123458
  2668. *
  2669. * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  2670. * @param {String} value The ID
  2671. * @returns {Boolean}
  2672. */
  2673. _ro: function(value) {
  2674. if (!/^[0-9]{13}$/.test(value)) {
  2675. return false;
  2676. }
  2677. var gender = parseInt(value.charAt(0));
  2678. if (gender == 0 || gender == 7 || gender == 8) {
  2679. return false;
  2680. }
  2681. // Determine the date of birth
  2682. var year = parseInt(value.substr(1, 2), 10),
  2683. month = parseInt(value.substr(3, 2), 10),
  2684. day = parseInt(value.substr(5, 2), 10),
  2685. // The year of date is determined base on the gender
  2686. centuries = {
  2687. '1': 1900, // Male born between 1900 and 1999
  2688. '2': 1900, // Female born between 1900 and 1999
  2689. '3': 1800, // Male born between 1800 and 1899
  2690. '4': 1800, // Female born between 1800 and 1899
  2691. '5': 2000, // Male born after 2000
  2692. '6': 2000 // Female born after 2000
  2693. };
  2694. if (day > 31 && month > 12) {
  2695. return false;
  2696. }
  2697. if (gender != 9) {
  2698. year = centuries[gender + ''] + year;
  2699. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2700. return false;
  2701. }
  2702. }
  2703. // Validate the check digit
  2704. var sum = 0,
  2705. weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  2706. length = value.length;
  2707. for (var i = 0; i < length - 1; i++) {
  2708. sum += parseInt(value.charAt(i)) * weight[i];
  2709. }
  2710. sum = sum % 11;
  2711. if (sum == 10) {
  2712. sum = 1;
  2713. }
  2714. return (sum == value.charAt(length - 1));
  2715. },
  2716. /**
  2717. * Validate Swedish personal identity number (personnummer)
  2718. * Examples:
  2719. * - Valid: 8112289874, 811228-9874, 811228+9874
  2720. * - Invalid: 811228-9873
  2721. *
  2722. * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  2723. * @param {String} value The ID
  2724. * @returns {Boolean}
  2725. */
  2726. _se: function(value) {
  2727. if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  2728. return false;
  2729. }
  2730. value = value.replace(/[^0-9]/g, '');
  2731. var year = parseInt(value.substr(0, 2)) + 1900,
  2732. month = parseInt(value.substr(2, 2)),
  2733. day = parseInt(value.substr(4, 2));
  2734. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2735. return false;
  2736. }
  2737. // Validate the last check digit
  2738. return $.fn.bootstrapValidator.helpers.luhn(value);
  2739. },
  2740. /**
  2741. * Validate Slovak national identifier number (RC)
  2742. * Examples:
  2743. * - Valid: 7103192745, 991231123
  2744. * - Invalid: 7103192746, 1103492745
  2745. *
  2746. * @param {String} value The ID
  2747. * @returns {Boolean}
  2748. */
  2749. _sk: function(value) {
  2750. // Slovakia uses the same format as Czech Republic
  2751. return this._cz(value);
  2752. },
  2753. /**
  2754. * Validate San Marino citizen number
  2755. *
  2756. * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  2757. * @param {String} value The ID
  2758. * @returns {Boolean}
  2759. */
  2760. _sm: function(value) {
  2761. return /^\d{5}$/.test(value);
  2762. },
  2763. /**
  2764. * Validate South African ID
  2765. * Example:
  2766. * - Valid: 8001015009087
  2767. * - Invalid: 8001015009287, 8001015009086
  2768. *
  2769. * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  2770. * @param {String} value The ID
  2771. * @returns {Boolean}
  2772. */
  2773. _za: function(value) {
  2774. if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  2775. return false;
  2776. }
  2777. var year = parseInt(value.substr(0, 2)),
  2778. currentYear = new Date().getFullYear() % 100,
  2779. month = parseInt(value.substr(2, 2)),
  2780. day = parseInt(value.substr(4, 2));
  2781. year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  2782. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2783. return false;
  2784. }
  2785. // Validate the last check digit
  2786. return $.fn.bootstrapValidator.helpers.luhn(value);
  2787. }
  2788. };
  2789. }(window.jQuery));
  2790. ;(function($) {
  2791. $.fn.bootstrapValidator.validators.identical = {
  2792. html5Attributes: {
  2793. message: 'message',
  2794. field: 'field'
  2795. },
  2796. /**
  2797. * Check if input value equals to value of particular one
  2798. *
  2799. * @param {BootstrapValidator} validator The validator plugin instance
  2800. * @param {jQuery} $field Field element
  2801. * @param {Object} options Consists of the following key:
  2802. * - field: The name of field that will be used to compare with current one
  2803. * @returns {Boolean}
  2804. */
  2805. validate: function(validator, $field, options) {
  2806. var value = $field.val();
  2807. if (value == '') {
  2808. return true;
  2809. }
  2810. var compareWith = validator.getFieldElements(options.field);
  2811. if (compareWith == null) {
  2812. return true;
  2813. }
  2814. if (value == compareWith.val()) {
  2815. validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
  2816. return true;
  2817. } else {
  2818. return false;
  2819. }
  2820. }
  2821. };
  2822. }(window.jQuery));
  2823. ;(function($) {
  2824. $.fn.bootstrapValidator.validators.imei = {
  2825. /**
  2826. * Validate IMEI (International Mobile Station Equipment Identity)
  2827. * Examples:
  2828. * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  2829. * - Invalid: 490154203237517
  2830. *
  2831. * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  2832. * @param {BootstrapValidator} validator The validator plugin instance
  2833. * @param {jQuery} $field Field element
  2834. * @param {Object} options Can consist of the following keys:
  2835. * - message: The invalid message
  2836. * @returns {Boolean}
  2837. */
  2838. validate: function(validator, $field, options) {
  2839. var value = $field.val();
  2840. if (value == '') {
  2841. return true;
  2842. }
  2843. switch (true) {
  2844. case /^\d{15}$/.test(value):
  2845. case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  2846. case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  2847. value = value.replace(/[^0-9]/g, '');
  2848. return $.fn.bootstrapValidator.helpers.luhn(value);
  2849. break;
  2850. case /^\d{14}$/.test(value):
  2851. case /^\d{16}$/.test(value):
  2852. case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  2853. case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  2854. return true;
  2855. default:
  2856. return false;
  2857. }
  2858. }
  2859. };
  2860. }(window.jQuery));
  2861. ;(function($) {
  2862. $.fn.bootstrapValidator.validators.integer = {
  2863. enableByHtml5: function($field) {
  2864. return ('number' == $field.attr('type'));
  2865. },
  2866. /**
  2867. * Return true if the input value is an integer
  2868. *
  2869. * @param {BootstrapValidator} validator The validator plugin instance
  2870. * @param {jQuery} $field Field element
  2871. * @param {Object} options Can consist of the following key:
  2872. * - message: The invalid message
  2873. * @returns {Boolean}
  2874. */
  2875. validate: function(validator, $field, options) {
  2876. var value = $field.val();
  2877. if (value == '') {
  2878. return true;
  2879. }
  2880. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  2881. }
  2882. };
  2883. }(window.jQuery));
  2884. ;(function($) {
  2885. $.fn.bootstrapValidator.validators.ip = {
  2886. html5Attributes: {
  2887. message: 'message',
  2888. ipv4: 'ipv4',
  2889. ipv6: 'ipv6'
  2890. },
  2891. /**
  2892. * Return true if the input value is a IP address.
  2893. *
  2894. * @param {BootstrapValidator} validator The validator plugin instance
  2895. * @param {jQuery} $field Field element
  2896. * @param {Object} options Can consist of the following keys:
  2897. * - ipv4: Enable IPv4 validator, default to true
  2898. * - ipv6: Enable IPv6 validator, default to true
  2899. * - message: The invalid message
  2900. * @returns {Boolean}
  2901. */
  2902. validate: function(validator, $field, options) {
  2903. var value = $field.val();
  2904. if (value == '') {
  2905. return true;
  2906. }
  2907. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  2908. if (options.ipv4) {
  2909. return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(value);
  2910. } else if (options.ipv6) {
  2911. return /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/.test(str);
  2912. }
  2913. return false;
  2914. }
  2915. };
  2916. }(window.jQuery));
  2917. ;(function($) {
  2918. $.fn.bootstrapValidator.validators.isbn = {
  2919. /**
  2920. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  2921. * Examples:
  2922. * - Valid:
  2923. * ISBN 10: 99921-58-10-7, 9971-5-0210-0, 960-425-059-0, 80-902734-1-6, 85-359-0277-5, 1-84356-028-3, 0-684-84328-5, 0-8044-2957-X, 0-85131-041-9, 0-943396-04-2, 0-9752298-0-X
  2924. * ISBN 13: 978-0-306-40615-7
  2925. * - Invalid:
  2926. * ISBN 10: 99921-58-10-6
  2927. * ISBN 13: 978-0-306-40615-6
  2928. *
  2929. * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  2930. * @param {BootstrapValidator} validator The validator plugin instance
  2931. * @param {jQuery} $field Field element
  2932. * @param {Object} options Can consist of the following keys:
  2933. * - message: The invalid message
  2934. * @returns {Boolean}
  2935. */
  2936. validate: function(validator, $field, options) {
  2937. var value = $field.val();
  2938. if (value == '') {
  2939. return true;
  2940. }
  2941. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  2942. // Groups are separated by a hyphen or a space
  2943. var type;
  2944. switch (true) {
  2945. case /^\d{9}[\dX]$/.test(value):
  2946. case (value.length == 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  2947. case (value.length == 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  2948. type = 'ISBN10';
  2949. break;
  2950. case /^(978|979)\d{9}[\dX]$/.test(value):
  2951. case (value.length == 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  2952. case (value.length == 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  2953. type = 'ISBN13';
  2954. break;
  2955. default:
  2956. return false;
  2957. }
  2958. // Replace all special characters except digits and X
  2959. value = value.replace(/[^0-9X]/gi, '');
  2960. var chars = value.split(''),
  2961. length = chars.length,
  2962. sum = 0,
  2963. checksum;
  2964. switch (type) {
  2965. case 'ISBN10':
  2966. sum = 0;
  2967. for (var i = 0; i < length - 1; i++) {
  2968. sum += ((10 - i) * parseInt(chars[i]));
  2969. }
  2970. checksum = 11 - (sum % 11);
  2971. if (checksum == 11) {
  2972. checksum = 0;
  2973. } else if (checksum == 10) {
  2974. checksum = 'X';
  2975. }
  2976. return (checksum + '' == chars[length - 1]);
  2977. case 'ISBN13':
  2978. sum = 0;
  2979. for (var i = 0; i < length - 1; i++) {
  2980. sum += ((i % 2 == 0) ? parseInt(chars[i]) : (parseInt(chars[i]) * 3));
  2981. }
  2982. checksum = 10 - (sum % 10);
  2983. if (checksum == 10) {
  2984. checksum = '0';
  2985. }
  2986. return (checksum + '' == chars[length - 1]);
  2987. default:
  2988. return false;
  2989. }
  2990. }
  2991. };
  2992. }(window.jQuery));
  2993. ;(function($) {
  2994. $.fn.bootstrapValidator.validators.isin = {
  2995. // Available country codes
  2996. // See http://isin.net/country-codes/
  2997. COUNTRY_CODES: 'AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW',
  2998. /**
  2999. * Validate an ISIN (International Securities Identification Number)
  3000. * Examples:
  3001. * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  3002. * - Invalid: US0378331004, AA0000XVGZA3
  3003. *
  3004. * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  3005. * @param {BootstrapValidator} validator The validator plugin instance
  3006. * @param {jQuery} $field Field element
  3007. * @param {Object} options Can consist of the following keys:
  3008. * - message: The invalid message
  3009. * @returns {Boolean}
  3010. */
  3011. validate: function(validator, $field, options) {
  3012. var value = $field.val();
  3013. if (value == '') {
  3014. return true;
  3015. }
  3016. value = value.toUpperCase();
  3017. var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  3018. if (!regex.test(value)) {
  3019. return false;
  3020. }
  3021. var converted = '',
  3022. length = value.length;
  3023. // Convert letters to number
  3024. for (var i = 0; i < length - 1; i++) {
  3025. var c = value.charCodeAt(i);
  3026. converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  3027. }
  3028. var digits = '',
  3029. n = converted.length,
  3030. group = (n % 2 != 0) ? 0 : 1;
  3031. for (i = 0; i < n; i++) {
  3032. digits += (parseInt(converted[i]) * ((i % 2) == group ? 2 : 1) + '');
  3033. }
  3034. var sum = 0;
  3035. for (i = 0; i < digits.length; i++) {
  3036. sum += parseInt(digits.charAt(i));
  3037. }
  3038. sum = (10 - (sum % 10)) % 10;
  3039. return sum == value.charAt(length - 1);
  3040. }
  3041. };
  3042. }(window.jQuery));
  3043. ;(function($) {
  3044. $.fn.bootstrapValidator.validators.ismn = {
  3045. /**
  3046. * Validate ISMN (International Standard Music Number)
  3047. * Examples:
  3048. * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  3049. * - Invalid: 9790060115614
  3050. *
  3051. * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  3052. * @param {BootstrapValidator} validator The validator plugin instance
  3053. * @param {jQuery} $field Field element
  3054. * @param {Object} options Can consist of the following keys:
  3055. * - message: The invalid message
  3056. * @returns {Boolean}
  3057. */
  3058. validate: function(validator, $field, options) {
  3059. var value = $field.val();
  3060. if (value == '') {
  3061. return true;
  3062. }
  3063. // Groups are separated by a hyphen or a space
  3064. var type;
  3065. switch (true) {
  3066. case /^M\d{9}$/.test(value):
  3067. case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  3068. case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3069. type = 'ISMN10';
  3070. break;
  3071. case /^9790\d{9}$/.test(value):
  3072. case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  3073. case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3074. type = 'ISMN13';
  3075. break;
  3076. default:
  3077. return false;
  3078. }
  3079. if ('ISMN10' == type) {
  3080. value = '9790' + value.substr(1);
  3081. }
  3082. // Replace all special characters except digits
  3083. value = value.replace(/[^0-9]/gi, '');
  3084. var length = value.length,
  3085. sum = 0,
  3086. weight = [1, 3];
  3087. for (var i = 0; i < length - 1; i++) {
  3088. sum += parseInt(value.charAt(i)) * weight[i % 2];
  3089. }
  3090. sum = 10 - sum % 10;
  3091. return (sum == value.charAt(length - 1));
  3092. }
  3093. };
  3094. }(window.jQuery));
  3095. ;(function($) {
  3096. $.fn.bootstrapValidator.validators.issn = {
  3097. /**
  3098. * Validate ISSN (International Standard Serial Number)
  3099. * Examples:
  3100. * - Valid: 0378-5955, 0024-9319, 0032-1478
  3101. * - Invalid: 0032-147X
  3102. *
  3103. * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  3104. * @param {BootstrapValidator} validator The validator plugin instance
  3105. * @param {jQuery} $field Field element
  3106. * @param {Object} options Can consist of the following keys:
  3107. * - message: The invalid message
  3108. * @returns {Boolean}
  3109. */
  3110. validate: function(validator, $field, options) {
  3111. var value = $field.val();
  3112. if (value == '') {
  3113. return true;
  3114. }
  3115. // Groups are separated by a hyphen or a space
  3116. if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  3117. return false;
  3118. }
  3119. // Replace all special characters except digits and X
  3120. value = value.replace(/[^0-9X]/gi, '');
  3121. var chars = value.split(''),
  3122. length = chars.length,
  3123. sum = 0;
  3124. if (chars[7] == 'X') {
  3125. chars[7] = 10;
  3126. }
  3127. for (var i = 0; i < length; i++) {
  3128. sum += ((8 - i) * parseInt(chars[i]));
  3129. }
  3130. return (sum % 11 == 0);
  3131. }
  3132. };
  3133. }(window.jQuery));
  3134. ;(function($) {
  3135. $.fn.bootstrapValidator.validators.lessThan = {
  3136. html5Attributes: {
  3137. message: 'message',
  3138. value: 'value',
  3139. inclusive: 'inclusive'
  3140. },
  3141. enableByHtml5: function($field) {
  3142. var max = $field.attr('max');
  3143. if (max) {
  3144. return {
  3145. value: max
  3146. };
  3147. }
  3148. return false;
  3149. },
  3150. /**
  3151. * Return true if the input value is less than or equal to given number
  3152. *
  3153. * @param {BootstrapValidator} validator The validator plugin instance
  3154. * @param {jQuery} $field Field element
  3155. * @param {Object} options Can consist of the following keys:
  3156. * - value: The number used to compare to
  3157. * - inclusive [optional]: Can be true or false. Default is true
  3158. * - message: The invalid message
  3159. * @returns {Boolean}
  3160. */
  3161. validate: function(validator, $field, options) {
  3162. var value = $field.val();
  3163. if (value == '') {
  3164. return true;
  3165. }
  3166. value = parseFloat(value);
  3167. return (options.inclusive === true || options.inclusive == undefined) ? (value <= options.value) : (value < options.value);
  3168. }
  3169. };
  3170. }(window.jQuery));
  3171. ;(function($) {
  3172. $.fn.bootstrapValidator.validators.mac = {
  3173. /**
  3174. * Return true if the input value is a MAC address.
  3175. *
  3176. * @param {BootstrapValidator} validator The validator plugin instance
  3177. * @param {jQuery} $field Field element
  3178. * @param {Object} options Can consist of the following keys:
  3179. * - message: The invalid message
  3180. * @returns {Boolean}
  3181. */
  3182. validate: function(validator, $field, options) {
  3183. var value = $field.val();
  3184. if (value == '') {
  3185. return true;
  3186. }
  3187. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  3188. }
  3189. };
  3190. }(window.jQuery));
  3191. ;(function($) {
  3192. $.fn.bootstrapValidator.validators.notEmpty = {
  3193. enableByHtml5: function($field) {
  3194. var required = $field.attr('required') + '';
  3195. return ('required' == required || 'true' == required);
  3196. },
  3197. /**
  3198. * Check if input value is empty or not
  3199. *
  3200. * @param {BootstrapValidator} validator The validator plugin instance
  3201. * @param {jQuery} $field Field element
  3202. * @param {Object} options
  3203. * @returns {Boolean}
  3204. */
  3205. validate: function(validator, $field, options) {
  3206. var type = $field.attr('type');
  3207. if ('radio' == type || 'checkbox' == type) {
  3208. return validator
  3209. .getFieldElements($field.attr('data-bv-field'))
  3210. .filter(':checked')
  3211. .length > 0;
  3212. }
  3213. return $.trim($field.val()) != '';
  3214. }
  3215. };
  3216. }(window.jQuery));
  3217. ;(function($) {
  3218. $.fn.bootstrapValidator.validators.numeric = {
  3219. html5Attributes: {
  3220. message: 'message',
  3221. separator: 'separator'
  3222. },
  3223. /**
  3224. * Validate decimal number
  3225. *
  3226. * @param {BootstrapValidator} validator The validator plugin instance
  3227. * @param {jQuery} $field Field element
  3228. * @param {Object} options Consist of key:
  3229. * - message: The invalid message
  3230. * - separator: The decimal separator. Can be "." (default), ","
  3231. * @returns {Boolean}
  3232. */
  3233. validate: function(validator, $field, options) {
  3234. var value = $field.val();
  3235. if (value == '') {
  3236. return true;
  3237. }
  3238. var separator = options.separator || '.';
  3239. if (separator != '.') {
  3240. value = value.replace(separator, '.');
  3241. }
  3242. return !isNaN(parseFloat(value)) && isFinite(value);
  3243. }
  3244. };
  3245. }(window.jQuery));
  3246. ;(function($) {
  3247. $.fn.bootstrapValidator.validators.phone = {
  3248. html5Attributes: {
  3249. message: 'message',
  3250. country: 'country'
  3251. },
  3252. /**
  3253. * Return true if the input value contains a valid US phone number only
  3254. *
  3255. * @param {BootstrapValidator} validator Validate plugin instance
  3256. * @param {jQuery} $field Field element
  3257. * @param {Object} options Consist of key:
  3258. * - message: The invalid message
  3259. * - country: The ISO 3166 country code
  3260. * Currently it only supports United State (US) country
  3261. * @returns {Boolean}
  3262. */
  3263. validate: function(validator, $field, options) {
  3264. var value = $field.val();
  3265. if (value == '') {
  3266. return true;
  3267. }
  3268. var country = (options.country || 'US').toUpperCase();
  3269. switch (country) {
  3270. case 'US':
  3271. default:
  3272. // Make sure US phone numbers have 10 digits
  3273. // May start with 1, +1, or 1-; should discard
  3274. // Area code may be delimited with (), & sections may be delimited with . or -
  3275. // Test: http://regexr.com/38mqi
  3276. value = value.replace(/\D/g, '');
  3277. return (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
  3278. }
  3279. }
  3280. }
  3281. }(window.jQuery));
  3282. ;(function($) {
  3283. $.fn.bootstrapValidator.validators.regexp = {
  3284. html5Attributes: {
  3285. message: 'message',
  3286. regexp: 'regexp'
  3287. },
  3288. enableByHtml5: function($field) {
  3289. var pattern = $field.attr('pattern');
  3290. if (pattern) {
  3291. return {
  3292. regexp: pattern
  3293. };
  3294. }
  3295. return false;
  3296. },
  3297. /**
  3298. * Check if the element value matches given regular expression
  3299. *
  3300. * @param {BootstrapValidator} validator The validator plugin instance
  3301. * @param {jQuery} $field Field element
  3302. * @param {Object} options Consists of the following key:
  3303. * - regexp: The regular expression you need to check
  3304. * @returns {Boolean}
  3305. */
  3306. validate: function(validator, $field, options) {
  3307. var value = $field.val();
  3308. if (value == '') {
  3309. return true;
  3310. }
  3311. var regexp = ('string' == typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  3312. return regexp.test(value);
  3313. }
  3314. };
  3315. }(window.jQuery));
  3316. ;(function($) {
  3317. $.fn.bootstrapValidator.validators.remote = {
  3318. html5Attributes: {
  3319. message: 'message',
  3320. url: 'url',
  3321. name: 'name'
  3322. },
  3323. /**
  3324. * Request a remote server to check the input value
  3325. *
  3326. * @param {BootstrapValidator} validator Plugin instance
  3327. * @param {jQuery} $field Field element
  3328. * @param {Object} options Can consist of the following keys:
  3329. * - url
  3330. * - data [optional]: By default, it will take the value
  3331. * {
  3332. * <fieldName>: <fieldValue>
  3333. * }
  3334. * - name [optional]: Override the field name for the request.
  3335. * - message: The invalid message
  3336. * @returns {Boolean|Deferred}
  3337. */
  3338. validate: function(validator, $field, options) {
  3339. var value = $field.val();
  3340. if (value == '') {
  3341. return true;
  3342. }
  3343. var name = $field.attr('data-bv-field'), data = options.data;
  3344. if (data == null) {
  3345. data = {};
  3346. }
  3347. // Support dynamic data
  3348. if ('function' == typeof data) {
  3349. data = data.call(this, validator);
  3350. }
  3351. data[options.name || name] = value;
  3352. var dfd = new $.Deferred();
  3353. var xhr = $.ajax({
  3354. type: 'POST',
  3355. url: options.url,
  3356. dataType: 'json',
  3357. data: data
  3358. });
  3359. xhr.then(function(response) {
  3360. dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true', response.message ? response.message : null);
  3361. });
  3362. dfd.fail(function() {
  3363. xhr.abort();
  3364. });
  3365. return dfd;
  3366. }
  3367. };
  3368. }(window.jQuery));
  3369. ;(function($) {
  3370. $.fn.bootstrapValidator.validators.rtn = {
  3371. /**
  3372. * Validate a RTN (Routing transit number)
  3373. * Examples:
  3374. * - Valid: 021200025, 789456124
  3375. *
  3376. * @see http://en.wikipedia.org/wiki/Routing_transit_number
  3377. * @param {BootstrapValidator} validator The validator plugin instance
  3378. * @param {jQuery} $field Field element
  3379. * @param {Object} options Can consist of the following keys:
  3380. * - message: The invalid message
  3381. * @returns {Boolean}
  3382. */
  3383. validate: function(validator, $field, options) {
  3384. var value = $field.val();
  3385. if (value == '') {
  3386. return true;
  3387. }
  3388. if (!/^\d{9}$/.test(value)) {
  3389. return false;
  3390. }
  3391. var sum = 0;
  3392. for (var i = 0; i < value.length; i += 3) {
  3393. sum += parseInt(value.charAt(i), 10) * 3
  3394. + parseInt(value.charAt(i + 1), 10) * 7
  3395. + parseInt(value.charAt(i + 2), 10);
  3396. }
  3397. return (sum != 0 && sum % 10 == 0);
  3398. }
  3399. };
  3400. }(window.jQuery));
  3401. ;(function($) {
  3402. $.fn.bootstrapValidator.validators.sedol = {
  3403. /**
  3404. * Validate a SEDOL (Stock Exchange Daily Official List)
  3405. * Examples:
  3406. * - Valid: 0263494, B0WNLY7
  3407. *
  3408. * @see http://en.wikipedia.org/wiki/SEDOL
  3409. * @param {BootstrapValidator} validator The validator plugin instance
  3410. * @param {jQuery} $field Field element
  3411. * @param {Object} options Can consist of the following keys:
  3412. * - message: The invalid message
  3413. * @returns {Boolean}
  3414. */
  3415. validate: function(validator, $field, options) {
  3416. var value = $field.val();
  3417. if (value == '') {
  3418. return true;
  3419. }
  3420. value = value.toUpperCase();
  3421. if (!/^[0-9A-Z]{7}$/.test(value)) {
  3422. return false;
  3423. }
  3424. var sum = 0,
  3425. weight = [1, 3, 1, 7, 3, 9, 1],
  3426. length = value.length;
  3427. for (var i = 0; i < length - 1; i++) {
  3428. sum += weight[i] * parseInt(value.charAt(i), 36);
  3429. }
  3430. sum = (10 - sum % 10) % 10;
  3431. return sum == value.charAt(length - 1);
  3432. }
  3433. };
  3434. }(window.jQuery));
  3435. ;(function($) {
  3436. $.fn.bootstrapValidator.validators.siren = {
  3437. /**
  3438. * Check if a string is a siren number
  3439. *
  3440. * @param {BootstrapValidator} validator The validator plugin instance
  3441. * @param {jQuery} $field Field element
  3442. * @param {Object} options Consist of key:
  3443. * - message: The invalid message
  3444. * @returns {Boolean}
  3445. */
  3446. validate: function(validator, $field, options) {
  3447. var value = $field.val();
  3448. if (value == '') {
  3449. return true;
  3450. }
  3451. if (!/^\d{9}$/.test(value)) {
  3452. return false;
  3453. }
  3454. return $.fn.bootstrapValidator.helpers.luhn(value);
  3455. }
  3456. };
  3457. }(window.jQuery));
  3458. ;(function($) {
  3459. $.fn.bootstrapValidator.validators.siret = {
  3460. /**
  3461. * Check if a string is a siret number
  3462. *
  3463. * @param {BootstrapValidator} validator The validator plugin instance
  3464. * @param {jQuery} $field Field element
  3465. * @param {Object} options Consist of key:
  3466. * - message: The invalid message
  3467. * @returns {Boolean}
  3468. */
  3469. validate: function(validator, $field, options) {
  3470. var value = $field.val();
  3471. if (value == '') {
  3472. return true;
  3473. }
  3474. var sum = 0,
  3475. length = value.length,
  3476. tmp;
  3477. for (var i = 0; i < length; i++) {
  3478. tmp = parseInt(value.charAt(i), 10);
  3479. if ((i % 2) == 0) {
  3480. tmp = tmp * 2;
  3481. if (tmp > 9) {
  3482. tmp -= 9;
  3483. }
  3484. }
  3485. sum += tmp;
  3486. }
  3487. return (sum % 10 == 0);
  3488. }
  3489. };
  3490. }(window.jQuery));
  3491. ;(function($) {
  3492. $.fn.bootstrapValidator.validators.step = {
  3493. html5Attributes: {
  3494. message: 'message',
  3495. base: 'baseValue',
  3496. step: 'step'
  3497. },
  3498. /**
  3499. * Return true if the input value is valid step one
  3500. *
  3501. * @param {BootstrapValidator} validator The validator plugin instance
  3502. * @param {jQuery} $field Field element
  3503. * @param {Object} options Can consist of the following keys:
  3504. * - baseValue: The base value
  3505. * - step: The step
  3506. * - message: The invalid message
  3507. * @returns {Boolean}
  3508. */
  3509. validate: function(validator, $field, options) {
  3510. var value = $field.val();
  3511. if (value == '') {
  3512. return true;
  3513. }
  3514. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  3515. value = parseFloat(value);
  3516. if (isNaN(value) || !isFinite(value)) {
  3517. return false;
  3518. }
  3519. var round = function(x, precision) {
  3520. var m = Math.pow(10, precision);
  3521. x = x * m;
  3522. var sign = (x > 0) | -(x < 0),
  3523. isHalf = (x % 1 === 0.5 * sign);
  3524. if (isHalf) {
  3525. return (Math.floor(x) + (sign > 0)) / m;
  3526. } else {
  3527. return Math.round(x) / m;
  3528. }
  3529. },
  3530. floatMod = function(x, y) {
  3531. if (y == 0.0) {
  3532. return 1.0;
  3533. }
  3534. var dotX = (x + '').split('.'),
  3535. dotY = (y + '').split('.'),
  3536. precision = ((dotX.length == 1) ? 0 : dotX[1].length) + ((dotY.length == 1) ? 0 : dotY[1].length);
  3537. return round(x - y * Math.floor(x / y), precision);
  3538. };
  3539. var mod = floatMod(value - options.baseValue, options.step);
  3540. return (mod == 0.0 || mod == options.step);
  3541. }
  3542. };
  3543. }(window.jQuery));
  3544. ;(function($) {
  3545. $.fn.bootstrapValidator.validators.stringCase = {
  3546. html5Attributes: {
  3547. message: 'message',
  3548. 'case': 'case'
  3549. },
  3550. /**
  3551. * Check if a string is a lower or upper case one
  3552. *
  3553. * @param {BootstrapValidator} validator The validator plugin instance
  3554. * @param {jQuery} $field Field element
  3555. * @param {Object} options Consist of key:
  3556. * - message: The invalid message
  3557. * - case: Can be 'lower' (default) or 'upper'
  3558. * @returns {Boolean}
  3559. */
  3560. validate: function(validator, $field, options) {
  3561. var value = $field.val();
  3562. if (value == '') {
  3563. return true;
  3564. }
  3565. var stringCase = (options['case'] || 'lower').toLowerCase();
  3566. switch (stringCase) {
  3567. case 'upper':
  3568. return value === value.toUpperCase();
  3569. case 'lower':
  3570. default:
  3571. return value === value.toLowerCase();
  3572. }
  3573. }
  3574. };
  3575. }(window.jQuery));
  3576. ;(function($) {
  3577. $.fn.bootstrapValidator.validators.stringLength = {
  3578. html5Attributes: {
  3579. message: 'message',
  3580. min: 'min',
  3581. max: 'max'
  3582. },
  3583. enableByHtml5: function($field) {
  3584. var maxLength = $field.attr('maxlength');
  3585. if (maxLength) {
  3586. return {
  3587. max: parseInt(maxLength, 10)
  3588. };
  3589. }
  3590. return false;
  3591. },
  3592. /**
  3593. * Check if the length of element value is less or more than given number
  3594. *
  3595. * @param {BootstrapValidator} validator The validator plugin instance
  3596. * @param {jQuery} $field Field element
  3597. * @param {Object} options Consists of following keys:
  3598. * - min
  3599. * - max
  3600. * At least one of two keys is required
  3601. * - message: The invalid message
  3602. * @returns {Boolean}
  3603. */
  3604. validate: function(validator, $field, options) {
  3605. var value = $field.val();
  3606. if (value == '') {
  3607. return true;
  3608. }
  3609. var length = $.trim(value).length;
  3610. if ((options.min && length < options.min) || (options.max && length > options.max)) {
  3611. return false;
  3612. }
  3613. return true;
  3614. }
  3615. };
  3616. }(window.jQuery));
  3617. ;(function($) {
  3618. $.fn.bootstrapValidator.validators.uri = {
  3619. enableByHtml5: function($field) {
  3620. return ('url' == $field.attr('type'));
  3621. },
  3622. /**
  3623. * Return true if the input value is a valid URL
  3624. *
  3625. * @param {BootstrapValidator} validator The validator plugin instance
  3626. * @param {jQuery} $field Field element
  3627. * @param {Object} options
  3628. * @returns {Boolean}
  3629. */
  3630. validate: function(validator, $field, options) {
  3631. var value = $field.val();
  3632. if (value == '') {
  3633. return true;
  3634. }
  3635. // Credit to https://gist.github.com/dperini/729294
  3636. //
  3637. // Regular Expression for URL validation
  3638. //
  3639. // Author: Diego Perini
  3640. // Updated: 2010/12/05
  3641. //
  3642. // the regular expression composed & commented
  3643. // could be easily tweaked for RFC compliance,
  3644. // it was expressly modified to fit & satisfy
  3645. // these test for an URL shortener:
  3646. //
  3647. // http://mathiasbynens.be/demo/url-regex
  3648. //
  3649. // Notes on possible differences from a standard/generic validation:
  3650. //
  3651. // - utf-8 char class take in consideration the full Unicode range
  3652. // - TLDs have been made mandatory so single names like "localhost" fails
  3653. // - protocols have been restricted to ftp, http and https only as requested
  3654. //
  3655. // Changes:
  3656. //
  3657. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  3658. // first and last IP address of each class is considered invalid
  3659. // (since they are broadcast/network addresses)
  3660. //
  3661. // - Added exclusion of private, reserved and/or local networks ranges
  3662. //
  3663. // Compressed one-line versions:
  3664. //
  3665. // Javascript version
  3666. //
  3667. // /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/i
  3668. //
  3669. // PHP version
  3670. //
  3671. // _^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS
  3672. var urlExp = new RegExp(
  3673. "^" +
  3674. // protocol identifier
  3675. "(?:(?:https?|ftp)://)" +
  3676. // user:pass authentication
  3677. "(?:\\S+(?::\\S*)?@)?" +
  3678. "(?:" +
  3679. // IP address exclusion
  3680. // private & local networks
  3681. "(?!10(?:\\.\\d{1,3}){3})" +
  3682. "(?!127(?:\\.\\d{1,3}){3})" +
  3683. "(?!169\\.254(?:\\.\\d{1,3}){2})" +
  3684. "(?!192\\.168(?:\\.\\d{1,3}){2})" +
  3685. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
  3686. // IP address dotted notation octets
  3687. // excludes loopback network 0.0.0.0
  3688. // excludes reserved space >= 224.0.0.0
  3689. // excludes network & broadcast addresses
  3690. // (first & last IP address of each class)
  3691. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  3692. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  3693. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  3694. "|" +
  3695. // host name
  3696. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  3697. // domain name
  3698. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  3699. // TLD identifier
  3700. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  3701. ")" +
  3702. // port number
  3703. "(?::\\d{2,5})?" +
  3704. // resource path
  3705. "(?:/[^\\s]*)?" +
  3706. "$", "i"
  3707. );
  3708. return urlExp.test(value);
  3709. }
  3710. };
  3711. }(window.jQuery));
  3712. ;(function($) {
  3713. $.fn.bootstrapValidator.validators.uuid = {
  3714. html5Attributes: {
  3715. message: 'message',
  3716. version: 'version'
  3717. },
  3718. /**
  3719. * Return true if and only if the input value is a valid UUID string
  3720. *
  3721. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  3722. * @param {BootstrapValidator} validator The validator plugin instance
  3723. * @param {jQuery} $field Field element
  3724. * @param {Object} options Consist of key:
  3725. * - message: The invalid message
  3726. * - version: Can be 3, 4, 5, null
  3727. * @returns {Boolean}
  3728. */
  3729. validate: function(validator, $field, options) {
  3730. var value = $field.val();
  3731. if (value == '') {
  3732. return true;
  3733. }
  3734. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  3735. var patterns = {
  3736. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  3737. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  3738. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  3739. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  3740. },
  3741. version = options.version ? (options.version + '') : 'all';
  3742. return (null == patterns[version]) ? true : patterns[version].test(value);
  3743. }
  3744. };
  3745. }(window.jQuery));
  3746. ;(function($) {
  3747. $.fn.bootstrapValidator.validators.vat = {
  3748. html5Attributes: {
  3749. message: 'message',
  3750. country: 'country'
  3751. },
  3752. /**
  3753. * Validate an European VAT number
  3754. *
  3755. * @param {BootstrapValidator} validator The validator plugin instance
  3756. * @param {jQuery} $field Field element
  3757. * @param {Object} options Consist of key:
  3758. * - message: The invalid message
  3759. * - country: The ISO 3166-1 country code
  3760. * @returns {Boolean}
  3761. */
  3762. validate: function(validator, $field, options) {
  3763. var value = $field.val();
  3764. if (value == '') {
  3765. return true;
  3766. }
  3767. var country = options.country || value.substr(0, 2),
  3768. method = ['_', country.toLowerCase()].join('');
  3769. if (this[method] && 'function' == typeof this[method]) {
  3770. return this[method](value);
  3771. }
  3772. return true;
  3773. },
  3774. // VAT validators
  3775. /**
  3776. * Validate Austrian VAT number
  3777. * Example:
  3778. * - Valid: ATU13585627
  3779. * - Invalid: ATU13585626
  3780. *
  3781. * @param {String} value VAT number
  3782. * @returns {Boolean}
  3783. */
  3784. _at: function(value) {
  3785. if (!/^ATU[0-9]{8}$/.test(value)) {
  3786. return false;
  3787. }
  3788. value = value.substr(3);
  3789. var sum = 0,
  3790. weight = [1, 2, 1, 2, 1, 2, 1],
  3791. temp = 0;
  3792. for (var i = 0; i < 7; i++) {
  3793. temp = parseInt(value.charAt(i)) * weight[i];
  3794. if (temp > 9) {
  3795. temp = Math.floor(temp / 10) + temp % 10;
  3796. }
  3797. sum += temp;
  3798. }
  3799. sum = 10 - (sum + 4) % 10;
  3800. if (sum == 10) {
  3801. sum = 0;
  3802. }
  3803. return (sum == value.substr(7, 1));
  3804. },
  3805. /**
  3806. * Validate Belgian VAT number
  3807. * Example:
  3808. * - Valid: BE0428759497
  3809. * - Invalid: BE431150351
  3810. *
  3811. * @param {String} value VAT number
  3812. * @returns {Boolean}
  3813. */
  3814. _be: function(value) {
  3815. if (!/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  3816. return false;
  3817. }
  3818. value = value.substr(2);
  3819. if (value.length == 9) {
  3820. value = '0' + value;
  3821. }
  3822. if (value.substr(1, 1) == 0) {
  3823. return false;
  3824. }
  3825. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  3826. return (sum % 97 == 0);
  3827. },
  3828. /**
  3829. * Validate Bulgarian VAT number
  3830. * Example:
  3831. * - Valid: BG175074752,
  3832. * BG7523169263, BG8032056031,
  3833. * BG7542011030,
  3834. * BG7111042925
  3835. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  3836. *
  3837. * @param {String} value VAT number
  3838. * @returns {Boolean}
  3839. */
  3840. _bg: function(value) {
  3841. if (!/^BG[0-9]{9,10}$/.test(value)) {
  3842. return false;
  3843. }
  3844. value = value.substr(2);
  3845. var total = 0, sum = 0, weight = [], i = 0;
  3846. // Legal entities
  3847. if (value.length == 9) {
  3848. for (i = 0; i < 8; i++) {
  3849. sum += parseInt(value.charAt(i)) * (i + 1);
  3850. }
  3851. sum = sum % 11;
  3852. if (sum == 10) {
  3853. sum = 0;
  3854. for (i = 0; i < 8; i++) {
  3855. sum += parseInt(value.charAt(i)) * (i + 3);
  3856. }
  3857. }
  3858. sum = sum % 10;
  3859. return (sum == value.substr(8));
  3860. }
  3861. // Physical persons, foreigners and others
  3862. else if (value.length == 10) {
  3863. // Validate Bulgarian national identification numbers
  3864. var egn = function(value) {
  3865. // Check the birth date
  3866. var year = parseInt(value.substr(0, 2), 10) + 1900,
  3867. month = parseInt(value.substr(2, 2), 10),
  3868. day = parseInt(value.substr(4, 2), 10);
  3869. if (month > 40) {
  3870. year += 100;
  3871. month -= 40;
  3872. } else if (month > 20) {
  3873. year -= 100;
  3874. month -= 20;
  3875. }
  3876. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3877. return false;
  3878. }
  3879. var sum = 0,
  3880. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  3881. for (var i = 0; i < 9; i++) {
  3882. sum += parseInt(value.charAt(i)) * weight[i];
  3883. }
  3884. sum = (sum % 11) % 10;
  3885. return (sum == value.substr(9, 1));
  3886. },
  3887. // Validate Bulgarian personal number of a foreigner
  3888. pnf = function(value) {
  3889. var sum = 0,
  3890. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  3891. for (var i = 0; i < 9; i++) {
  3892. sum += parseInt(value.charAt(i)) * weight[i];
  3893. }
  3894. sum = sum % 10;
  3895. return (sum == value.substr(9, 1));
  3896. },
  3897. // Finally, consider it as a VAT number
  3898. vat = function(value) {
  3899. var sum = 0,
  3900. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  3901. for (var i = 0; i < 9; i++) {
  3902. sum += parseInt(value.charAt(i)) * weight[i];
  3903. }
  3904. sum = 11 - sum % 11;
  3905. if (sum == 10) {
  3906. return false;
  3907. }
  3908. if (sum == 11) {
  3909. sum = 0;
  3910. }
  3911. return (sum == value.substr(9, 1));
  3912. };
  3913. return (egn(value) || pnf(value) || vat(value));
  3914. }
  3915. return false;
  3916. },
  3917. /**
  3918. * Validate Swiss VAT number
  3919. *
  3920. * @param {String} value VAT number
  3921. * @returns {Boolean}
  3922. */
  3923. _ch: function(value) {
  3924. if (!/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  3925. return false;
  3926. }
  3927. value = value.substr(3);
  3928. var sum = 0,
  3929. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  3930. for (var i = 0; i < 8; i++) {
  3931. sum += parseInt(value.charAt(i), 10) * weight[i];
  3932. }
  3933. sum = 11 - sum % 11;
  3934. if (sum == 10) {
  3935. return false;
  3936. }
  3937. if (sum == 11) {
  3938. sum = 0;
  3939. }
  3940. return (sum == value.substr(8, 1));
  3941. },
  3942. /**
  3943. * Validate Cypriot VAT number
  3944. * Examples:
  3945. * - Valid: CY10259033P
  3946. * - Invalid: CY10259033Z
  3947. *
  3948. * @param {String} value VAT number
  3949. * @returns {Boolean}
  3950. */
  3951. _cy: function(value) {
  3952. if (!/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  3953. return false;
  3954. }
  3955. value = value.substr(2);
  3956. // Do not allow to start with "12"
  3957. if (value.substr(0, 2) == '12') {
  3958. return false;
  3959. }
  3960. // Extract the next digit and multiply by the counter.
  3961. var sum = 0,
  3962. translation = {
  3963. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  3964. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  3965. };
  3966. for (var i = 0; i < 8; i++) {
  3967. var temp = parseInt(value.charAt(i), 10);
  3968. if (i % 2 == 0) {
  3969. temp = translation[temp + ''];
  3970. }
  3971. sum += temp;
  3972. }
  3973. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  3974. return (sum == value.substr(8, 1));
  3975. },
  3976. /**
  3977. * Validate Czech Republic VAT number
  3978. * Can be:
  3979. * i) Legal entities (8 digit numbers)
  3980. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  3981. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  3982. *
  3983. * Examples:
  3984. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  3985. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  3986. *
  3987. * @param {String} value VAT number
  3988. * @returns {Boolean}
  3989. */
  3990. _cz: function(value) {
  3991. if (!/^CZ[0-9]{8,10}$/.test(value)) {
  3992. return false;
  3993. }
  3994. value = value.substr(2);
  3995. var sum = 0,
  3996. i = 0;
  3997. if (value.length == 8) {
  3998. // Do not allow to start with '9'
  3999. if (value.charAt(0) + '' == '9') {
  4000. return false;
  4001. }
  4002. sum = 0;
  4003. for (i = 0; i < 7; i++) {
  4004. sum += parseInt(value.charAt(i), 10) * (8 - i);
  4005. }
  4006. sum = 11 - sum % 11;
  4007. if (sum == 10) {
  4008. sum = 0;
  4009. }
  4010. if (sum == 11) {
  4011. sum = 1;
  4012. }
  4013. return (sum == value.substr(7, 1));
  4014. } else if (value.length == 9 && (value.charAt(0) + '' == '6')) {
  4015. sum = 0;
  4016. // Skip the first (which is 6)
  4017. for (i = 0; i < 7; i++) {
  4018. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  4019. }
  4020. sum = 11 - sum % 11;
  4021. if (sum == 10) {
  4022. sum = 0;
  4023. }
  4024. if (sum == 11) {
  4025. sum = 1;
  4026. }
  4027. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  4028. return (sum == value.substr(8, 1));
  4029. } else if (value.length == 9 || value.length == 10) {
  4030. // Validate Czech birth number (Rodné číslo), which is also national identifier
  4031. var year = 1900 + parseInt(value.substr(0, 2)),
  4032. month = parseInt(value.substr(2, 2)) % 50 % 20,
  4033. day = parseInt(value.substr(4, 2));
  4034. if (value.length == 9) {
  4035. if (year >= 1980) {
  4036. year -= 100;
  4037. }
  4038. if (year > 1953) {
  4039. return false;
  4040. }
  4041. } else if (year < 1954) {
  4042. year += 100;
  4043. }
  4044. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4045. return false;
  4046. }
  4047. // Check that the birth date is not in the future
  4048. if (value.length == 10) {
  4049. var check = parseInt(value.substr(0, 9), 10) % 11;
  4050. if (year < 1985) {
  4051. check = check % 10;
  4052. }
  4053. return (check == value.substr(9, 1));
  4054. }
  4055. return true;
  4056. }
  4057. return false;
  4058. },
  4059. /**
  4060. * Validate German VAT number
  4061. * Examples:
  4062. * - Valid: DE136695976
  4063. * - Invalid: DE136695978
  4064. *
  4065. * @param {String} value VAT number
  4066. * @returns {Boolean}
  4067. */
  4068. _de: function(value) {
  4069. if (!/^DE[0-9]{9}$/.test(value)) {
  4070. return false;
  4071. }
  4072. value = value.substr(2);
  4073. return $.fn.bootstrapValidator.helpers.mod_11_10(value);
  4074. },
  4075. /**
  4076. * Validate Danish VAT number
  4077. * Example:
  4078. * - Valid: DK13585628
  4079. * - Invalid: DK13585627
  4080. *
  4081. * @param {String} value VAT number
  4082. * @returns {Boolean}
  4083. */
  4084. _dk: function(value) {
  4085. if (!/^DK[0-9]{8}$/.test(value)) {
  4086. return false;
  4087. }
  4088. value = value.substr(2);
  4089. var sum = 0,
  4090. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  4091. for (var i = 0; i < 8; i++) {
  4092. sum += parseInt(value.charAt(i), 10) * weight[i];
  4093. }
  4094. return (sum % 11 == 0);
  4095. },
  4096. /**
  4097. * Validate Estonian VAT number
  4098. * Examples:
  4099. * - Valid: EE100931558, EE100594102
  4100. * - Invalid: EE100594103
  4101. *
  4102. * @param {String} value VAT number
  4103. * @returns {Boolean}
  4104. */
  4105. _ee: function(value) {
  4106. if (!/^EE[0-9]{9}$/.test(value)) {
  4107. return false;
  4108. }
  4109. value = value.substr(2);
  4110. var sum = 0,
  4111. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  4112. for (var i = 0; i < 9; i++) {
  4113. sum += parseInt(value.charAt(i)) * weight[i];
  4114. }
  4115. return (sum % 10 == 0);
  4116. },
  4117. /**
  4118. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  4119. * Can be:
  4120. * i) DNI (Documento nacional de identidad), for Spaniards
  4121. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  4122. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  4123. *
  4124. * Examples:
  4125. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  4126. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  4127. *
  4128. * @param {String} value VAT number
  4129. * @returns {Boolean}
  4130. */
  4131. _es: function(value) {
  4132. if (!/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  4133. return false;
  4134. }
  4135. value = value.substr(2);
  4136. var dni = function(value) {
  4137. var check = parseInt(value.substr(0, 8), 10);
  4138. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4139. return (check == value.substr(8, 1));
  4140. },
  4141. nie = function(value) {
  4142. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  4143. check = parseInt(check, 10);
  4144. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4145. return (check == value.substr(8, 1));
  4146. },
  4147. cif = function(value) {
  4148. var first = value.charAt(0), check;
  4149. if ('KLM'.indexOf(first) != -1) {
  4150. // K: Spanish younger than 14 year old
  4151. // L: Spanish living outside Spain without DNI
  4152. // M: Granted the tax to foreigners who have no NIE
  4153. check = parseInt(value.substr(1, 8), 10);
  4154. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4155. return (check == value.substr(8, 1));
  4156. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) != -1) {
  4157. var sum = 0,
  4158. weight = [2, 1, 2, 1, 2, 1, 2],
  4159. temp = 0;
  4160. for (var i = 0; i < 7; i++) {
  4161. temp = parseInt(value.charAt(i + 1)) * weight[i];
  4162. if (temp > 9) {
  4163. temp = Math.floor(temp / 10) + temp % 10;
  4164. }
  4165. sum += temp;
  4166. }
  4167. sum = 10 - sum % 10;
  4168. return (sum == value.substr(8, 1) || 'JABCDEFGHI'[sum] == value.substr(8, 1));
  4169. }
  4170. return false;
  4171. };
  4172. var first = value.charAt(0);
  4173. if (/^[0-9]$/.test(first)) {
  4174. return dni(value);
  4175. } else if (/^[XYZ]$/.test(first)) {
  4176. return nie(value);
  4177. } else {
  4178. return cif(value);
  4179. }
  4180. },
  4181. /**
  4182. * Validate Finnish VAT number
  4183. * Examples:
  4184. * - Valid: FI20774740
  4185. * - Invalid: FI20774741
  4186. *
  4187. * @param {String} value VAT number
  4188. * @returns {Boolean}
  4189. */
  4190. _fi: function(value) {
  4191. if (!/^FI[0-9]{8}$/.test(value)) {
  4192. return false;
  4193. }
  4194. value = value.substr(2);
  4195. var sum = 0,
  4196. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  4197. for (var i = 0; i < 8; i++) {
  4198. sum += parseInt(value.charAt(i)) * weight[i];
  4199. }
  4200. return (sum % 11 == 0);
  4201. },
  4202. /**
  4203. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  4204. * It's constructed by a SIREN number, prefixed by two characters.
  4205. *
  4206. * Examples:
  4207. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  4208. * - Invalid: FR84323140391
  4209. *
  4210. * @param {String} value VAT number
  4211. * @returns {Boolean}
  4212. */
  4213. _fr: function(value) {
  4214. if (!/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  4215. return false;
  4216. }
  4217. value = value.substr(2);
  4218. if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
  4219. return false;
  4220. }
  4221. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  4222. // First two characters are digits
  4223. return value.substr(0, 2) == (parseInt(value.substr(2) + '12', 10) % 97);
  4224. } else {
  4225. // The first characters cann't be O and I
  4226. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  4227. check;
  4228. // First one is digit
  4229. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  4230. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  4231. } else {
  4232. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  4233. }
  4234. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) == (check % 11);
  4235. }
  4236. },
  4237. /**
  4238. * Validate United Kingdom VAT number
  4239. * Example:
  4240. * - Valid: GB980780684
  4241. * - Invalid: GB802311781
  4242. *
  4243. * @param {String} value VAT number
  4244. * @returns {Boolean}
  4245. */
  4246. _gb: function(value) {
  4247. if (!/^GB[0-9]{9}$/.test(value) // Standard
  4248. && !/^GB[0-9]{12}$/.test(value) // Branches
  4249. && !/^GBGD[0-9]{3}$/.test(value) // Government department
  4250. && !/^GBHA[0-9]{3}$/.test(value) // Health authority
  4251. && !/^GB(GD|HA)8888[0-9]{5}$/.test(value))
  4252. {
  4253. return false;
  4254. }
  4255. value = value.substr(2);
  4256. var length = value.length;
  4257. if (length == 5) {
  4258. var firstTwo = value.substr(0, 2),
  4259. lastThree = parseInt(value.substr(2));
  4260. return ('GD' == firstTwo && lastThree < 500) || ('HA' == firstTwo && lastThree >= 500);
  4261. } else if (length == 11 && ('GD8888' == value.substr(0, 6) || 'HA8888' == value.substr(0, 6))) {
  4262. if (('GD' == value.substr(0, 2) && parseInt(value.substr(6, 3)) >= 500)
  4263. || ('HA' == value.substr(0, 2) && parseInt(value.substr(6, 3)) < 500))
  4264. {
  4265. return false;
  4266. }
  4267. return (parseInt(value.substr(6, 3)) % 97 == parseInt(value.substr(9, 2)));
  4268. } else if (length == 9 || length == 12) {
  4269. var sum = 0,
  4270. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  4271. for (var i = 0; i < 9; i++) {
  4272. sum += parseInt(value.charAt(i)) * weight[i];
  4273. }
  4274. sum = sum % 97;
  4275. if (parseInt(value.substr(0, 3)) >= 100) {
  4276. return (sum == 0 || sum == 42 || sum == 55);
  4277. } else {
  4278. return (sum == 0);
  4279. }
  4280. }
  4281. return true;
  4282. },
  4283. /**
  4284. * Validate Greek VAT number
  4285. * Examples:
  4286. * - Valid: GR023456780, EL094259216
  4287. * - Invalid: EL123456781
  4288. *
  4289. * @param {String} value VAT number
  4290. * @returns {Boolean}
  4291. */
  4292. _gr: function(value) {
  4293. if (!/^GR[0-9]{9}$/.test(value)) {
  4294. return false;
  4295. }
  4296. value = value.substr(2);
  4297. if (value.length == 8) {
  4298. value = '0' + value;
  4299. }
  4300. var sum = 0,
  4301. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  4302. for (var i = 0; i < 8; i++) {
  4303. sum += parseInt(value.charAt(i)) * weight[i];
  4304. }
  4305. sum = (sum % 11) % 10;
  4306. return (sum == value.substr(8, 1));
  4307. },
  4308. // EL is traditionally prefix of Greek VAT numbers
  4309. _el: function(value) {
  4310. if (!/^EL[0-9]{9}$/.test(value)) {
  4311. return false;
  4312. }
  4313. value = 'GR' + value.substr(2);
  4314. return this._gr(value);
  4315. },
  4316. /**
  4317. * Validate Hungarian VAT number
  4318. * Examples:
  4319. * - Valid: HU12892312
  4320. * - Invalid: HU12892313
  4321. *
  4322. * @param {String} value VAT number
  4323. * @returns {Boolean}
  4324. */
  4325. _hu: function(value) {
  4326. if (!/^HU[0-9]{8}$/.test(value)) {
  4327. return false;
  4328. }
  4329. value = value.substr(2);
  4330. var sum = 0,
  4331. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  4332. for (var i = 0; i < 8; i++) {
  4333. sum += parseInt(value.charAt(i)) * weight[i];
  4334. }
  4335. return (sum % 10 == 0);
  4336. },
  4337. /**
  4338. * Validate Croatian VAT number
  4339. * Examples:
  4340. * - Valid: HR33392005961
  4341. * - Invalid: HR33392005962
  4342. *
  4343. * @param {String} value VAT number
  4344. * @returns {Boolean}
  4345. */
  4346. _hr: function(value) {
  4347. if (!/^HR[0-9]{11}$/.test(value)) {
  4348. return false;
  4349. }
  4350. value = value.substr(2);
  4351. return $.fn.bootstrapValidator.helpers.mod_11_10(value);
  4352. },
  4353. /**
  4354. * Validate Irish VAT number
  4355. * Examples:
  4356. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  4357. * - Invalid: IE8D79738J
  4358. *
  4359. * @param {String} value VAT number
  4360. * @returns {Boolean}
  4361. */
  4362. _ie: function(value) {
  4363. if (!/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  4364. return false;
  4365. }
  4366. value = value.substr(2);
  4367. var getCheckDigit = function(value) {
  4368. while (value.length < 7) {
  4369. value = '0' + value;
  4370. }
  4371. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  4372. sum = 0;
  4373. for (var i = 0; i < 7; i++) {
  4374. sum += parseInt(value.charAt(i)) * (8 - i);
  4375. }
  4376. sum += 9 * alphabet.indexOf(value.substr(7));
  4377. return alphabet[sum % 23];
  4378. };
  4379. // The first 7 characters are digits
  4380. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  4381. // New system
  4382. return value.charAt(7) == getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  4383. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) != -1) {
  4384. // Old system
  4385. return value.charAt(7) == getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  4386. }
  4387. return true;
  4388. },
  4389. /**
  4390. * Validate Italian VAT number, which consists of 11 digits.
  4391. * - First 7 digits are a company identifier
  4392. * - Next 3 are the province of residence
  4393. * - The last one is a check digit
  4394. *
  4395. * Examples:
  4396. * - Valid: IT00743110157
  4397. * - Invalid: IT00743110158
  4398. *
  4399. * @param {String} value VAT number
  4400. * @returns {Boolean}
  4401. */
  4402. _it: function(value) {
  4403. if (!/^IT[0-9]{11}$/.test(value)) {
  4404. return false;
  4405. }
  4406. value = value.substr(2);
  4407. if (parseInt(value.substr(0, 7)) == 0) {
  4408. return false;
  4409. }
  4410. var lastThree = parseInt(value.substr(7, 3));
  4411. if ((lastThree < 1) || (lastThree > 201) && lastThree != 999 && lastThree != 888) {
  4412. return false;
  4413. }
  4414. return $.fn.bootstrapValidator.helpers.luhn(value);
  4415. },
  4416. /**
  4417. * Validate Lithuanian VAT number
  4418. * It can be:
  4419. * - 9 digits, for legal entities
  4420. * - 12 digits, for temporarily registered taxpayers
  4421. *
  4422. * Examples:
  4423. * - Valid: LT119511515, LT100001919017, LT100004801610
  4424. * - Invalid: LT100001919018
  4425. *
  4426. * @param {String} value VAT number
  4427. * @returns {Boolean}
  4428. */
  4429. _lt: function(value) {
  4430. if (!/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  4431. return false;
  4432. }
  4433. value = value.substr(2);
  4434. var length = value.length,
  4435. sum = 0;
  4436. for (var i = 0; i < length - 1; i++) {
  4437. sum += parseInt(value.charAt(i)) * (1 + i % 9);
  4438. }
  4439. var check = sum % 11;
  4440. if (check == 10) {
  4441. sum = 0;
  4442. for (var i = 0; i < length - 1; i++) {
  4443. sum += parseInt(value.charAt(i)) * (1 + (i + 2) % 9);
  4444. }
  4445. }
  4446. check = check % 11 % 10;
  4447. return (check == value.charAt(length - 1));
  4448. },
  4449. /**
  4450. * Validate Luxembourg VAT number
  4451. * Examples:
  4452. * - Valid: LU15027442
  4453. * - Invalid: LU15027443
  4454. *
  4455. * @param {String} value VAT number
  4456. * @returns {Boolean}
  4457. */
  4458. _lu: function(value) {
  4459. if (!/^LU[0-9]{8}$/.test(value)) {
  4460. return false;
  4461. }
  4462. value = value.substr(2);
  4463. return (value.substr(0, 6) % 89 == value.substr(6, 2));
  4464. },
  4465. /**
  4466. * Validate Latvian VAT number
  4467. * Examples:
  4468. * - Valid: LV40003521600, LV16117519997
  4469. * - Invalid: LV40003521601, LV16137519997
  4470. *
  4471. * @param {String} value VAT number
  4472. * @returns {Boolean}
  4473. */
  4474. _lv: function(value) {
  4475. if (!/^LV[0-9]{11}$/.test(value)) {
  4476. return false;
  4477. }
  4478. value = value.substr(2);
  4479. var first = parseInt(value.charAt(0)),
  4480. sum = 0,
  4481. weight = [],
  4482. i = 0,
  4483. length = value.length;
  4484. if (first > 3) {
  4485. // Legal entity
  4486. sum = 0;
  4487. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  4488. for (i = 0; i < length; i++) {
  4489. sum += parseInt(value.charAt(i)) * weight[i];
  4490. }
  4491. sum = sum % 11;
  4492. return (sum == 3);
  4493. } else {
  4494. // Check birth date
  4495. var day = parseInt(value.substr(0, 2)),
  4496. month = parseInt(value.substr(2, 2)),
  4497. year = parseInt(value.substr(4, 2));
  4498. year = year + 1800 + parseInt(value.charAt(6)) * 100;
  4499. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4500. return false;
  4501. }
  4502. // Check personal code
  4503. sum = 0;
  4504. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  4505. for (i = 0; i < length - 1; i++) {
  4506. sum += parseInt(value.charAt(i)) * weight[i];
  4507. }
  4508. sum = (sum + 1) % 11 % 10;
  4509. return (sum == value.charAt(length - 1));
  4510. }
  4511. return true;
  4512. },
  4513. /**
  4514. * Validate Maltese VAT number
  4515. * Examples:
  4516. * - Valid: MT11679112
  4517. * - Invalid: MT11679113
  4518. *
  4519. * @param {String} value VAT number
  4520. * @returns {Boolean}
  4521. */
  4522. _mt: function(value) {
  4523. if (!/^MT[0-9]{8}$/.test(value)) {
  4524. return false;
  4525. }
  4526. value = value.substr(2);
  4527. var sum = 0,
  4528. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  4529. for (var i = 0; i < 8; i++) {
  4530. sum += parseInt(value.charAt(i)) * weight[i];
  4531. }
  4532. return (sum % 37 == 0);
  4533. },
  4534. /**
  4535. * Validate Dutch VAT number
  4536. * Examples:
  4537. * - Valid: NL004495445B01
  4538. * - Invalid: NL123456789B90
  4539. *
  4540. * @param {String} value VAT number
  4541. * @returns {Boolean}
  4542. */
  4543. _nl: function(value) {
  4544. if (!/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  4545. return false;
  4546. }
  4547. value = value.substr(2);
  4548. var sum = 0,
  4549. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  4550. for (var i = 0; i < 8; i++) {
  4551. sum += parseInt(value.charAt(i)) * weight[i];
  4552. }
  4553. sum = sum % 11;
  4554. if (sum > 9) {
  4555. sum = 0;
  4556. }
  4557. return (sum == value.substr(8, 1));
  4558. },
  4559. /**
  4560. * Validate Norwegian VAT number
  4561. *
  4562. * @see http://www.brreg.no/english/coordination/number.html
  4563. * @param {String} value VAT number
  4564. * @returns {Boolean}
  4565. */
  4566. _no: function(value) {
  4567. if (!/^NO[0-9]{9}$/.test(value)) {
  4568. return false;
  4569. }
  4570. value = value.substr(2);
  4571. var sum = 0,
  4572. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  4573. for (var i = 0; i < 8; i++) {
  4574. sum += parseInt(value.charAt(i)) * weight[i];
  4575. }
  4576. sum = 11 - sum % 11;
  4577. if (sum == 11) {
  4578. sum = 0;
  4579. }
  4580. return (sum == value.substr(8, 1));
  4581. },
  4582. /**
  4583. * Validate Polish VAT number
  4584. * Examples:
  4585. * - Valid: PL8567346215
  4586. * - Invalid: PL8567346216
  4587. *
  4588. * @param {String} value VAT number
  4589. * @returns {Boolean}
  4590. */
  4591. _pl: function(value) {
  4592. if (!/^PL[0-9]{10}$/.test(value)) {
  4593. return false;
  4594. }
  4595. value = value.substr(2);
  4596. var sum = 0,
  4597. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  4598. for (var i = 0; i < 10; i++) {
  4599. sum += parseInt(value.charAt(i)) * weight[i];
  4600. }
  4601. return (sum % 11 == 0);
  4602. },
  4603. /**
  4604. * Validate Portuguese VAT number
  4605. * Examples:
  4606. * - Valid: PT501964843
  4607. * - Invalid: PT501964842
  4608. *
  4609. * @param {String} value VAT number
  4610. * @returns {Boolean}
  4611. */
  4612. _pt: function(value) {
  4613. if (!/^PT[0-9]{9}$/.test(value)) {
  4614. return false;
  4615. }
  4616. value = value.substr(2);
  4617. var sum = 0,
  4618. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  4619. for (var i = 0; i < 8; i++) {
  4620. sum += parseInt(value.charAt(i)) * weight[i];
  4621. }
  4622. sum = 11 - sum % 11;
  4623. if (sum > 9) {
  4624. sum = 0;
  4625. }
  4626. return (sum == value.substr(8, 1));
  4627. },
  4628. /**
  4629. * Validate Romanian VAT number
  4630. * Examples:
  4631. * - Valid: RO18547290
  4632. * - Invalid: RO18547291
  4633. *
  4634. * @param {String} value VAT number
  4635. * @returns {Boolean}
  4636. */
  4637. _ro: function(value) {
  4638. if (!/^RO[1-9][0-9]{1,9}$/.test(value)) {
  4639. return false;
  4640. }
  4641. value = value.substr(2);
  4642. var length = value.length,
  4643. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  4644. sum = 0;
  4645. for (var i = 0; i < length - 1; i++) {
  4646. sum += parseInt(value.charAt(i)) * weight[i];
  4647. }
  4648. sum = (10 * sum) % 11 % 10;
  4649. return (sum == value.substr(length - 1, 1));
  4650. },
  4651. /**
  4652. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  4653. *
  4654. * @param {String} value VAT number
  4655. * @returns {Boolean}
  4656. */
  4657. _ru: function(value) {
  4658. if (!/^RU([0-9]{9}|[0-9]{12})$/.test(value)) {
  4659. return false;
  4660. }
  4661. value = value.substr(2);
  4662. if (value.length == 10) {
  4663. var sum = 0,
  4664. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  4665. for (var i = 0; i < 10; i++) {
  4666. sum += parseInt(value.charAt(i)) * weight[i];
  4667. }
  4668. sum = sum % 11;
  4669. if (sum > 9) {
  4670. sum = sum % 10;
  4671. }
  4672. return (sum == value.substr(9, 1));
  4673. } else if (value.length == 12) {
  4674. var sum1 = 0,
  4675. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  4676. sum2 = 0,
  4677. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  4678. for (var i = 0; i < 11; i++) {
  4679. sum1 += parseInt(value.charAt(i)) * weight1[i];
  4680. sum2 += parseInt(value.charAt(i)) * weight2[i];
  4681. }
  4682. sum1 = sum1 % 11;
  4683. if (sum1 > 9) {
  4684. sum1 = sum1 % 10;
  4685. }
  4686. sum2 = sum2 % 11;
  4687. if (sum2 > 9) {
  4688. sum2 = sum2 % 10;
  4689. }
  4690. return (sum1 == value.substr(10, 1) && sum2 == value.substr(11, 1));
  4691. }
  4692. return false;
  4693. },
  4694. /**
  4695. * Validate Serbian VAT number
  4696. *
  4697. * @param {String} value VAT number
  4698. * @returns {Boolean}
  4699. */
  4700. _rs: function(value) {
  4701. if (!/^RS[0-9]{9}$/.test(value)) {
  4702. return false;
  4703. }
  4704. value = value.substr(2);
  4705. var sum = 10,
  4706. temp = 0;
  4707. for (var i = 0; i < 8; i++) {
  4708. temp = (parseInt(value.charAt(i)) + sum) % 10;
  4709. if (temp == 0) {
  4710. temp = 10;
  4711. }
  4712. sum = (2 * temp) % 11;
  4713. }
  4714. return ((sum + parseInt(value.substr(8, 1))) % 10 == 1);
  4715. },
  4716. /**
  4717. * Validate Swedish VAT number
  4718. * Examples:
  4719. * - Valid: SE123456789701
  4720. * - Invalid: SE123456789101
  4721. *
  4722. * @param {String} value VAT number
  4723. * @returns {Boolean}
  4724. */
  4725. _se: function(value) {
  4726. if (!/^SE[0-9]{10}01$/.test(value)) {
  4727. return false;
  4728. }
  4729. value = value.substr(2, 10);
  4730. return $.fn.bootstrapValidator.helpers.luhn(value);
  4731. },
  4732. /**
  4733. * Validate Slovenian VAT number
  4734. * Examples:
  4735. * - Valid: SI50223054
  4736. * - Invalid: SI50223055
  4737. *
  4738. * @param {String} value VAT number
  4739. * @returns {Boolean}
  4740. */
  4741. _si: function(value) {
  4742. if (!/^SI[0-9]{8}$/.test(value)) {
  4743. return false;
  4744. }
  4745. value = value.substr(2);
  4746. var sum = 0,
  4747. weight = [8, 7, 6, 5, 4, 3, 2];
  4748. for (var i = 0; i < 7; i++) {
  4749. sum += parseInt(value.charAt(i)) * weight[i];
  4750. }
  4751. sum = 11 - sum % 11;
  4752. if (sum == 10) {
  4753. sum = 0;
  4754. }
  4755. return (sum == value.substr(7, 1));
  4756. },
  4757. /**
  4758. * Validate Slovak VAT number
  4759. * Examples:
  4760. * - Valid: SK2022749619
  4761. * - Invalid: SK2022749618
  4762. *
  4763. * @param {String} value VAT number
  4764. * @returns {Boolean}
  4765. */
  4766. _sk: function(value) {
  4767. if (!/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  4768. return false;
  4769. }
  4770. value = value.substr(2);
  4771. return (value % 11 == 0);
  4772. }
  4773. };
  4774. }(window.jQuery));
  4775. ;(function($) {
  4776. $.fn.bootstrapValidator.validators.vin = {
  4777. /**
  4778. * Validate an US VIN (Vehicle Identification Number)
  4779. *
  4780. * @param {BootstrapValidator} validator The validator plugin instance
  4781. * @param {jQuery} $field Field element
  4782. * @param {Object} options Consist of key:
  4783. * - message: The invalid message
  4784. * @returns {Boolean}
  4785. */
  4786. validate: function(validator, $field, options) {
  4787. var value = $field.val();
  4788. if (value == '') {
  4789. return true;
  4790. }
  4791. // Don't accept I, O, Q characters
  4792. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  4793. return false;
  4794. }
  4795. value = value.toUpperCase();
  4796. var chars = {
  4797. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  4798. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  4799. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  4800. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  4801. },
  4802. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  4803. sum = 0,
  4804. length = value.length;
  4805. for (var i = 0; i < length; i++) {
  4806. sum += chars[value.charAt(i) + ''] * weights[i];
  4807. }
  4808. var reminder = sum % 11;
  4809. if (reminder == 10) {
  4810. reminder = 'X';
  4811. }
  4812. return reminder == value.charAt(8);
  4813. }
  4814. };
  4815. }(window.jQuery));
  4816. ;(function($) {
  4817. $.fn.bootstrapValidator.validators.zipCode = {
  4818. html5Attributes: {
  4819. message: 'message',
  4820. country: 'country'
  4821. },
  4822. /**
  4823. * Return true if and only if the input value is a valid country zip code
  4824. *
  4825. * @param {BootstrapValidator} validator The validator plugin instance
  4826. * @param {jQuery} $field Field element
  4827. * @param {Object} options Consist of key:
  4828. * - message: The invalid message
  4829. * - country: The ISO 3166 country code
  4830. *
  4831. * Currently it supports the following countries:
  4832. * - US (United State)
  4833. * - CA (Canada)
  4834. * - DK (Denmark)
  4835. * - GB (United Kingdom)
  4836. * - IT (Italy)
  4837. * - NL (Netherlands)
  4838. * - SE (Sweden)
  4839. * @returns {Boolean}
  4840. */
  4841. validate: function(validator, $field, options) {
  4842. var value = $field.val();
  4843. if (value == '' || !options.country) {
  4844. return true;
  4845. }
  4846. var country = (options.country || 'US').toUpperCase();
  4847. switch (country) {
  4848. case 'CA': return /(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}\s?[0-9]{1}(?:A|B|C|E|G|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}/i.test(value);
  4849. case 'DK': return /^(DK(-|\s)?)?\d{4}$/i.test(value);
  4850. case 'GB': return this._gb(value);
  4851. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  4852. case 'IT': return /^(I-|IT-)?\d{5}$/i.test(value);
  4853. // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  4854. case 'NL': return /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  4855. case 'SE': return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  4856. case 'US':
  4857. default: return /^\d{4,5}([\-]\d{4})?$/.test(value);
  4858. }
  4859. },
  4860. /**
  4861. * Validate United Kingdom postcode
  4862. * Examples:
  4863. * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  4864. * - Special cases:
  4865. * AI-2640, ASCN 1ZZ, GIR 0AA
  4866. *
  4867. * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  4868. * @param {String} value The postcode
  4869. * @returns {Boolean}
  4870. */
  4871. _gb: function(value) {
  4872. var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
  4873. secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
  4874. thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
  4875. fourthChar = '[ABEHMNPRVWXY]',
  4876. fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
  4877. regexps = [
  4878. // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  4879. new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  4880. // ANA NAA
  4881. new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  4882. // AANA NAA
  4883. new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  4884. new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
  4885. /^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
  4886. /^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
  4887. /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
  4888. /^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
  4889. /^(AI-2640)$/i // Anguilla
  4890. ];
  4891. for (var i = 0; i < regexps.length; i++) {
  4892. if (regexps[i].test(value)) {
  4893. return true;
  4894. }
  4895. }
  4896. return false;
  4897. }
  4898. };
  4899. }(window.jQuery));