bootstrapValidator.js 234 KB

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