bootstrapValidator.js 258 KB

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