bootstrapValidator.js 315 KB

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