bootstrapValidator.js 265 KB

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