bootstrapValidator.js 311 KB

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