bootstrapValidator.js 231 KB

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