bootstrapValidator.js 312 KB

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