bootstrapValidator.js 308 KB

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