bootstrapValidator.js 258 KB

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