bootstrapValidator.js 211 KB

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