bootstrapValidator.js 299 KB

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