bootstrapValidator.js 305 KB

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