bootstrapValidator.js 250 KB

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