bootstrapValidator.js 262 KB

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