bootstrapValidator.js 298 KB

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