bootstrapValidator.js 254 KB

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