bootstrapValidator.js 265 KB

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