bootstrapValidator.js 318 KB

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