bootstrapValidator.js 230 KB

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