bootstrapValidator.js 236 KB

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