bootstrapValidator.js 317 KB

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