bootstrapValidator.js 182 KB

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