bootstrapValidator.js 312 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100
  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:33:17 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. value = value.replace(',', '.');
  1808. if (!$.isNumeric(value)) {
  1809. return false;
  1810. }
  1811. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  1812. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max);
  1813. value = parseFloat(value);
  1814. return (options.inclusive === true || options.inclusive === undefined)
  1815. ? {
  1816. valid: value >= min && value <= max,
  1817. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between['default'], [min, max])
  1818. }
  1819. : {
  1820. valid: value > min && value < max,
  1821. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between.notInclusive, [min, max])
  1822. };
  1823. }
  1824. };
  1825. }(window.jQuery));
  1826. ;(function($) {
  1827. $.fn.bootstrapValidator.validators.blank = {
  1828. /**
  1829. * Placeholder validator that can be used to display a custom validation message
  1830. * returned from the server
  1831. * Example:
  1832. *
  1833. * (1) a "blank" validator is applied to an input field.
  1834. * (2) data is entered via the UI that is unable to be validated client-side.
  1835. * (3) server returns a 400 with JSON data that contains the field that failed
  1836. * validation and an associated message.
  1837. * (4) ajax 400 call handler does the following:
  1838. *
  1839. * bv.updateMessage(field, 'blank', errorMessage);
  1840. * bv.updateStatus(field, 'INVALID');
  1841. *
  1842. * @see https://github.com/nghuuphuoc/bootstrapvalidator/issues/542
  1843. * @see https://github.com/nghuuphuoc/bootstrapvalidator/pull/666
  1844. * @param {BootstrapValidator} validator The validator plugin instance
  1845. * @param {jQuery} $field Field element
  1846. * @param {Object} options Can consist of the following keys:
  1847. * - message: The invalid message
  1848. * @returns {Boolean}
  1849. */
  1850. validate: function(validator, $field, options) {
  1851. return true;
  1852. }
  1853. };
  1854. }(window.jQuery));
  1855. ;(function($) {
  1856. $.fn.bootstrapValidator.i18n.callback = $.extend($.fn.bootstrapValidator.i18n.callback || {}, {
  1857. 'default': 'Please enter a valid value'
  1858. });
  1859. $.fn.bootstrapValidator.validators.callback = {
  1860. html5Attributes: {
  1861. message: 'message',
  1862. callback: 'callback'
  1863. },
  1864. /**
  1865. * Return result from the callback method
  1866. *
  1867. * @param {BootstrapValidator} validator The validator plugin instance
  1868. * @param {jQuery} $field Field element
  1869. * @param {Object} options Can consist of the following keys:
  1870. * - callback: The callback method that passes 2 parameters:
  1871. * callback: function(fieldValue, validator, $field) {
  1872. * // fieldValue is the value of field
  1873. * // validator is instance of BootstrapValidator
  1874. * // $field is the field element
  1875. * }
  1876. * - message: The invalid message
  1877. * @returns {Deferred}
  1878. */
  1879. validate: function(validator, $field, options) {
  1880. var value = $field.val(),
  1881. dfd = new $.Deferred(),
  1882. result = { valid: true };
  1883. if (options.callback) {
  1884. var response = $.fn.bootstrapValidator.helpers.call(options.callback, [value, validator, $field]);
  1885. result = ('boolean' === typeof response) ? { valid: response } : response;
  1886. }
  1887. dfd.resolve($field, 'callback', result);
  1888. return dfd;
  1889. }
  1890. };
  1891. }(window.jQuery));
  1892. ;(function($) {
  1893. $.fn.bootstrapValidator.i18n.choice = $.extend($.fn.bootstrapValidator.i18n.choice || {}, {
  1894. 'default': 'Please enter a valid value',
  1895. less: 'Please choose %s options at minimum',
  1896. more: 'Please choose %s options at maximum',
  1897. between: 'Please choose %s - %s options'
  1898. });
  1899. $.fn.bootstrapValidator.validators.choice = {
  1900. html5Attributes: {
  1901. message: 'message',
  1902. min: 'min',
  1903. max: 'max'
  1904. },
  1905. /**
  1906. * Check if the number of checked boxes are less or more than a given number
  1907. *
  1908. * @param {BootstrapValidator} validator The validator plugin instance
  1909. * @param {jQuery} $field Field element
  1910. * @param {Object} options Consists of following keys:
  1911. * - min
  1912. * - max
  1913. *
  1914. * At least one of two keys is required
  1915. * The min, max keys define the number which the field value compares to. min, max can be
  1916. * - A number
  1917. * - Name of field which its value defines the number
  1918. * - Name of callback function that returns the number
  1919. * - A callback function that returns the number
  1920. *
  1921. * - message: The invalid message
  1922. * @returns {Object}
  1923. */
  1924. validate: function(validator, $field, options) {
  1925. var numChoices = $field.is('select')
  1926. ? validator.getFieldElements($field.attr('data-bv-field')).find('option').filter(':selected').length
  1927. : validator.getFieldElements($field.attr('data-bv-field')).filter(':checked').length,
  1928. min = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min)) : null,
  1929. max = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max)) : null,
  1930. isValid = true,
  1931. message = options.message || $.fn.bootstrapValidator.i18n.choice['default'];
  1932. if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
  1933. isValid = false;
  1934. }
  1935. switch (true) {
  1936. case (!!min && !!max):
  1937. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.between, [parseInt(min, 10), parseInt(max, 10)]);
  1938. break;
  1939. case (!!min):
  1940. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.less, parseInt(min, 10));
  1941. break;
  1942. case (!!max):
  1943. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.more, parseInt(max, 10));
  1944. break;
  1945. default:
  1946. break;
  1947. }
  1948. return { valid: isValid, message: message };
  1949. }
  1950. };
  1951. }(window.jQuery));
  1952. ;(function($) {
  1953. $.fn.bootstrapValidator.i18n.color = $.extend($.fn.bootstrapValidator.i18n.color || {}, {
  1954. 'default': 'Please enter a valid color'
  1955. });
  1956. $.fn.bootstrapValidator.validators.color = {
  1957. SUPPORTED_TYPES: [
  1958. 'hex', 'rgb', 'rgba', 'hsl', 'hsla', 'keyword'
  1959. ],
  1960. KEYWORD_COLORS: [
  1961. // Colors start with A
  1962. 'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',
  1963. // B
  1964. 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood',
  1965. // C
  1966. 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan',
  1967. // D
  1968. 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta',
  1969. 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue',
  1970. 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray',
  1971. 'dimgrey', 'dodgerblue',
  1972. // F
  1973. 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia',
  1974. // G
  1975. 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey',
  1976. // H
  1977. 'honeydew', 'hotpink',
  1978. // I
  1979. 'indianred', 'indigo', 'ivory',
  1980. // K
  1981. 'khaki',
  1982. // L
  1983. 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan',
  1984. 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen',
  1985. 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen',
  1986. 'linen',
  1987. // M
  1988. 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen',
  1989. 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream',
  1990. 'mistyrose', 'moccasin',
  1991. // N
  1992. 'navajowhite', 'navy',
  1993. // O
  1994. 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid',
  1995. // P
  1996. 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink',
  1997. 'plum', 'powderblue', 'purple',
  1998. // R
  1999. 'red', 'rosybrown', 'royalblue',
  2000. // S
  2001. 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue',
  2002. 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue',
  2003. // T
  2004. 'tan', 'teal', 'thistle', 'tomato', 'transparent', 'turquoise',
  2005. // V
  2006. 'violet',
  2007. // W
  2008. 'wheat', 'white', 'whitesmoke',
  2009. // Y
  2010. 'yellow', 'yellowgreen'
  2011. ],
  2012. /**
  2013. * Return true if the input value is a valid color
  2014. *
  2015. * @param {BootstrapValidator} validator The validator plugin instance
  2016. * @param {jQuery} $field Field element
  2017. * @param {Object} options Can consist of the following keys:
  2018. * - message: The invalid message
  2019. * - type: The array of valid color types
  2020. * @returns {Boolean}
  2021. */
  2022. validate: function(validator, $field, options) {
  2023. var value = $field.val();
  2024. if (value === '') {
  2025. return true;
  2026. }
  2027. var types = options.type || this.SUPPORTED_TYPES;
  2028. if (!$.isArray(types)) {
  2029. types = types.replace(/s/g, '').split(',');
  2030. }
  2031. var method,
  2032. type,
  2033. isValid = false;
  2034. for (var i = 0; i < types.length; i++) {
  2035. type = types[i];
  2036. method = '_' + type.toLowerCase();
  2037. isValid = isValid || this[method](value);
  2038. if (isValid) {
  2039. return true;
  2040. }
  2041. }
  2042. return false;
  2043. },
  2044. _hex: function(value) {
  2045. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2046. },
  2047. _hsl: function(value) {
  2048. return /^hsl\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/.test(value);
  2049. },
  2050. _hsla: function(value) {
  2051. return /^hsla\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/.test(value);
  2052. },
  2053. _keyword: function(value) {
  2054. return $.inArray(value, this.KEYWORD_COLORS) >= 0;
  2055. },
  2056. _rgb: function(value) {
  2057. var regexInteger = /^rgb\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){2}(\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*)\)$/,
  2058. regexPercent = /^rgb\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/;
  2059. return regexInteger.test(value) || regexPercent.test(value);
  2060. },
  2061. _rgba: function(value) {
  2062. var regexInteger = /^rgba\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/,
  2063. regexPercent = /^rgba\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/;
  2064. return regexInteger.test(value) || regexPercent.test(value);
  2065. }
  2066. };
  2067. }(window.jQuery));
  2068. ;(function($) {
  2069. $.fn.bootstrapValidator.i18n.creditCard = $.extend($.fn.bootstrapValidator.i18n.creditCard || {}, {
  2070. 'default': 'Please enter a valid credit card number'
  2071. });
  2072. $.fn.bootstrapValidator.validators.creditCard = {
  2073. /**
  2074. * Return true if the input value is valid credit card number
  2075. * Based on https://gist.github.com/DiegoSalazar/4075533
  2076. *
  2077. * @param {BootstrapValidator} validator The validator plugin instance
  2078. * @param {jQuery} $field Field element
  2079. * @param {Object} [options] Can consist of the following key:
  2080. * - message: The invalid message
  2081. * @returns {Boolean}
  2082. */
  2083. validate: function(validator, $field, options) {
  2084. var value = $field.val();
  2085. if (value === '') {
  2086. return true;
  2087. }
  2088. // Accept only digits, dashes or spaces
  2089. if (/[^0-9-\s]+/.test(value)) {
  2090. return false;
  2091. }
  2092. value = value.replace(/\D/g, '');
  2093. if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
  2094. return false;
  2095. }
  2096. // Validate the card number based on prefix (IIN ranges) and length
  2097. var cards = {
  2098. AMERICAN_EXPRESS: {
  2099. length: [15],
  2100. prefix: ['34', '37']
  2101. },
  2102. DINERS_CLUB: {
  2103. length: [14],
  2104. prefix: ['300', '301', '302', '303', '304', '305', '36']
  2105. },
  2106. DINERS_CLUB_US: {
  2107. length: [16],
  2108. prefix: ['54', '55']
  2109. },
  2110. DISCOVER: {
  2111. length: [16],
  2112. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2113. '62214', '62215', '62216', '62217', '62218', '62219',
  2114. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2115. '62290', '62291', '622920', '622921', '622922', '622923',
  2116. '622924', '622925', '644', '645', '646', '647', '648',
  2117. '649', '65']
  2118. },
  2119. JCB: {
  2120. length: [16],
  2121. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2122. },
  2123. LASER: {
  2124. length: [16, 17, 18, 19],
  2125. prefix: ['6304', '6706', '6771', '6709']
  2126. },
  2127. MAESTRO: {
  2128. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2129. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2130. },
  2131. MASTERCARD: {
  2132. length: [16],
  2133. prefix: ['51', '52', '53', '54', '55']
  2134. },
  2135. SOLO: {
  2136. length: [16, 18, 19],
  2137. prefix: ['6334', '6767']
  2138. },
  2139. UNIONPAY: {
  2140. length: [16, 17, 18, 19],
  2141. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2142. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2143. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2144. '622920', '622921', '622922', '622923', '622924', '622925']
  2145. },
  2146. VISA: {
  2147. length: [16],
  2148. prefix: ['4']
  2149. }
  2150. };
  2151. var type, i;
  2152. for (type in cards) {
  2153. for (i in cards[type].prefix) {
  2154. if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2155. && $.inArray(value.length, cards[type].length) !== -1) // and length
  2156. {
  2157. return true;
  2158. }
  2159. }
  2160. }
  2161. return false;
  2162. }
  2163. };
  2164. }(window.jQuery));
  2165. ;(function($) {
  2166. $.fn.bootstrapValidator.i18n.cusip = $.extend($.fn.bootstrapValidator.i18n.cusip || {}, {
  2167. 'default': 'Please enter a valid CUSIP number'
  2168. });
  2169. $.fn.bootstrapValidator.validators.cusip = {
  2170. /**
  2171. * Validate a CUSIP
  2172. * Examples:
  2173. * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  2174. * - Invalid: 31430F200, 022615AC2
  2175. *
  2176. * @see http://en.wikipedia.org/wiki/CUSIP
  2177. * @param {BootstrapValidator} validator The validator plugin instance
  2178. * @param {jQuery} $field Field element
  2179. * @param {Object} [options] Can consist of the following keys:
  2180. * - message: The invalid message
  2181. * @returns {Boolean}
  2182. */
  2183. validate: function(validator, $field, options) {
  2184. var value = $field.val();
  2185. if (value === '') {
  2186. return true;
  2187. }
  2188. value = value.toUpperCase();
  2189. if (!/^[0-9A-Z]{9}$/.test(value)) {
  2190. return false;
  2191. }
  2192. var converted = $.map(value.split(''), function(item) {
  2193. var code = item.charCodeAt(0);
  2194. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  2195. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  2196. ? (code - 'A'.charCodeAt(0) + 10)
  2197. : item;
  2198. }),
  2199. length = converted.length,
  2200. sum = 0;
  2201. for (var i = 0; i < length - 1; i++) {
  2202. var num = parseInt(converted[i], 10);
  2203. if (i % 2 !== 0) {
  2204. num *= 2;
  2205. }
  2206. if (num > 9) {
  2207. num -= 9;
  2208. }
  2209. sum += num;
  2210. }
  2211. sum = (10 - (sum % 10)) % 10;
  2212. return sum === converted[length - 1];
  2213. }
  2214. };
  2215. }(window.jQuery));
  2216. ;(function($) {
  2217. $.fn.bootstrapValidator.i18n.cvv = $.extend($.fn.bootstrapValidator.i18n.cvv || {}, {
  2218. 'default': 'Please enter a valid CVV number'
  2219. });
  2220. $.fn.bootstrapValidator.validators.cvv = {
  2221. html5Attributes: {
  2222. message: 'message',
  2223. ccfield: 'creditCardField'
  2224. },
  2225. /**
  2226. * Return true if the input value is a valid CVV number.
  2227. *
  2228. * @param {BootstrapValidator} validator The validator plugin instance
  2229. * @param {jQuery} $field Field element
  2230. * @param {Object} options Can consist of the following keys:
  2231. * - creditCardField: The credit card number field. It can be null
  2232. * - message: The invalid message
  2233. * @returns {Boolean}
  2234. */
  2235. validate: function(validator, $field, options) {
  2236. var value = $field.val();
  2237. if (value === '') {
  2238. return true;
  2239. }
  2240. if (!/^[0-9]{3,4}$/.test(value)) {
  2241. return false;
  2242. }
  2243. if (!options.creditCardField) {
  2244. return true;
  2245. }
  2246. // Get the credit card number
  2247. var creditCard = validator.getFieldElements(options.creditCardField).val();
  2248. if (creditCard === '') {
  2249. return true;
  2250. }
  2251. creditCard = creditCard.replace(/\D/g, '');
  2252. // Supported credit card types
  2253. var cards = {
  2254. AMERICAN_EXPRESS: {
  2255. length: [15],
  2256. prefix: ['34', '37']
  2257. },
  2258. DINERS_CLUB: {
  2259. length: [14],
  2260. prefix: ['300', '301', '302', '303', '304', '305', '36']
  2261. },
  2262. DINERS_CLUB_US: {
  2263. length: [16],
  2264. prefix: ['54', '55']
  2265. },
  2266. DISCOVER: {
  2267. length: [16],
  2268. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2269. '62214', '62215', '62216', '62217', '62218', '62219',
  2270. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2271. '62290', '62291', '622920', '622921', '622922', '622923',
  2272. '622924', '622925', '644', '645', '646', '647', '648',
  2273. '649', '65']
  2274. },
  2275. JCB: {
  2276. length: [16],
  2277. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2278. },
  2279. LASER: {
  2280. length: [16, 17, 18, 19],
  2281. prefix: ['6304', '6706', '6771', '6709']
  2282. },
  2283. MAESTRO: {
  2284. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2285. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2286. },
  2287. MASTERCARD: {
  2288. length: [16],
  2289. prefix: ['51', '52', '53', '54', '55']
  2290. },
  2291. SOLO: {
  2292. length: [16, 18, 19],
  2293. prefix: ['6334', '6767']
  2294. },
  2295. UNIONPAY: {
  2296. length: [16, 17, 18, 19],
  2297. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2298. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2299. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2300. '622920', '622921', '622922', '622923', '622924', '622925']
  2301. },
  2302. VISA: {
  2303. length: [16],
  2304. prefix: ['4']
  2305. }
  2306. };
  2307. var type, i, creditCardType = null;
  2308. for (type in cards) {
  2309. for (i in cards[type].prefix) {
  2310. if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2311. && $.inArray(creditCard.length, cards[type].length) !== -1) // and length
  2312. {
  2313. creditCardType = type;
  2314. break;
  2315. }
  2316. }
  2317. }
  2318. return (creditCardType === null)
  2319. ? false
  2320. : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
  2321. }
  2322. };
  2323. }(window.jQuery));
  2324. ;(function($) {
  2325. $.fn.bootstrapValidator.i18n.date = $.extend($.fn.bootstrapValidator.i18n.date || {}, {
  2326. 'default': 'Please enter a valid date',
  2327. min: 'Please enter a date after %s',
  2328. max: 'Please enter a date before %s',
  2329. range: 'Please enter a date in the range %s - %s'
  2330. });
  2331. $.fn.bootstrapValidator.validators.date = {
  2332. html5Attributes: {
  2333. message: 'message',
  2334. format: 'format',
  2335. min: 'min',
  2336. max: 'max',
  2337. separator: 'separator'
  2338. },
  2339. /**
  2340. * Return true if the input value is valid date
  2341. *
  2342. * @param {BootstrapValidator} validator The validator plugin instance
  2343. * @param {jQuery} $field Field element
  2344. * @param {Object} options Can consist of the following keys:
  2345. * - message: The invalid message
  2346. * - min: the minimum date
  2347. * - max: the maximum date
  2348. * - separator: Use to separate the date, month, and year.
  2349. * By default, it is /
  2350. * - format: The date format. Default is MM/DD/YYYY
  2351. * The format can be:
  2352. *
  2353. * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  2354. * ii) date and time:
  2355. * The time can consist of h, m, s parts which are separated by :
  2356. * ii) date, time and A (indicating AM or PM)
  2357. * @returns {Boolean|Object}
  2358. */
  2359. validate: function(validator, $field, options) {
  2360. var value = $field.val();
  2361. if (value === '') {
  2362. return true;
  2363. }
  2364. options.format = options.format || 'MM/DD/YYYY';
  2365. // #683: Force the format to YYYY-MM-DD as the default browser behaviour when using type="date" attribute
  2366. if ($field.attr('type') === 'date') {
  2367. options.format = 'YYYY-MM-DD';
  2368. }
  2369. var formats = options.format.split(' '),
  2370. dateFormat = formats[0],
  2371. timeFormat = (formats.length > 1) ? formats[1] : null,
  2372. amOrPm = (formats.length > 2) ? formats[2] : null,
  2373. sections = value.split(' '),
  2374. date = sections[0],
  2375. time = (sections.length > 1) ? sections[1] : null;
  2376. if (formats.length !== sections.length) {
  2377. return {
  2378. valid: false,
  2379. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2380. };
  2381. }
  2382. // Determine the separator
  2383. var separator = options.separator;
  2384. if (!separator) {
  2385. separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
  2386. }
  2387. if (separator === null || date.indexOf(separator) === -1) {
  2388. return {
  2389. valid: false,
  2390. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2391. };
  2392. }
  2393. // Determine the date
  2394. date = date.split(separator);
  2395. dateFormat = dateFormat.split(separator);
  2396. if (date.length !== dateFormat.length) {
  2397. return {
  2398. valid: false,
  2399. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2400. };
  2401. }
  2402. var year = date[$.inArray('YYYY', dateFormat)],
  2403. month = date[$.inArray('MM', dateFormat)],
  2404. day = date[$.inArray('DD', dateFormat)];
  2405. if (!year || !month || !day || year.length !== 4) {
  2406. return {
  2407. valid: false,
  2408. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2409. };
  2410. }
  2411. // Determine the time
  2412. var minutes = null, hours = null, seconds = null;
  2413. if (timeFormat) {
  2414. timeFormat = timeFormat.split(':');
  2415. time = time.split(':');
  2416. if (timeFormat.length !== time.length) {
  2417. return {
  2418. valid: false,
  2419. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2420. };
  2421. }
  2422. hours = time.length > 0 ? time[0] : null;
  2423. minutes = time.length > 1 ? time[1] : null;
  2424. seconds = time.length > 2 ? time[2] : null;
  2425. // Validate seconds
  2426. if (seconds) {
  2427. if (isNaN(seconds) || seconds.length > 2) {
  2428. return {
  2429. valid: false,
  2430. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2431. };
  2432. }
  2433. seconds = parseInt(seconds, 10);
  2434. if (seconds < 0 || seconds > 60) {
  2435. return {
  2436. valid: false,
  2437. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2438. };
  2439. }
  2440. }
  2441. // Validate hours
  2442. if (hours) {
  2443. if (isNaN(hours) || hours.length > 2) {
  2444. return {
  2445. valid: false,
  2446. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2447. };
  2448. }
  2449. hours = parseInt(hours, 10);
  2450. if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  2451. return {
  2452. valid: false,
  2453. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2454. };
  2455. }
  2456. }
  2457. // Validate minutes
  2458. if (minutes) {
  2459. if (isNaN(minutes) || minutes.length > 2) {
  2460. return {
  2461. valid: false,
  2462. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2463. };
  2464. }
  2465. minutes = parseInt(minutes, 10);
  2466. if (minutes < 0 || minutes > 59) {
  2467. return {
  2468. valid: false,
  2469. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2470. };
  2471. }
  2472. }
  2473. }
  2474. // Validate day, month, and year
  2475. var valid = $.fn.bootstrapValidator.helpers.date(year, month, day),
  2476. message = options.message || $.fn.bootstrapValidator.i18n.date['default'];
  2477. // declare the date, min and max objects
  2478. var min = null,
  2479. max = null,
  2480. minOption = options.min,
  2481. maxOption = options.max;
  2482. if (minOption) {
  2483. if (isNaN(Date.parse(minOption))) {
  2484. minOption = validator.getDynamicOption($field, minOption);
  2485. }
  2486. min = this._parseDate(minOption, dateFormat, separator);
  2487. }
  2488. if (maxOption) {
  2489. if (isNaN(Date.parse(maxOption))) {
  2490. maxOption = validator.getDynamicOption($field, maxOption);
  2491. }
  2492. max = this._parseDate(maxOption, dateFormat, separator);
  2493. }
  2494. date = new Date(year, month, day, hours, minutes, seconds);
  2495. switch (true) {
  2496. case (minOption && !maxOption && valid):
  2497. valid = date.getTime() >= min.getTime();
  2498. message = options.message || $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.date.min, minOption);
  2499. break;
  2500. case (maxOption && !minOption && valid):
  2501. valid = date.getTime() <= max.getTime();
  2502. message = options.message || $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.date.max, maxOption);
  2503. break;
  2504. case (maxOption && minOption && valid):
  2505. valid = date.getTime() <= max.getTime() && date.getTime() >= min.getTime();
  2506. message = options.message || $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.date.range, [minOption, maxOption]);
  2507. break;
  2508. default:
  2509. break;
  2510. }
  2511. return {
  2512. valid: valid,
  2513. message: message
  2514. };
  2515. },
  2516. /**
  2517. * Return a date object after parsing the date string
  2518. *
  2519. * @param {String} date The date string to parse
  2520. * @param {String} format The date format
  2521. * The format can be:
  2522. * - date: Consist of DD, MM, YYYY parts which are separated by the separator option
  2523. * - date and time:
  2524. * The time can consist of h, m, s parts which are separated by :
  2525. * @param {String} separator The separator used to separate the date, month, and year
  2526. * @returns {Date}
  2527. */
  2528. _parseDate: function(date, format, separator) {
  2529. var minutes = 0, hours = 0, seconds = 0,
  2530. sections = date.split(' '),
  2531. dateSection = sections[0],
  2532. timeSection = (sections.length > 1) ? sections[1] : null;
  2533. dateSection = dateSection.split(separator);
  2534. var year = dateSection[$.inArray('YYYY', format)],
  2535. month = dateSection[$.inArray('MM', format)],
  2536. day = dateSection[$.inArray('DD', format)];
  2537. if (timeSection) {
  2538. timeSection = timeSection.split(':');
  2539. hours = timeSection.length > 0 ? timeSection[0] : null;
  2540. minutes = timeSection.length > 1 ? timeSection[1] : null;
  2541. seconds = timeSection.length > 2 ? timeSection[2] : null;
  2542. }
  2543. return new Date(year, month, day, hours, minutes, seconds);
  2544. }
  2545. };
  2546. }(window.jQuery));
  2547. ;(function($) {
  2548. $.fn.bootstrapValidator.i18n.different = $.extend($.fn.bootstrapValidator.i18n.different || {}, {
  2549. 'default': 'Please enter a different value'
  2550. });
  2551. $.fn.bootstrapValidator.validators.different = {
  2552. html5Attributes: {
  2553. message: 'message',
  2554. field: 'field'
  2555. },
  2556. /**
  2557. * Return true if the input value is different with given field's value
  2558. *
  2559. * @param {BootstrapValidator} validator The validator plugin instance
  2560. * @param {jQuery} $field Field element
  2561. * @param {Object} options Consists of the following key:
  2562. * - field: The name of field that will be used to compare with current one
  2563. * - message: The invalid message
  2564. * @returns {Boolean}
  2565. */
  2566. validate: function(validator, $field, options) {
  2567. var value = $field.val();
  2568. if (value === '') {
  2569. return true;
  2570. }
  2571. var fields = options.field.split(','),
  2572. isValid = true;
  2573. for (var i = 0; i < fields.length; i++) {
  2574. var compareWith = validator.getFieldElements(fields[i]);
  2575. if (compareWith == null || compareWith.length === 0) {
  2576. continue;
  2577. }
  2578. var compareValue = compareWith.val();
  2579. if (value === compareValue) {
  2580. isValid = false;
  2581. } else if (compareValue !== '') {
  2582. validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
  2583. }
  2584. }
  2585. return isValid;
  2586. }
  2587. };
  2588. }(window.jQuery));
  2589. ;(function($) {
  2590. $.fn.bootstrapValidator.i18n.digits = $.extend($.fn.bootstrapValidator.i18n.digits || {}, {
  2591. 'default': 'Please enter only digits'
  2592. });
  2593. $.fn.bootstrapValidator.validators.digits = {
  2594. /**
  2595. * Return true if the input value contains digits only
  2596. *
  2597. * @param {BootstrapValidator} validator Validate plugin instance
  2598. * @param {jQuery} $field Field element
  2599. * @param {Object} [options]
  2600. * @returns {Boolean}
  2601. */
  2602. validate: function(validator, $field, options) {
  2603. var value = $field.val();
  2604. if (value === '') {
  2605. return true;
  2606. }
  2607. return /^\d+$/.test(value);
  2608. }
  2609. };
  2610. }(window.jQuery));
  2611. ;(function($) {
  2612. $.fn.bootstrapValidator.i18n.ean = $.extend($.fn.bootstrapValidator.i18n.ean || {}, {
  2613. 'default': 'Please enter a valid EAN number'
  2614. });
  2615. $.fn.bootstrapValidator.validators.ean = {
  2616. /**
  2617. * Validate EAN (International Article Number)
  2618. * Examples:
  2619. * - Valid: 73513537, 9780471117094, 4006381333931
  2620. * - Invalid: 73513536
  2621. *
  2622. * @see http://en.wikipedia.org/wiki/European_Article_Number
  2623. * @param {BootstrapValidator} validator The validator plugin instance
  2624. * @param {jQuery} $field Field element
  2625. * @param {Object} options Can consist of the following keys:
  2626. * - message: The invalid message
  2627. * @returns {Boolean}
  2628. */
  2629. validate: function(validator, $field, options) {
  2630. var value = $field.val();
  2631. if (value === '') {
  2632. return true;
  2633. }
  2634. if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  2635. return false;
  2636. }
  2637. var length = value.length,
  2638. sum = 0,
  2639. weight = (length === 8) ? [3, 1] : [1, 3];
  2640. for (var i = 0; i < length - 1; i++) {
  2641. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  2642. }
  2643. sum = (10 - sum % 10) % 10;
  2644. return (sum + '' === value.charAt(length - 1));
  2645. }
  2646. };
  2647. }(window.jQuery));
  2648. ;(function($) {
  2649. $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
  2650. 'default': 'Please enter a valid email address'
  2651. });
  2652. $.fn.bootstrapValidator.validators.emailAddress = {
  2653. html5Attributes: {
  2654. message: 'message',
  2655. multiple: 'multiple',
  2656. separator: 'separator'
  2657. },
  2658. enableByHtml5: function($field) {
  2659. return ('email' === $field.attr('type'));
  2660. },
  2661. /**
  2662. * Return true if and only if the input value is a valid email address
  2663. *
  2664. * @param {BootstrapValidator} validator Validate plugin instance
  2665. * @param {jQuery} $field Field element
  2666. * @param {Object} [options]
  2667. * - multiple: Allow multiple email addresses, separated by a comma or semicolon; default is false.
  2668. * - separator: Regex for character or characters expected as separator between addresses; default is comma /[,;]/, i.e. comma or semicolon.
  2669. * @returns {Boolean}
  2670. */
  2671. validate: function(validator, $field, options) {
  2672. var value = $field.val();
  2673. if (value === '') {
  2674. return true;
  2675. }
  2676. // Email address regular expression
  2677. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  2678. var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
  2679. allowMultiple = options.multiple === true || options.multiple === 'true';
  2680. if (allowMultiple) {
  2681. var separator = options.separator || /[,;]/,
  2682. addresses = this._splitEmailAddresses(value, separator);
  2683. for (var i = 0; i < addresses.length; i++) {
  2684. if (!emailRegExp.test(addresses[i])) {
  2685. return false;
  2686. }
  2687. }
  2688. return true;
  2689. } else {
  2690. return emailRegExp.test(value);
  2691. }
  2692. },
  2693. _splitEmailAddresses: function(emailAddresses, separator) {
  2694. var quotedFragments = emailAddresses.split(/"/),
  2695. quotedFragmentCount = quotedFragments.length,
  2696. emailAddressArray = [],
  2697. nextEmailAddress = '';
  2698. for (var i = 0; i < quotedFragmentCount; i++) {
  2699. if (i % 2 === 0) {
  2700. var splitEmailAddressFragments = quotedFragments[i].split(separator),
  2701. splitEmailAddressFragmentCount = splitEmailAddressFragments.length;
  2702. if (splitEmailAddressFragmentCount === 1) {
  2703. nextEmailAddress += splitEmailAddressFragments[0];
  2704. } else {
  2705. emailAddressArray.push(nextEmailAddress + splitEmailAddressFragments[0]);
  2706. for (var j = 1; j < splitEmailAddressFragmentCount - 1; j++) {
  2707. emailAddressArray.push(splitEmailAddressFragments[j]);
  2708. }
  2709. nextEmailAddress = splitEmailAddressFragments[splitEmailAddressFragmentCount - 1];
  2710. }
  2711. } else {
  2712. nextEmailAddress += '"' + quotedFragments[i];
  2713. if (i < quotedFragmentCount - 1) {
  2714. nextEmailAddress += '"';
  2715. }
  2716. }
  2717. }
  2718. emailAddressArray.push(nextEmailAddress);
  2719. return emailAddressArray;
  2720. }
  2721. };
  2722. }(window.jQuery));
  2723. ;(function($) {
  2724. $.fn.bootstrapValidator.i18n.file = $.extend($.fn.bootstrapValidator.i18n.file || {}, {
  2725. 'default': 'Please choose a valid file'
  2726. });
  2727. $.fn.bootstrapValidator.validators.file = {
  2728. html5Attributes: {
  2729. extension: 'extension',
  2730. maxsize: 'maxSize',
  2731. minsize: 'minSize',
  2732. message: 'message',
  2733. type: 'type'
  2734. },
  2735. /**
  2736. * Validate upload file. Use HTML 5 API if the browser supports
  2737. *
  2738. * @param {BootstrapValidator} validator The validator plugin instance
  2739. * @param {jQuery} $field Field element
  2740. * @param {Object} options Can consist of the following keys:
  2741. * - extension: The allowed extensions, separated by a comma
  2742. * - maxSize: The maximum size in bytes
  2743. * - minSize: the minimum size in bytes
  2744. * - message: The invalid message
  2745. * - type: The allowed MIME type, separated by a comma
  2746. * @returns {Boolean}
  2747. */
  2748. validate: function(validator, $field, options) {
  2749. var value = $field.val();
  2750. if (value === '') {
  2751. return true;
  2752. }
  2753. var ext,
  2754. extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  2755. types = options.type ? options.type.toLowerCase().split(',') : null,
  2756. html5 = (window.File && window.FileList && window.FileReader);
  2757. if (html5) {
  2758. // Get FileList instance
  2759. var files = $field.get(0).files,
  2760. total = files.length;
  2761. for (var i = 0; i < total; i++) {
  2762. // Check the minSize
  2763. if (options.minSize && files[i].size < parseInt(options.minSize, 10)) {
  2764. return false;
  2765. }
  2766. // Check the maxSize
  2767. if (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) {
  2768. return false;
  2769. }
  2770. // Check file extension
  2771. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  2772. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2773. return false;
  2774. }
  2775. // Check file type
  2776. if (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1) {
  2777. return false;
  2778. }
  2779. }
  2780. } else {
  2781. // Check file extension
  2782. ext = value.substr(value.lastIndexOf('.') + 1);
  2783. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2784. return false;
  2785. }
  2786. }
  2787. return true;
  2788. }
  2789. };
  2790. }(window.jQuery));
  2791. ;(function($) {
  2792. $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
  2793. 'default': 'Please enter a value greater than or equal to %s',
  2794. notInclusive: 'Please enter a value greater than %s'
  2795. });
  2796. $.fn.bootstrapValidator.validators.greaterThan = {
  2797. html5Attributes: {
  2798. message: 'message',
  2799. value: 'value',
  2800. inclusive: 'inclusive'
  2801. },
  2802. enableByHtml5: function($field) {
  2803. var type = $field.attr('type'),
  2804. min = $field.attr('min');
  2805. if (min && type !== 'date') {
  2806. return {
  2807. value: min
  2808. };
  2809. }
  2810. return false;
  2811. },
  2812. /**
  2813. * Return true if the input value is greater than or equals to given number
  2814. *
  2815. * @param {BootstrapValidator} validator Validate plugin instance
  2816. * @param {jQuery} $field Field element
  2817. * @param {Object} options Can consist of the following keys:
  2818. * - value: Define the number to compare with. It can be
  2819. * - A number
  2820. * - Name of field which its value defines the number
  2821. * - Name of callback function that returns the number
  2822. * - A callback function that returns the number
  2823. *
  2824. * - inclusive [optional]: Can be true or false. Default is true
  2825. * - message: The invalid message
  2826. * @returns {Boolean|Object}
  2827. */
  2828. validate: function(validator, $field, options) {
  2829. var value = $field.val();
  2830. if (value === '') {
  2831. return true;
  2832. }
  2833. value = value.replace(',', '.');
  2834. if (!$.isNumeric(value)) {
  2835. return false;
  2836. }
  2837. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
  2838. value = parseFloat(value);
  2839. return (options.inclusive === true || options.inclusive === undefined)
  2840. ? {
  2841. valid: value >= compareTo,
  2842. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan['default'], compareTo)
  2843. }
  2844. : {
  2845. valid: value > compareTo,
  2846. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan.notInclusive, compareTo)
  2847. };
  2848. }
  2849. };
  2850. }(window.jQuery));
  2851. ;(function($) {
  2852. $.fn.bootstrapValidator.i18n.grid = $.extend($.fn.bootstrapValidator.i18n.grid || {}, {
  2853. 'default': 'Please enter a valid GRId number'
  2854. });
  2855. $.fn.bootstrapValidator.validators.grid = {
  2856. /**
  2857. * Validate GRId (Global Release Identifier)
  2858. * Examples:
  2859. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  2860. * - Invalid: A1-2425G-ABC1234002-Q
  2861. *
  2862. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  2863. * @param {BootstrapValidator} validator The validator plugin instance
  2864. * @param {jQuery} $field Field element
  2865. * @param {Object} options Can consist of the following keys:
  2866. * - message: The invalid message
  2867. * @returns {Boolean}
  2868. */
  2869. validate: function(validator, $field, options) {
  2870. var value = $field.val();
  2871. if (value === '') {
  2872. return true;
  2873. }
  2874. value = value.toUpperCase();
  2875. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  2876. return false;
  2877. }
  2878. value = value.replace(/\s/g, '').replace(/-/g, '');
  2879. if ('GRID:' === value.substr(0, 5)) {
  2880. value = value.substr(5);
  2881. }
  2882. return $.fn.bootstrapValidator.helpers.mod37And36(value);
  2883. }
  2884. };
  2885. }(window.jQuery));
  2886. ;(function($) {
  2887. $.fn.bootstrapValidator.i18n.hex = $.extend($.fn.bootstrapValidator.i18n.hex || {}, {
  2888. 'default': 'Please enter a valid hexadecimal number'
  2889. });
  2890. $.fn.bootstrapValidator.validators.hex = {
  2891. /**
  2892. * Return true if and only if the input value is a valid hexadecimal number
  2893. *
  2894. * @param {BootstrapValidator} validator The validator plugin instance
  2895. * @param {jQuery} $field Field element
  2896. * @param {Object} options Consist of key:
  2897. * - message: The invalid message
  2898. * @returns {Boolean}
  2899. */
  2900. validate: function(validator, $field, options) {
  2901. var value = $field.val();
  2902. if (value === '') {
  2903. return true;
  2904. }
  2905. return /^[0-9a-fA-F]+$/.test(value);
  2906. }
  2907. };
  2908. }(window.jQuery));
  2909. ;(function($) {
  2910. $.fn.bootstrapValidator.i18n.hexColor = $.extend($.fn.bootstrapValidator.i18n.hexColor || {}, {
  2911. 'default': 'Please enter a valid hex color'
  2912. });
  2913. $.fn.bootstrapValidator.validators.hexColor = {
  2914. enableByHtml5: function($field) {
  2915. return ('color' === $field.attr('type'));
  2916. },
  2917. /**
  2918. * Return true if the input value is a valid hex color
  2919. *
  2920. * @param {BootstrapValidator} validator The validator plugin instance
  2921. * @param {jQuery} $field Field element
  2922. * @param {Object} options Can consist of the following keys:
  2923. * - message: The invalid message
  2924. * @returns {Boolean}
  2925. */
  2926. validate: function(validator, $field, options) {
  2927. var value = $field.val();
  2928. if (value === '') {
  2929. return true;
  2930. }
  2931. return ('color' === $field.attr('type'))
  2932. // Only accept 6 hex character values due to the HTML 5 spec
  2933. // See http://www.w3.org/TR/html-markup/input.color.html#input.color.attrs.value
  2934. ? /^#[0-9A-F]{6}$/i.test(value)
  2935. : /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2936. }
  2937. };
  2938. }(window.jQuery));
  2939. ;(function($) {
  2940. $.fn.bootstrapValidator.i18n.iban = $.extend($.fn.bootstrapValidator.i18n.iban || {}, {
  2941. 'default': 'Please enter a valid IBAN number',
  2942. countryNotSupported: 'The country code %s is not supported',
  2943. country: 'Please enter a valid IBAN number in %s',
  2944. countries: {
  2945. AD: 'Andorra',
  2946. AE: 'United Arab Emirates',
  2947. AL: 'Albania',
  2948. AO: 'Angola',
  2949. AT: 'Austria',
  2950. AZ: 'Azerbaijan',
  2951. BA: 'Bosnia and Herzegovina',
  2952. BE: 'Belgium',
  2953. BF: 'Burkina Faso',
  2954. BG: 'Bulgaria',
  2955. BH: 'Bahrain',
  2956. BI: 'Burundi',
  2957. BJ: 'Benin',
  2958. BR: 'Brazil',
  2959. CH: 'Switzerland',
  2960. CI: 'Ivory Coast',
  2961. CM: 'Cameroon',
  2962. CR: 'Costa Rica',
  2963. CV: 'Cape Verde',
  2964. CY: 'Cyprus',
  2965. CZ: 'Czech Republic',
  2966. DE: 'Germany',
  2967. DK: 'Denmark',
  2968. DO: 'Dominica',
  2969. DZ: 'Algeria',
  2970. EE: 'Estonia',
  2971. ES: 'Spain',
  2972. FI: 'Finland',
  2973. FO: 'Faroe Islands',
  2974. FR: 'France',
  2975. GB: 'United Kingdom',
  2976. GE: 'Georgia',
  2977. GI: 'Gibraltar',
  2978. GL: 'Greenland',
  2979. GR: 'Greece',
  2980. GT: 'Guatemala',
  2981. HR: 'Croatia',
  2982. HU: 'Hungary',
  2983. IE: 'Ireland',
  2984. IL: 'Israel',
  2985. IR: 'Iran',
  2986. IS: 'Iceland',
  2987. IT: 'Italy',
  2988. JO: 'Jordan',
  2989. KW: 'Kuwait',
  2990. KZ: 'Kazakhstan',
  2991. LB: 'Lebanon',
  2992. LI: 'Liechtenstein',
  2993. LT: 'Lithuania',
  2994. LU: 'Luxembourg',
  2995. LV: 'Latvia',
  2996. MC: 'Monaco',
  2997. MD: 'Moldova',
  2998. ME: 'Montenegro',
  2999. MG: 'Madagascar',
  3000. MK: 'Macedonia',
  3001. ML: 'Mali',
  3002. MR: 'Mauritania',
  3003. MT: 'Malta',
  3004. MU: 'Mauritius',
  3005. MZ: 'Mozambique',
  3006. NL: 'Netherlands',
  3007. NO: 'Norway',
  3008. PK: 'Pakistan',
  3009. PL: 'Poland',
  3010. PS: 'Palestine',
  3011. PT: 'Portugal',
  3012. QA: 'Qatar',
  3013. RO: 'Romania',
  3014. RS: 'Serbia',
  3015. SA: 'Saudi Arabia',
  3016. SE: 'Sweden',
  3017. SI: 'Slovenia',
  3018. SK: 'Slovakia',
  3019. SM: 'San Marino',
  3020. SN: 'Senegal',
  3021. TN: 'Tunisia',
  3022. TR: 'Turkey',
  3023. VG: 'Virgin Islands, British'
  3024. }
  3025. });
  3026. $.fn.bootstrapValidator.validators.iban = {
  3027. html5Attributes: {
  3028. message: 'message',
  3029. country: 'country'
  3030. },
  3031. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  3032. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  3033. REGEX: {
  3034. AD: 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  3035. AE: 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  3036. AL: 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  3037. AO: 'AO[0-9]{2}[0-9]{21}', // Angola
  3038. AT: 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  3039. AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  3040. BA: 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  3041. BE: 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  3042. BF: 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  3043. BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  3044. BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  3045. BI: 'BI[0-9]{2}[0-9]{12}', // Burundi
  3046. BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  3047. BR: 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  3048. CH: 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  3049. CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  3050. CM: 'CM[0-9]{2}[0-9]{23}', // Cameroon
  3051. CR: 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  3052. CV: 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  3053. CY: 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  3054. CZ: 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  3055. DE: 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  3056. DK: 'DK[0-9]{2}[0-9]{14}', // Denmark
  3057. DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  3058. DZ: 'DZ[0-9]{2}[0-9]{20}', // Algeria
  3059. EE: 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  3060. ES: 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  3061. FI: 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  3062. FO: 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  3063. FR: 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  3064. GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  3065. GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  3066. GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  3067. GL: 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland
  3068. GR: 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  3069. GT: 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  3070. HR: 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  3071. HU: 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  3072. IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  3073. IL: 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  3074. IR: 'IR[0-9]{2}[0-9]{22}', // Iran
  3075. IS: 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  3076. IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  3077. JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  3078. KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  3079. KZ: 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  3080. LB: 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  3081. LI: 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  3082. LT: 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  3083. LU: 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  3084. LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  3085. MC: 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  3086. MD: 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  3087. ME: 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  3088. MG: 'MG[0-9]{2}[0-9]{23}', // Madagascar
  3089. MK: 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  3090. ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  3091. MR: 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  3092. MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  3093. MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}', // Mauritius
  3094. MZ: 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  3095. NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  3096. NO: 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  3097. PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  3098. PL: 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  3099. PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  3100. PT: 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  3101. QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  3102. RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  3103. RS: 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  3104. SA: 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  3105. SE: 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  3106. SI: 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  3107. SK: 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  3108. SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  3109. SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  3110. TN: 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  3111. TR: 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  3112. VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  3113. },
  3114. /**
  3115. * Validate an International Bank Account Number (IBAN)
  3116. * To test it, take the sample IBAN from
  3117. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  3118. *
  3119. * @param {BootstrapValidator} validator The validator plugin instance
  3120. * @param {jQuery} $field Field element
  3121. * @param {Object} options Can consist of the following keys:
  3122. * - message: The invalid message
  3123. * - country: The ISO 3166-1 country code. It can be
  3124. * - A country code
  3125. * - Name of field which its value defines the country code
  3126. * - Name of callback function that returns the country code
  3127. * - A callback function that returns the country code
  3128. * @returns {Boolean|Object}
  3129. */
  3130. validate: function(validator, $field, options) {
  3131. var value = $field.val();
  3132. if (value === '') {
  3133. return true;
  3134. }
  3135. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  3136. var country = options.country;
  3137. if (!country) {
  3138. country = value.substr(0, 2);
  3139. } else if (typeof country !== 'string' || !this.REGEX[country]) {
  3140. // Determine the country code
  3141. country = validator.getDynamicOption($field, country);
  3142. }
  3143. if (!this.REGEX[country]) {
  3144. return {
  3145. valid: false,
  3146. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.iban.countryNotSupported, country)
  3147. };
  3148. }
  3149. if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
  3150. return {
  3151. valid: false,
  3152. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  3153. };
  3154. }
  3155. value = value.substr(4) + value.substr(0, 4);
  3156. value = $.map(value.split(''), function(n) {
  3157. var code = n.charCodeAt(0);
  3158. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  3159. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  3160. ? (code - 'A'.charCodeAt(0) + 10)
  3161. : n;
  3162. });
  3163. value = value.join('');
  3164. var temp = parseInt(value.substr(0, 1), 10),
  3165. length = value.length;
  3166. for (var i = 1; i < length; ++i) {
  3167. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  3168. }
  3169. return {
  3170. valid: (temp === 1),
  3171. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  3172. };
  3173. }
  3174. };
  3175. }(window.jQuery));
  3176. ;(function($) {
  3177. $.fn.bootstrapValidator.i18n.id = $.extend($.fn.bootstrapValidator.i18n.id || {}, {
  3178. 'default': 'Please enter a valid identification number',
  3179. countryNotSupported: 'The country code %s is not supported',
  3180. country: 'Please enter a valid identification number in %s',
  3181. countries: {
  3182. BA: 'Bosnia and Herzegovina',
  3183. BG: 'Bulgaria',
  3184. BR: 'Brazil',
  3185. CH: 'Switzerland',
  3186. CL: 'Chile',
  3187. CN: 'China',
  3188. CZ: 'Czech Republic',
  3189. DK: 'Denmark',
  3190. EE: 'Estonia',
  3191. ES: 'Spain',
  3192. FI: 'Finland',
  3193. HR: 'Croatia',
  3194. IE: 'Ireland',
  3195. IS: 'Iceland',
  3196. LT: 'Lithuania',
  3197. LV: 'Latvia',
  3198. ME: 'Montenegro',
  3199. MK: 'Macedonia',
  3200. NL: 'Netherlands',
  3201. RO: 'Romania',
  3202. RS: 'Serbia',
  3203. SE: 'Sweden',
  3204. SI: 'Slovenia',
  3205. SK: 'Slovakia',
  3206. SM: 'San Marino',
  3207. TH: 'Thailand',
  3208. ZA: 'South Africa'
  3209. }
  3210. });
  3211. $.fn.bootstrapValidator.validators.id = {
  3212. html5Attributes: {
  3213. message: 'message',
  3214. country: 'country'
  3215. },
  3216. // Supported country codes
  3217. COUNTRY_CODES: [
  3218. 'BA', 'BG', 'BR', 'CH', 'CL', 'CN', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL',
  3219. 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'TH', 'ZA'
  3220. ],
  3221. /**
  3222. * Validate identification number in different countries
  3223. *
  3224. * @see http://en.wikipedia.org/wiki/National_identification_number
  3225. * @param {BootstrapValidator} validator The validator plugin instance
  3226. * @param {jQuery} $field Field element
  3227. * @param {Object} options Consist of key:
  3228. * - message: The invalid message
  3229. * - country: The ISO 3166-1 country code. It can be
  3230. * - One of country code defined in COUNTRY_CODES
  3231. * - Name of field which its value defines the country code
  3232. * - Name of callback function that returns the country code
  3233. * - A callback function that returns the country code
  3234. * @returns {Boolean|Object}
  3235. */
  3236. validate: function(validator, $field, options) {
  3237. var value = $field.val();
  3238. if (value === '') {
  3239. return true;
  3240. }
  3241. var country = options.country;
  3242. if (!country) {
  3243. country = value.substr(0, 2);
  3244. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  3245. // Determine the country code
  3246. country = validator.getDynamicOption($field, country);
  3247. }
  3248. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  3249. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.id.countryNotSupported, country) };
  3250. }
  3251. var method = ['_', country.toLowerCase()].join('');
  3252. return this[method](value)
  3253. ? true
  3254. : {
  3255. valid: false,
  3256. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.id.country, $.fn.bootstrapValidator.i18n.id.countries[country.toUpperCase()])
  3257. };
  3258. },
  3259. /**
  3260. * Validate Unique Master Citizen Number which uses in
  3261. * - Bosnia and Herzegovina (country code: BA)
  3262. * - Macedonia (MK)
  3263. * - Montenegro (ME)
  3264. * - Serbia (RS)
  3265. * - Slovenia (SI)
  3266. *
  3267. * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  3268. * @param {String} value The ID
  3269. * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  3270. * @returns {Boolean}
  3271. */
  3272. _validateJMBG: function(value, countryCode) {
  3273. if (!/^\d{13}$/.test(value)) {
  3274. return false;
  3275. }
  3276. var day = parseInt(value.substr(0, 2), 10),
  3277. month = parseInt(value.substr(2, 2), 10),
  3278. year = parseInt(value.substr(4, 3), 10),
  3279. rr = parseInt(value.substr(7, 2), 10),
  3280. k = parseInt(value.substr(12, 1), 10);
  3281. // Validate date of birth
  3282. // FIXME: Validate the year of birth
  3283. if (day > 31 || month > 12) {
  3284. return false;
  3285. }
  3286. // Validate checksum
  3287. var sum = 0;
  3288. for (var i = 0; i < 6; i++) {
  3289. sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
  3290. }
  3291. sum = 11 - sum % 11;
  3292. if (sum === 10 || sum === 11) {
  3293. sum = 0;
  3294. }
  3295. if (sum !== k) {
  3296. return false;
  3297. }
  3298. // Validate political region
  3299. // rr is the political region of birth, which can be in ranges:
  3300. // 10-19: Bosnia and Herzegovina
  3301. // 20-29: Montenegro
  3302. // 30-39: Croatia (not used anymore)
  3303. // 41-49: Macedonia
  3304. // 50-59: Slovenia (only 50 is used)
  3305. // 70-79: Central Serbia
  3306. // 80-89: Serbian province of Vojvodina
  3307. // 90-99: Kosovo
  3308. switch (countryCode.toUpperCase()) {
  3309. case 'BA':
  3310. return (10 <= rr && rr <= 19);
  3311. case 'MK':
  3312. return (41 <= rr && rr <= 49);
  3313. case 'ME':
  3314. return (20 <= rr && rr <= 29);
  3315. case 'RS':
  3316. return (70 <= rr && rr <= 99);
  3317. case 'SI':
  3318. return (50 <= rr && rr <= 59);
  3319. default:
  3320. return true;
  3321. }
  3322. },
  3323. _ba: function(value) {
  3324. return this._validateJMBG(value, 'BA');
  3325. },
  3326. _mk: function(value) {
  3327. return this._validateJMBG(value, 'MK');
  3328. },
  3329. _me: function(value) {
  3330. return this._validateJMBG(value, 'ME');
  3331. },
  3332. _rs: function(value) {
  3333. return this._validateJMBG(value, 'RS');
  3334. },
  3335. /**
  3336. * Examples: 0101006500006
  3337. */
  3338. _si: function(value) {
  3339. return this._validateJMBG(value, 'SI');
  3340. },
  3341. /**
  3342. * Validate Bulgarian national identification number (EGN)
  3343. * Examples:
  3344. * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  3345. * - Invalid: 8019010008
  3346. *
  3347. * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  3348. * @param {String} value The ID
  3349. * @returns {Boolean}
  3350. */
  3351. _bg: function(value) {
  3352. if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  3353. return false;
  3354. }
  3355. value = value.replace(/\s/g, '');
  3356. // Check the birth date
  3357. var year = parseInt(value.substr(0, 2), 10) + 1900,
  3358. month = parseInt(value.substr(2, 2), 10),
  3359. day = parseInt(value.substr(4, 2), 10);
  3360. if (month > 40) {
  3361. year += 100;
  3362. month -= 40;
  3363. } else if (month > 20) {
  3364. year -= 100;
  3365. month -= 20;
  3366. }
  3367. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3368. return false;
  3369. }
  3370. var sum = 0,
  3371. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  3372. for (var i = 0; i < 9; i++) {
  3373. sum += parseInt(value.charAt(i), 10) * weight[i];
  3374. }
  3375. sum = (sum % 11) % 10;
  3376. return (sum + '' === value.substr(9, 1));
  3377. },
  3378. /**
  3379. * Validate Brazilian national identification number (CPF)
  3380. * Examples:
  3381. * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  3382. * - Invalid: 231.002.999-00
  3383. *
  3384. * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  3385. * @param {String} value The ID
  3386. * @returns {Boolean}
  3387. */
  3388. _br: function(value) {
  3389. if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  3390. return false;
  3391. }
  3392. if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
  3393. return false;
  3394. }
  3395. value = value.replace(/\./g, '').replace(/-/g, '');
  3396. var d1 = 0;
  3397. for (var i = 0; i < 9; i++) {
  3398. d1 += (10 - i) * parseInt(value.charAt(i), 10);
  3399. }
  3400. d1 = 11 - d1 % 11;
  3401. if (d1 === 10 || d1 === 11) {
  3402. d1 = 0;
  3403. }
  3404. if (d1 + '' !== value.charAt(9)) {
  3405. return false;
  3406. }
  3407. var d2 = 0;
  3408. for (i = 0; i < 10; i++) {
  3409. d2 += (11 - i) * parseInt(value.charAt(i), 10);
  3410. }
  3411. d2 = 11 - d2 % 11;
  3412. if (d2 === 10 || d2 === 11) {
  3413. d2 = 0;
  3414. }
  3415. return (d2 + '' === value.charAt(10));
  3416. },
  3417. /**
  3418. * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  3419. * Examples:
  3420. * - Valid: 756.1234.5678.95, 7561234567895
  3421. *
  3422. * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  3423. * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  3424. * @param {String} value The ID
  3425. * @returns {Boolean}
  3426. */
  3427. _ch: function(value) {
  3428. if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  3429. return false;
  3430. }
  3431. value = value.replace(/\D/g, '').substr(3);
  3432. var length = value.length,
  3433. sum = 0,
  3434. weight = (length === 8) ? [3, 1] : [1, 3];
  3435. for (var i = 0; i < length - 1; i++) {
  3436. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3437. }
  3438. sum = 10 - sum % 10;
  3439. return (sum + '' === value.charAt(length - 1));
  3440. },
  3441. /**
  3442. * Validate Chilean national identification number (RUN/RUT)
  3443. * Examples:
  3444. * - Valid: 76086428-5, 22060449-7, 12531909-2
  3445. *
  3446. * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  3447. * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  3448. * @param {String} value The ID
  3449. * @returns {Boolean}
  3450. */
  3451. _cl: function(value) {
  3452. if (!/^\d{7,8}[-]{0,1}[0-9K]$/i.test(value)) {
  3453. return false;
  3454. }
  3455. value = value.replace(/\-/g, '');
  3456. while (value.length < 9) {
  3457. value = '0' + value;
  3458. }
  3459. var sum = 0,
  3460. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  3461. for (var i = 0; i < 8; i++) {
  3462. sum += parseInt(value.charAt(i), 10) * weight[i];
  3463. }
  3464. sum = 11 - sum % 11;
  3465. if (sum === 11) {
  3466. sum = 0;
  3467. } else if (sum === 10) {
  3468. sum = 'K';
  3469. }
  3470. return sum + '' === value.charAt(8).toUpperCase();
  3471. },
  3472. /**
  3473. * Validate Chinese citizen identification number
  3474. *
  3475. * Rules:
  3476. * - For current 18-digit system (since 1st Oct 1999, defined by GB11643—1999 national standard):
  3477. * - Digit 0-5: Must be a valid administrative division code of China PR.
  3478. * - Digit 6-13: Must be a valid YYYYMMDD date of birth. A future date is tolerated.
  3479. * - Digit 14-16: Order code, any integer.
  3480. * - Digit 17: An ISO 7064:1983, MOD 11-2 checksum.
  3481. * Both upper/lower case of X are tolerated.
  3482. * - For deprecated 15-digit system:
  3483. * - Digit 0-5: Must be a valid administrative division code of China PR.
  3484. * - Digit 6-11: Must be a valid YYMMDD date of birth, indicating the year of 19XX.
  3485. * - Digit 12-14: Order code, any integer.
  3486. * Lists of valid administrative division codes of China PR can be seen here:
  3487. * <http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/>
  3488. * Published and maintained by National Bureau of Statistics of China PR.
  3489. * NOTE: Current and deprecated codes MUST BOTH be considered valid.
  3490. * Many Chinese citizens born in once existed administrative divisions!
  3491. *
  3492. * @see http://en.wikipedia.org/wiki/Resident_Identity_Card#Identity_card_number
  3493. * @param {String} value The ID
  3494. * @returns {Boolean}
  3495. */
  3496. _cn: function(value) {
  3497. // Basic format check (18 or 15 digits, considering X in checksum)
  3498. value = value.trim();
  3499. if (!/^\d{15}$/.test(value) && !/^\d{17}[\dXx]{1}$/.test(value)) {
  3500. return false;
  3501. }
  3502. // Check China PR Administrative division code
  3503. var adminDivisionCodes = {
  3504. 11: {
  3505. 0: [0],
  3506. 1: [[0, 9], [11, 17]],
  3507. 2: [0, 28, 29]
  3508. },
  3509. 12: {
  3510. 0: [0],
  3511. 1: [[0, 16]],
  3512. 2: [0, 21, 23, 25]
  3513. },
  3514. 13: {
  3515. 0: [0],
  3516. 1: [[0, 5], 7, 8, 21, [23, 33], [81, 85]],
  3517. 2: [[0, 5], [7, 9], [23, 25], 27, 29, 30, 81, 83],
  3518. 3: [[0, 4], [21, 24]],
  3519. 4: [[0, 4], 6, 21, [23, 35], 81],
  3520. 5: [[0, 3], [21, 35], 81, 82],
  3521. 6: [[0, 4], [21, 38], [81, 84]],
  3522. 7: [[0, 3], 5, 6, [21, 33]],
  3523. 8: [[0, 4], [21, 28]],
  3524. 9: [[0, 3], [21, 30], [81, 84]],
  3525. 10: [[0, 3], [22, 26], 28, 81, 82],
  3526. 11: [[0, 2], [21, 28], 81, 82]
  3527. },
  3528. 14: {
  3529. 0: [0],
  3530. 1: [0, 1, [5, 10], [21, 23], 81],
  3531. 2: [[0, 3], 11, 12, [21, 27]],
  3532. 3: [[0, 3], 11, 21, 22],
  3533. 4: [[0, 2], 11, 21, [23, 31], 81],
  3534. 5: [[0, 2], 21, 22, 24, 25, 81],
  3535. 6: [[0, 3], [21, 24]],
  3536. 7: [[0, 2], [21, 29], 81],
  3537. 8: [[0, 2], [21, 30], 81, 82],
  3538. 9: [[0, 2], [21, 32], 81],
  3539. 10: [[0, 2], [21, 34], 81, 82],
  3540. 11: [[0, 2], [21, 30], 81, 82],
  3541. 23: [[0, 3], 22, 23, [25, 30], 32, 33]
  3542. },
  3543. 15: {
  3544. 0: [0],
  3545. 1: [[0, 5], [21, 25]],
  3546. 2: [[0, 7], [21, 23]],
  3547. 3: [[0, 4]],
  3548. 4: [[0, 4], [21, 26], [28, 30]],
  3549. 5: [[0, 2], [21, 26], 81],
  3550. 6: [[0, 2], [21, 27]],
  3551. 7: [[0, 3], [21, 27], [81, 85]],
  3552. 8: [[0, 2], [21, 26]],
  3553. 9: [[0, 2], [21, 29], 81],
  3554. 22: [[0, 2], [21, 24]],
  3555. 25: [[0, 2], [22, 31]],
  3556. 26: [[0, 2], [24, 27], [29, 32], 34],
  3557. 28: [0, 1, [22, 27]],
  3558. 29: [0, [21, 23]]
  3559. },
  3560. 21: {
  3561. 0: [0],
  3562. 1: [[0, 6], [11, 14], [22, 24], 81],
  3563. 2: [[0, 4], [11, 13], 24, [81, 83]],
  3564. 3: [[0, 4], 11, 21, 23, 81],
  3565. 4: [[0, 4], 11, [21, 23]],
  3566. 5: [[0, 5], 21, 22],
  3567. 6: [[0, 4], 24, 81, 82],
  3568. 7: [[0, 3], 11, 26, 27, 81, 82],
  3569. 8: [[0, 4], 11, 81, 82],
  3570. 9: [[0, 5], 11, 21, 22],
  3571. 10: [[0, 5], 11, 21, 81],
  3572. 11: [[0, 3], 21, 22],
  3573. 12: [[0, 2], 4, 21, 23, 24, 81, 82],
  3574. 13: [[0, 3], 21, 22, 24, 81, 82],
  3575. 14: [[0, 4], 21, 22, 81]
  3576. },
  3577. 22: {
  3578. 0: [0],
  3579. 1: [[0, 6], 12, 22, [81, 83]],
  3580. 2: [[0, 4], 11, 21, [81, 84]],
  3581. 3: [[0, 3], 22, 23, 81, 82],
  3582. 4: [[0, 3], 21, 22],
  3583. 5: [[0, 3], 21, 23, 24, 81, 82],
  3584. 6: [[0, 2], 4, 5, [21, 23], 25, 81],
  3585. 7: [[0, 2], [21, 24], 81],
  3586. 8: [[0, 2], 21, 22, 81, 82],
  3587. 24: [[0, 6], 24, 26]
  3588. },
  3589. 23: {
  3590. 0: [0],
  3591. 1: [[0, 12], 21, [23, 29], [81, 84]],
  3592. 2: [[0, 8], 21, [23, 25], 27, [29, 31], 81],
  3593. 3: [[0, 7], 21, 81, 82],
  3594. 4: [[0, 7], 21, 22],
  3595. 5: [[0, 3], 5, 6, [21, 24]],
  3596. 6: [[0, 6], [21, 24]],
  3597. 7: [[0, 16], 22, 81],
  3598. 8: [[0, 5], 11, 22, 26, 28, 33, 81, 82],
  3599. 9: [[0, 4], 21],
  3600. 10: [[0, 5], 24, 25, 81, [83, 85]],
  3601. 11: [[0, 2], 21, 23, 24, 81, 82],
  3602. 12: [[0, 2], [21, 26], [81, 83]],
  3603. 27: [[0, 4], [21, 23]]
  3604. },
  3605. 31: {
  3606. 0: [0],
  3607. 1: [0, 1, [3, 10], [12, 20]],
  3608. 2: [0, 30]
  3609. },
  3610. 32: {
  3611. 0: [0],
  3612. 1: [[0, 7], 11, [13, 18], 24, 25],
  3613. 2: [[0, 6], 11, 81, 82],
  3614. 3: [[0, 5], 11, 12, [21, 24], 81, 82],
  3615. 4: [[0, 2], 4, 5, 11, 12, 81, 82],
  3616. 5: [[0, 9], [81, 85]],
  3617. 6: [[0, 2], 11, 12, 21, 23, [81, 84]],
  3618. 7: [0, 1, 3, 5, 6, [21, 24]],
  3619. 8: [[0, 4], 11, 26, [29, 31]],
  3620. 9: [[0, 3], [21, 25], 28, 81, 82],
  3621. 10: [[0, 3], 11, 12, 23, 81, 84, 88],
  3622. 11: [[0, 2], 11, 12, [81, 83]],
  3623. 12: [[0, 4], [81, 84]],
  3624. 13: [[0, 2], 11, [21, 24]]
  3625. },
  3626. 33: {
  3627. 0: [0],
  3628. 1: [[0, 6], [8, 10], 22, 27, 82, 83, 85],
  3629. 2: [0, 1, [3, 6], 11, 12, 25, 26, [81, 83]],
  3630. 3: [[0, 4], 22, 24, [26, 29], 81, 82],
  3631. 4: [[0, 2], 11, 21, 24, [81, 83]],
  3632. 5: [[0, 3], [21, 23]],
  3633. 6: [[0, 2], 21, 24, [81, 83]],
  3634. 7: [[0, 3], 23, 26, 27, [81, 84]],
  3635. 8: [[0, 3], 22, 24, 25, 81],
  3636. 9: [[0, 3], 21, 22],
  3637. 10: [[0, 4], [21, 24], 81, 82],
  3638. 11: [[0, 2], [21, 27], 81]
  3639. },
  3640. 34: {
  3641. 0: [0],
  3642. 1: [[0, 4], 11, [21, 24], 81],
  3643. 2: [[0, 4], 7, 8, [21, 23], 25],
  3644. 3: [[0, 4], 11, [21, 23]],
  3645. 4: [[0, 6], 21],
  3646. 5: [[0, 4], 6, [21, 23]],
  3647. 6: [[0, 4], 21],
  3648. 7: [[0, 3], 11, 21],
  3649. 8: [[0, 3], 11, [22, 28], 81],
  3650. 10: [[0, 4], [21, 24]],
  3651. 11: [[0, 3], 22, [24, 26], 81, 82],
  3652. 12: [[0, 4], 21, 22, 25, 26, 82],
  3653. 13: [[0, 2], [21, 24]],
  3654. 14: [[0, 2], [21, 24]],
  3655. 15: [[0, 3], [21, 25]],
  3656. 16: [[0, 2], [21, 23]],
  3657. 17: [[0, 2], [21, 23]],
  3658. 18: [[0, 2], [21, 25], 81]
  3659. },
  3660. 35: {
  3661. 0: [0],
  3662. 1: [[0, 5], 11, [21, 25], 28, 81, 82],
  3663. 2: [[0, 6], [11, 13]],
  3664. 3: [[0, 5], 22],
  3665. 4: [[0, 3], 21, [23, 30], 81],
  3666. 5: [[0, 5], 21, [24, 27], [81, 83]],
  3667. 6: [[0, 3], [22, 29], 81],
  3668. 7: [[0, 2], [21, 25], [81, 84]],
  3669. 8: [[0, 2], [21, 25], 81],
  3670. 9: [[0, 2], [21, 26], 81, 82]
  3671. },
  3672. 36: {
  3673. 0: [0],
  3674. 1: [[0, 5], 11, [21, 24]],
  3675. 2: [[0, 3], 22, 81],
  3676. 3: [[0, 2], 13, [21, 23]],
  3677. 4: [[0, 3], 21, [23, 30], 81, 82],
  3678. 5: [[0, 2], 21],
  3679. 6: [[0, 2], 22, 81],
  3680. 7: [[0, 2], [21, 35], 81, 82],
  3681. 8: [[0, 3], [21, 30], 81],
  3682. 9: [[0, 2], [21, 26], [81, 83]],
  3683. 10: [[0, 2], [21, 30]],
  3684. 11: [[0, 2], [21, 30], 81]
  3685. },
  3686. 37: {
  3687. 0: [0],
  3688. 1: [[0, 5], 12, 13, [24, 26], 81],
  3689. 2: [[0, 3], 5, [11, 14], [81, 85]],
  3690. 3: [[0, 6], [21, 23]],
  3691. 4: [[0, 6], 81],
  3692. 5: [[0, 3], [21, 23]],
  3693. 6: [[0, 2], [11, 13], 34, [81, 87]],
  3694. 7: [[0, 5], 24, 25, [81, 86]],
  3695. 8: [[0, 2], 11, [26, 32], [81, 83]],
  3696. 9: [[0, 3], 11, 21, 23, 82, 83],
  3697. 10: [[0, 2], [81, 83]],
  3698. 11: [[0, 3], 21, 22],
  3699. 12: [[0, 3]],
  3700. 13: [[0, 2], 11, 12, [21, 29]],
  3701. 14: [[0, 2], [21, 28], 81, 82],
  3702. 15: [[0, 2], [21, 26], 81],
  3703. 16: [[0, 2], [21, 26]],
  3704. 17: [[0, 2], [21, 28]]
  3705. },
  3706. 41: {
  3707. 0: [0],
  3708. 1: [[0, 6], 8, 22, [81, 85]],
  3709. 2: [[0, 5], 11, [21, 25]],
  3710. 3: [[0, 7], 11, [22, 29], 81],
  3711. 4: [[0, 4], 11, [21, 23], 25, 81, 82],
  3712. 5: [[0, 3], 5, 6, 22, 23, 26, 27, 81],
  3713. 6: [[0, 3], 11, 21, 22],
  3714. 7: [[0, 4], 11, 21, [24, 28], 81, 82],
  3715. 8: [[0, 4], 11, [21, 23], 25, [81, 83]],
  3716. 9: [[0, 2], 22, 23, [26, 28]],
  3717. 10: [[0, 2], [23, 25], 81, 82],
  3718. 11: [[0, 4], [21, 23]],
  3719. 12: [[0, 2], 21, 22, 24, 81, 82],
  3720. 13: [[0, 3], [21, 30], 81],
  3721. 14: [[0, 3], [21, 26], 81],
  3722. 15: [[0, 3], [21, 28]],
  3723. 16: [[0, 2], [21, 28], 81],
  3724. 17: [[0, 2], [21, 29]],
  3725. 90: [0, 1]
  3726. },
  3727. 42: {
  3728. 0: [0],
  3729. 1: [[0, 7], [11, 17]],
  3730. 2: [[0, 5], 22, 81],
  3731. 3: [[0, 3], [21, 25], 81],
  3732. 5: [[0, 6], [25, 29], [81, 83]],
  3733. 6: [[0, 2], 6, 7, [24, 26], [82, 84]],
  3734. 7: [[0, 4]],
  3735. 8: [[0, 2], 4, 21, 22, 81],
  3736. 9: [[0, 2], [21, 23], 81, 82, 84],
  3737. 10: [[0, 3], [22, 24], 81, 83, 87],
  3738. 11: [[0, 2], [21, 27], 81, 82],
  3739. 12: [[0, 2], [21, 24], 81],
  3740. 13: [[0, 3], 21, 81],
  3741. 28: [[0, 2], 22, 23, [25, 28]],
  3742. 90: [0, [4, 6], 21]
  3743. },
  3744. 43: {
  3745. 0: [0],
  3746. 1: [[0, 5], 11, 12, 21, 22, 24, 81],
  3747. 2: [[0, 4], 11, 21, [23, 25], 81],
  3748. 3: [[0, 2], 4, 21, 81, 82],
  3749. 4: [0, 1, [5, 8], 12, [21, 24], 26, 81, 82],
  3750. 5: [[0, 3], 11, [21, 25], [27, 29], 81],
  3751. 6: [[0, 3], 11, 21, 23, 24, 26, 81, 82],
  3752. 7: [[0, 3], [21, 26], 81],
  3753. 8: [[0, 2], 11, 21, 22],
  3754. 9: [[0, 3], [21, 23], 81],
  3755. 10: [[0, 3], [21, 28], 81],
  3756. 11: [[0, 3], [21, 29]],
  3757. 12: [[0, 2], [21, 30], 81],
  3758. 13: [[0, 2], 21, 22, 81, 82],
  3759. 31: [0, 1, [22, 27], 30]
  3760. },
  3761. 44: {
  3762. 0: [0],
  3763. 1: [[0, 7], [11, 16], 83, 84],
  3764. 2: [[0, 5], 21, 22, 24, 29, 32, 33, 81, 82],
  3765. 3: [0, 1, [3, 8]],
  3766. 4: [[0, 4]],
  3767. 5: [0, 1, [6, 15], 23, 82, 83],
  3768. 6: [0, 1, [4, 8]],
  3769. 7: [0, 1, [3, 5], 81, [83, 85]],
  3770. 8: [[0, 4], 11, 23, 25, [81, 83]],
  3771. 9: [[0, 3], 23, [81, 83]],
  3772. 12: [[0, 3], [23, 26], 83, 84],
  3773. 13: [[0, 3], [22, 24], 81],
  3774. 14: [[0, 2], [21, 24], 26, 27, 81],
  3775. 15: [[0, 2], 21, 23, 81],
  3776. 16: [[0, 2], [21, 25]],
  3777. 17: [[0, 2], 21, 23, 81],
  3778. 18: [[0, 3], 21, 23, [25, 27], 81, 82],
  3779. 19: [0],
  3780. 20: [0],
  3781. 51: [[0, 3], 21, 22],
  3782. 52: [[0, 3], 21, 22, 24, 81],
  3783. 53: [[0, 2], [21, 23], 81]
  3784. },
  3785. 45: {
  3786. 0: [0],
  3787. 1: [[0, 9], [21, 27]],
  3788. 2: [[0, 5], [21, 26]],
  3789. 3: [[0, 5], 11, 12, [21, 32]],
  3790. 4: [0, 1, [3, 6], 11, [21, 23], 81],
  3791. 5: [[0, 3], 12, 21],
  3792. 6: [[0, 3], 21, 81],
  3793. 7: [[0, 3], 21, 22],
  3794. 8: [[0, 4], 21, 81],
  3795. 9: [[0, 3], [21, 24], 81],
  3796. 10: [[0, 2], [21, 31]],
  3797. 11: [[0, 2], [21, 23]],
  3798. 12: [[0, 2], [21, 29], 81],
  3799. 13: [[0, 2], [21, 24], 81],
  3800. 14: [[0, 2], [21, 25], 81]
  3801. },
  3802. 46: {
  3803. 0: [0],
  3804. 1: [0, 1, [5, 8]],
  3805. 2: [0, 1],
  3806. 3: [0, [21, 23]],
  3807. 90: [[0, 3], [5, 7], [21, 39]]
  3808. },
  3809. 50: {
  3810. 0: [0],
  3811. 1: [[0, 19]],
  3812. 2: [0, [22, 38], [40, 43]],
  3813. 3: [0, [81, 84]]
  3814. },
  3815. 51: {
  3816. 0: [0],
  3817. 1: [0, 1, [4, 8], [12, 15], [21, 24], 29, 31, 32, [81, 84]],
  3818. 3: [[0, 4], 11, 21, 22],
  3819. 4: [[0, 3], 11, 21, 22],
  3820. 5: [[0, 4], 21, 22, 24, 25],
  3821. 6: [0, 1, 3, 23, 26, [81, 83]],
  3822. 7: [0, 1, 3, 4, [22, 27], 81],
  3823. 8: [[0, 2], 11, 12, [21, 24]],
  3824. 9: [[0, 4], [21, 23]],
  3825. 10: [[0, 2], 11, 24, 25, 28],
  3826. 11: [[0, 2], [11, 13], 23, 24, 26, 29, 32, 33, 81],
  3827. 13: [[0, 4], [21, 25], 81],
  3828. 14: [[0, 2], [21, 25]],
  3829. 15: [[0, 3], [21, 29]],
  3830. 16: [[0, 3], [21, 23], 81],
  3831. 17: [[0, 3], [21, 25], 81],
  3832. 18: [[0, 3], [21, 27]],
  3833. 19: [[0, 3], [21, 23]],
  3834. 20: [[0, 2], 21, 22, 81],
  3835. 32: [0, [21, 33]],
  3836. 33: [0, [21, 38]],
  3837. 34: [0, 1, [22, 37]]
  3838. },
  3839. 52: {
  3840. 0: [0],
  3841. 1: [[0, 3], [11, 15], [21, 23], 81],
  3842. 2: [0, 1, 3, 21, 22],
  3843. 3: [[0, 3], [21, 30], 81, 82],
  3844. 4: [[0, 2], [21, 25]],
  3845. 5: [[0, 2], [21, 27]],
  3846. 6: [[0, 3], [21, 28]],
  3847. 22: [0, 1, [22, 30]],
  3848. 23: [0, 1, [22, 28]],
  3849. 24: [0, 1, [22, 28]],
  3850. 26: [0, 1, [22, 36]],
  3851. 27: [[0, 2], 22, 23, [25, 32]]
  3852. },
  3853. 53: {
  3854. 0: [0],
  3855. 1: [[0, 3], [11, 14], 21, 22, [24, 29], 81],
  3856. 3: [[0, 2], [21, 26], 28, 81],
  3857. 4: [[0, 2], [21, 28]],
  3858. 5: [[0, 2], [21, 24]],
  3859. 6: [[0, 2], [21, 30]],
  3860. 7: [[0, 2], [21, 24]],
  3861. 8: [[0, 2], [21, 29]],
  3862. 9: [[0, 2], [21, 27]],
  3863. 23: [0, 1, [22, 29], 31],
  3864. 25: [[0, 4], [22, 32]],
  3865. 26: [0, 1, [21, 28]],
  3866. 27: [0, 1, [22, 30]], 28: [0, 1, 22, 23],
  3867. 29: [0, 1, [22, 32]],
  3868. 31: [0, 2, 3, [22, 24]],
  3869. 34: [0, [21, 23]],
  3870. 33: [0, 21, [23, 25]],
  3871. 35: [0, [21, 28]]
  3872. },
  3873. 54: {
  3874. 0: [0],
  3875. 1: [[0, 2], [21, 27]],
  3876. 21: [0, [21, 29], 32, 33],
  3877. 22: [0, [21, 29], [31, 33]],
  3878. 23: [0, 1, [22, 38]],
  3879. 24: [0, [21, 31]],
  3880. 25: [0, [21, 27]],
  3881. 26: [0, [21, 27]]
  3882. },
  3883. 61: {
  3884. 0: [0],
  3885. 1: [[0, 4], [11, 16], 22, [24, 26]],
  3886. 2: [[0, 4], 22],
  3887. 3: [[0, 4], [21, 24], [26, 31]],
  3888. 4: [[0, 4], [22, 31], 81],
  3889. 5: [[0, 2], [21, 28], 81, 82],
  3890. 6: [[0, 2], [21, 32]],
  3891. 7: [[0, 2], [21, 30]],
  3892. 8: [[0, 2], [21, 31]],
  3893. 9: [[0, 2], [21, 29]],
  3894. 10: [[0, 2], [21, 26]]
  3895. },
  3896. 62: {
  3897. 0: [0],
  3898. 1: [[0, 5], 11, [21, 23]],
  3899. 2: [0, 1],
  3900. 3: [[0, 2], 21],
  3901. 4: [[0, 3], [21, 23]],
  3902. 5: [[0, 3], [21, 25]],
  3903. 6: [[0, 2], [21, 23]],
  3904. 7: [[0, 2], [21, 25]],
  3905. 8: [[0, 2], [21, 26]],
  3906. 9: [[0, 2], [21, 24], 81, 82],
  3907. 10: [[0, 2], [21, 27]],
  3908. 11: [[0, 2], [21, 26]],
  3909. 12: [[0, 2], [21, 28]],
  3910. 24: [0, 21, [24, 29]],
  3911. 26: [0, 21, [23, 30]],
  3912. 29: [0, 1, [21, 27]],
  3913. 30: [0, 1, [21, 27]]
  3914. },
  3915. 63: {
  3916. 0: [0],
  3917. 1: [[0, 5], [21, 23]],
  3918. 2: [0, 2, [21, 25]],
  3919. 21: [0, [21, 23], [26, 28]],
  3920. 22: [0, [21, 24]],
  3921. 23: [0, [21, 24]],
  3922. 25: [0, [21, 25]],
  3923. 26: [0, [21, 26]],
  3924. 27: [0, 1, [21, 26]],
  3925. 28: [[0, 2], [21, 23]]
  3926. },
  3927. 64: {
  3928. 0: [0],
  3929. 1: [0, 1, [4, 6], 21, 22, 81],
  3930. 2: [[0, 3], 5, [21, 23]],
  3931. 3: [[0, 3], [21, 24], 81],
  3932. 4: [[0, 2], [21, 25]],
  3933. 5: [[0, 2], 21, 22]
  3934. },
  3935. 65: {
  3936. 0: [0],
  3937. 1: [[0, 9], 21],
  3938. 2: [[0, 5]],
  3939. 21: [0, 1, 22, 23],
  3940. 22: [0, 1, 22, 23],
  3941. 23: [[0, 3], [23, 25], 27, 28],
  3942. 28: [0, 1, [22, 29]],
  3943. 29: [0, 1, [22, 29]],
  3944. 30: [0, 1, [22, 24]], 31: [0, 1, [21, 31]],
  3945. 32: [0, 1, [21, 27]],
  3946. 40: [0, 2, 3, [21, 28]],
  3947. 42: [[0, 2], 21, [23, 26]],
  3948. 43: [0, 1, [21, 26]],
  3949. 90: [[0, 4]], 27: [[0, 2], 22, 23]
  3950. },
  3951. 71: { 0: [0] },
  3952. 81: { 0: [0] },
  3953. 82: { 0: [0] }
  3954. };
  3955. var provincial = parseInt(value.substr(0, 2), 10),
  3956. prefectural = parseInt(value.substr(2, 2), 10),
  3957. county = parseInt(value.substr(4, 2), 10);
  3958. if (!adminDivisionCodes[provincial] || !adminDivisionCodes[provincial][prefectural]) {
  3959. return false;
  3960. }
  3961. var inRange = false,
  3962. rangeDef = adminDivisionCodes[provincial][prefectural];
  3963. for (var i = 0; i < rangeDef.length; i++) {
  3964. if (($.isArray(rangeDef[i]) && rangeDef[i][0] <= county && county <= rangeDef[i][1])
  3965. || (!$.isArray(rangeDef[i]) && county === rangeDef[i]))
  3966. {
  3967. inRange = true;
  3968. break;
  3969. }
  3970. }
  3971. if (!inRange) {
  3972. return false;
  3973. }
  3974. // Check date of birth
  3975. var dob;
  3976. if (value.length === 18) {
  3977. dob = value.substr(6, 8);
  3978. } else /* length == 15 */ {
  3979. dob = '19' + value.substr(6, 6);
  3980. }
  3981. var year = parseInt(dob.substr(0, 4), 10),
  3982. month = parseInt(dob.substr(4, 2), 10),
  3983. day = parseInt(dob.substr(6, 2), 10);
  3984. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3985. return false;
  3986. }
  3987. // Check checksum (18-digit system only)
  3988. if (value.length === 18) {
  3989. var sum = 0,
  3990. weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  3991. for (i = 0; i < 17; i++) {
  3992. sum += parseInt(value.charAt(i), 10) * weight[i];
  3993. }
  3994. sum = (12 - (sum % 11)) % 11;
  3995. var checksum = (value.charAt(17).toUpperCase() !== 'X') ? parseInt(value.charAt(17), 10) : 10;
  3996. return checksum === sum;
  3997. }
  3998. return true;
  3999. },
  4000. /**
  4001. * Validate Czech national identification number (RC)
  4002. * Examples:
  4003. * - Valid: 7103192745, 991231123
  4004. * - Invalid: 1103492745, 590312123
  4005. *
  4006. * @param {String} value The ID
  4007. * @returns {Boolean}
  4008. */
  4009. _cz: function(value) {
  4010. if (!/^\d{9,10}$/.test(value)) {
  4011. return false;
  4012. }
  4013. var year = 1900 + parseInt(value.substr(0, 2), 10),
  4014. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  4015. day = parseInt(value.substr(4, 2), 10);
  4016. if (value.length === 9) {
  4017. if (year >= 1980) {
  4018. year -= 100;
  4019. }
  4020. if (year > 1953) {
  4021. return false;
  4022. }
  4023. } else if (year < 1954) {
  4024. year += 100;
  4025. }
  4026. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4027. return false;
  4028. }
  4029. // Check that the birth date is not in the future
  4030. if (value.length === 10) {
  4031. var check = parseInt(value.substr(0, 9), 10) % 11;
  4032. if (year < 1985) {
  4033. check = check % 10;
  4034. }
  4035. return (check + '' === value.substr(9, 1));
  4036. }
  4037. return true;
  4038. },
  4039. /**
  4040. * Validate Danish Personal Identification number (CPR)
  4041. * Examples:
  4042. * - Valid: 2110625629, 211062-5629
  4043. * - Invalid: 511062-5629
  4044. *
  4045. * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  4046. * @param {String} value The ID
  4047. * @returns {Boolean}
  4048. */
  4049. _dk: function(value) {
  4050. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  4051. return false;
  4052. }
  4053. value = value.replace(/-/g, '');
  4054. var day = parseInt(value.substr(0, 2), 10),
  4055. month = parseInt(value.substr(2, 2), 10),
  4056. year = parseInt(value.substr(4, 2), 10);
  4057. switch (true) {
  4058. case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
  4059. year += 1800;
  4060. break;
  4061. case ('0123'.indexOf(value.charAt(6)) !== -1):
  4062. case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
  4063. year += 1900;
  4064. break;
  4065. default:
  4066. year += 2000;
  4067. break;
  4068. }
  4069. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  4070. },
  4071. /**
  4072. * Validate Estonian Personal Identification Code (isikukood)
  4073. * Examples:
  4074. * - Valid: 37605030299
  4075. *
  4076. * @see http://et.wikipedia.org/wiki/Isikukood
  4077. * @param {String} value The ID
  4078. * @returns {Boolean}
  4079. */
  4080. _ee: function(value) {
  4081. // Use the same format as Lithuanian Personal Code
  4082. return this._lt(value);
  4083. },
  4084. /**
  4085. * Validate Spanish personal identity code (DNI)
  4086. * Support i) DNI (for Spanish citizens) and ii) NIE (for foreign people)
  4087. *
  4088. * Examples:
  4089. * - Valid: i) 54362315K, 54362315-K; ii) X2482300W, X-2482300W, X-2482300-W
  4090. * - Invalid: i) 54362315Z; ii) X-2482300A
  4091. *
  4092. * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  4093. * @param {String} value The ID
  4094. * @returns {Boolean}
  4095. */
  4096. _es: function(value) {
  4097. if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]$/.test(value) // DNI
  4098. && !/^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-Z]$/.test(value)) { // NIE
  4099. return false;
  4100. }
  4101. value = value.replace(/-/g, '');
  4102. var index = 'XYZ'.indexOf(value.charAt(0));
  4103. if (index !== -1) {
  4104. // It is NIE number
  4105. value = index + value.substr(1) + '';
  4106. }
  4107. var check = parseInt(value.substr(0, 8), 10);
  4108. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4109. return (check === value.substr(8, 1));
  4110. },
  4111. /**
  4112. * Validate Finnish Personal Identity Code (HETU)
  4113. * Examples:
  4114. * - Valid: 311280-888Y, 131052-308T
  4115. * - Invalid: 131052-308U, 310252-308Y
  4116. *
  4117. * @param {String} value The ID
  4118. * @returns {Boolean}
  4119. */
  4120. _fi: function(value) {
  4121. if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  4122. return false;
  4123. }
  4124. var day = parseInt(value.substr(0, 2), 10),
  4125. month = parseInt(value.substr(2, 2), 10),
  4126. year = parseInt(value.substr(4, 2), 10),
  4127. centuries = {
  4128. '+': 1800,
  4129. '-': 1900,
  4130. 'A': 2000
  4131. };
  4132. year = centuries[value.charAt(6)] + year;
  4133. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4134. return false;
  4135. }
  4136. var individual = parseInt(value.substr(7, 3), 10);
  4137. if (individual < 2) {
  4138. return false;
  4139. }
  4140. var n = value.substr(0, 6) + value.substr(7, 3) + '';
  4141. n = parseInt(n, 10);
  4142. return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
  4143. },
  4144. /**
  4145. * Validate Croatian personal identification number (OIB)
  4146. * Examples:
  4147. * - Valid: 33392005961
  4148. * - Invalid: 33392005962
  4149. *
  4150. * @param {String} value The ID
  4151. * @returns {Boolean}
  4152. */
  4153. _hr: function(value) {
  4154. if (!/^[0-9]{11}$/.test(value)) {
  4155. return false;
  4156. }
  4157. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  4158. },
  4159. /**
  4160. * Validate Irish Personal Public Service Number (PPS)
  4161. * Examples:
  4162. * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  4163. * - Invalid: 6433435E, 6433435VH
  4164. *
  4165. * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  4166. * @param {String} value The ID
  4167. * @returns {Boolean}
  4168. */
  4169. _ie: function(value) {
  4170. if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  4171. return false;
  4172. }
  4173. var getCheckDigit = function(value) {
  4174. while (value.length < 7) {
  4175. value = '0' + value;
  4176. }
  4177. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  4178. sum = 0;
  4179. for (var i = 0; i < 7; i++) {
  4180. sum += parseInt(value.charAt(i), 10) * (8 - i);
  4181. }
  4182. sum += 9 * alphabet.indexOf(value.substr(7));
  4183. return alphabet[sum % 23];
  4184. };
  4185. // 2013 format
  4186. if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
  4187. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  4188. }
  4189. // The old format
  4190. else {
  4191. return value.charAt(7) === getCheckDigit(value.substr(0, 7));
  4192. }
  4193. },
  4194. /**
  4195. * Validate Iceland national identification number (Kennitala)
  4196. * Examples:
  4197. * - Valid: 120174-3399, 1201743399, 0902862349
  4198. *
  4199. * @see http://en.wikipedia.org/wiki/Kennitala
  4200. * @param {String} value The ID
  4201. * @returns {Boolean}
  4202. */
  4203. _is: function(value) {
  4204. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  4205. return false;
  4206. }
  4207. value = value.replace(/-/g, '');
  4208. var day = parseInt(value.substr(0, 2), 10),
  4209. month = parseInt(value.substr(2, 2), 10),
  4210. year = parseInt(value.substr(4, 2), 10),
  4211. century = parseInt(value.charAt(9), 10);
  4212. year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
  4213. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  4214. return false;
  4215. }
  4216. // Validate the check digit
  4217. var sum = 0,
  4218. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  4219. for (var i = 0; i < 8; i++) {
  4220. sum += parseInt(value.charAt(i), 10) * weight[i];
  4221. }
  4222. sum = 11 - sum % 11;
  4223. return (sum + '' === value.charAt(8));
  4224. },
  4225. /**
  4226. * Validate Lithuanian Personal Code (Asmens kodas)
  4227. * Examples:
  4228. * - Valid: 38703181745
  4229. * - Invalid: 38703181746, 78703181745, 38703421745
  4230. *
  4231. * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  4232. * @see http://www.adomas.org/midi2007/pcode.html
  4233. * @param {String} value The ID
  4234. * @returns {Boolean}
  4235. */
  4236. _lt: function(value) {
  4237. if (!/^[0-9]{11}$/.test(value)) {
  4238. return false;
  4239. }
  4240. var gender = parseInt(value.charAt(0), 10),
  4241. year = parseInt(value.substr(1, 2), 10),
  4242. month = parseInt(value.substr(3, 2), 10),
  4243. day = parseInt(value.substr(5, 2), 10),
  4244. century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  4245. year = century * 100 + year;
  4246. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  4247. return false;
  4248. }
  4249. // Validate the check digit
  4250. var sum = 0,
  4251. weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  4252. for (var i = 0; i < 10; i++) {
  4253. sum += parseInt(value.charAt(i), 10) * weight[i];
  4254. }
  4255. sum = sum % 11;
  4256. if (sum !== 10) {
  4257. return sum + '' === value.charAt(10);
  4258. }
  4259. // Re-calculate the check digit
  4260. sum = 0;
  4261. weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  4262. for (i = 0; i < 10; i++) {
  4263. sum += parseInt(value.charAt(i), 10) * weight[i];
  4264. }
  4265. sum = sum % 11;
  4266. if (sum === 10) {
  4267. sum = 0;
  4268. }
  4269. return (sum + '' === value.charAt(10));
  4270. },
  4271. /**
  4272. * Validate Latvian Personal Code (Personas kods)
  4273. * Examples:
  4274. * - Valid: 161175-19997, 16117519997
  4275. * - Invalid: 161375-19997
  4276. *
  4277. * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  4278. * @param {String} value The ID
  4279. * @returns {Boolean}
  4280. */
  4281. _lv: function(value) {
  4282. if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  4283. return false;
  4284. }
  4285. value = value.replace(/\D/g, '');
  4286. // Check birth date
  4287. var day = parseInt(value.substr(0, 2), 10),
  4288. month = parseInt(value.substr(2, 2), 10),
  4289. year = parseInt(value.substr(4, 2), 10);
  4290. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  4291. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  4292. return false;
  4293. }
  4294. // Check personal code
  4295. var sum = 0,
  4296. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  4297. for (var i = 0; i < 10; i++) {
  4298. sum += parseInt(value.charAt(i), 10) * weight[i];
  4299. }
  4300. sum = (sum + 1) % 11 % 10;
  4301. return (sum + '' === value.charAt(10));
  4302. },
  4303. /**
  4304. * Validate Dutch national identification number (BSN)
  4305. * Examples:
  4306. * - Valid: 111222333, 941331490, 9413.31.490
  4307. * - Invalid: 111252333
  4308. *
  4309. * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  4310. * @param {String} value The ID
  4311. * @returns {Boolean}
  4312. */
  4313. _nl: function(value) {
  4314. while (value.length < 9) {
  4315. value = '0' + value;
  4316. }
  4317. if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  4318. return false;
  4319. }
  4320. value = value.replace(/\./g, '');
  4321. if (parseInt(value, 10) === 0) {
  4322. return false;
  4323. }
  4324. var sum = 0,
  4325. length = value.length;
  4326. for (var i = 0; i < length - 1; i++) {
  4327. sum += (9 - i) * parseInt(value.charAt(i), 10);
  4328. }
  4329. sum = sum % 11;
  4330. if (sum === 10) {
  4331. sum = 0;
  4332. }
  4333. return (sum + '' === value.charAt(length - 1));
  4334. },
  4335. /**
  4336. * Validate Romanian numerical personal code (CNP)
  4337. * Examples:
  4338. * - Valid: 1630615123457, 1800101221144
  4339. * - Invalid: 8800101221144, 1632215123457, 1630615123458
  4340. *
  4341. * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  4342. * @param {String} value The ID
  4343. * @returns {Boolean}
  4344. */
  4345. _ro: function(value) {
  4346. if (!/^[0-9]{13}$/.test(value)) {
  4347. return false;
  4348. }
  4349. var gender = parseInt(value.charAt(0), 10);
  4350. if (gender === 0 || gender === 7 || gender === 8) {
  4351. return false;
  4352. }
  4353. // Determine the date of birth
  4354. var year = parseInt(value.substr(1, 2), 10),
  4355. month = parseInt(value.substr(3, 2), 10),
  4356. day = parseInt(value.substr(5, 2), 10),
  4357. // The year of date is determined base on the gender
  4358. centuries = {
  4359. '1': 1900, // Male born between 1900 and 1999
  4360. '2': 1900, // Female born between 1900 and 1999
  4361. '3': 1800, // Male born between 1800 and 1899
  4362. '4': 1800, // Female born between 1800 and 1899
  4363. '5': 2000, // Male born after 2000
  4364. '6': 2000 // Female born after 2000
  4365. };
  4366. if (day > 31 && month > 12) {
  4367. return false;
  4368. }
  4369. if (gender !== 9) {
  4370. year = centuries[gender + ''] + year;
  4371. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4372. return false;
  4373. }
  4374. }
  4375. // Validate the check digit
  4376. var sum = 0,
  4377. weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  4378. length = value.length;
  4379. for (var i = 0; i < length - 1; i++) {
  4380. sum += parseInt(value.charAt(i), 10) * weight[i];
  4381. }
  4382. sum = sum % 11;
  4383. if (sum === 10) {
  4384. sum = 1;
  4385. }
  4386. return (sum + '' === value.charAt(length - 1));
  4387. },
  4388. /**
  4389. * Validate Swedish personal identity number (personnummer)
  4390. * Examples:
  4391. * - Valid: 8112289874, 811228-9874, 811228+9874
  4392. * - Invalid: 811228-9873
  4393. *
  4394. * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  4395. * @param {String} value The ID
  4396. * @returns {Boolean}
  4397. */
  4398. _se: function(value) {
  4399. if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  4400. return false;
  4401. }
  4402. value = value.replace(/[^0-9]/g, '');
  4403. var year = parseInt(value.substr(0, 2), 10) + 1900,
  4404. month = parseInt(value.substr(2, 2), 10),
  4405. day = parseInt(value.substr(4, 2), 10);
  4406. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4407. return false;
  4408. }
  4409. // Validate the last check digit
  4410. return $.fn.bootstrapValidator.helpers.luhn(value);
  4411. },
  4412. /**
  4413. * Validate Slovak national identifier number (RC)
  4414. * Examples:
  4415. * - Valid: 7103192745, 991231123
  4416. * - Invalid: 7103192746, 1103492745
  4417. *
  4418. * @param {String} value The ID
  4419. * @returns {Boolean}
  4420. */
  4421. _sk: function(value) {
  4422. // Slovakia uses the same format as Czech Republic
  4423. return this._cz(value);
  4424. },
  4425. /**
  4426. * Validate San Marino citizen number
  4427. *
  4428. * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  4429. * @param {String} value The ID
  4430. * @returns {Boolean}
  4431. */
  4432. _sm: function(value) {
  4433. return /^\d{5}$/.test(value);
  4434. },
  4435. /**
  4436. * Validate Thailand citizen number
  4437. * Examples:
  4438. * - Valid: 7145620509547, 3688699975685, 2368719339716
  4439. * - Invalid: 1100800092310
  4440. *
  4441. * @see http://en.wikipedia.org/wiki/National_identification_number#Thailand
  4442. * @param {String} value The ID
  4443. * @returns {Boolean}
  4444. */
  4445. _th: function(value) {
  4446. if (value.length !== 13) {
  4447. return false;
  4448. }
  4449. var sum = 0;
  4450. for (var i = 0; i < 12; i++) {
  4451. sum += parseInt(value.charAt(i), 10) * (13 - i);
  4452. }
  4453. return (11 - sum % 11) % 10 === parseInt(value.charAt(12), 10);
  4454. },
  4455. /**
  4456. * Validate South African ID
  4457. * Example:
  4458. * - Valid: 8001015009087
  4459. * - Invalid: 8001015009287, 8001015009086
  4460. *
  4461. * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  4462. * @param {String} value The ID
  4463. * @returns {Boolean}
  4464. */
  4465. _za: function(value) {
  4466. if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  4467. return false;
  4468. }
  4469. var year = parseInt(value.substr(0, 2), 10),
  4470. currentYear = new Date().getFullYear() % 100,
  4471. month = parseInt(value.substr(2, 2), 10),
  4472. day = parseInt(value.substr(4, 2), 10);
  4473. year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  4474. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4475. return false;
  4476. }
  4477. // Validate the last check digit
  4478. return $.fn.bootstrapValidator.helpers.luhn(value);
  4479. }
  4480. };
  4481. }(window.jQuery));
  4482. ;(function($) {
  4483. $.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
  4484. 'default': 'Please enter the same value'
  4485. });
  4486. $.fn.bootstrapValidator.validators.identical = {
  4487. html5Attributes: {
  4488. message: 'message',
  4489. field: 'field'
  4490. },
  4491. /**
  4492. * Check if input value equals to value of particular one
  4493. *
  4494. * @param {BootstrapValidator} validator The validator plugin instance
  4495. * @param {jQuery} $field Field element
  4496. * @param {Object} options Consists of the following key:
  4497. * - field: The name of field that will be used to compare with current one
  4498. * @returns {Boolean}
  4499. */
  4500. validate: function(validator, $field, options) {
  4501. var value = $field.val();
  4502. if (value === '') {
  4503. return true;
  4504. }
  4505. var compareWith = validator.getFieldElements(options.field);
  4506. if (compareWith === null || compareWith.length === 0) {
  4507. return true;
  4508. }
  4509. if (value === compareWith.val()) {
  4510. validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
  4511. return true;
  4512. } else {
  4513. return false;
  4514. }
  4515. }
  4516. };
  4517. }(window.jQuery));
  4518. ;(function($) {
  4519. $.fn.bootstrapValidator.i18n.imei = $.extend($.fn.bootstrapValidator.i18n.imei || {}, {
  4520. 'default': 'Please enter a valid IMEI number'
  4521. });
  4522. $.fn.bootstrapValidator.validators.imei = {
  4523. /**
  4524. * Validate IMEI (International Mobile Station Equipment Identity)
  4525. * Examples:
  4526. * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  4527. * - Invalid: 490154203237517
  4528. *
  4529. * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  4530. * @param {BootstrapValidator} validator The validator plugin instance
  4531. * @param {jQuery} $field Field element
  4532. * @param {Object} options Can consist of the following keys:
  4533. * - message: The invalid message
  4534. * @returns {Boolean}
  4535. */
  4536. validate: function(validator, $field, options) {
  4537. var value = $field.val();
  4538. if (value === '') {
  4539. return true;
  4540. }
  4541. switch (true) {
  4542. case /^\d{15}$/.test(value):
  4543. case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  4544. case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  4545. value = value.replace(/[^0-9]/g, '');
  4546. return $.fn.bootstrapValidator.helpers.luhn(value);
  4547. case /^\d{14}$/.test(value):
  4548. case /^\d{16}$/.test(value):
  4549. case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  4550. case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  4551. return true;
  4552. default:
  4553. return false;
  4554. }
  4555. }
  4556. };
  4557. }(window.jQuery));
  4558. ;(function($) {
  4559. $.fn.bootstrapValidator.i18n.imo = $.extend($.fn.bootstrapValidator.i18n.imo || {}, {
  4560. 'default': 'Please enter a valid IMO number'
  4561. });
  4562. $.fn.bootstrapValidator.validators.imo = {
  4563. /**
  4564. * Validate IMO (International Maritime Organization)
  4565. * Examples:
  4566. * - Valid: IMO 8814275, IMO 9176187
  4567. * - Invalid: IMO 8814274
  4568. *
  4569. * @see http://en.wikipedia.org/wiki/IMO_Number
  4570. * @param {BootstrapValidator} validator The validator plugin instance
  4571. * @param {jQuery} $field Field element
  4572. * @param {Object} options Can consist of the following keys:
  4573. * - message: The invalid message
  4574. * @returns {Boolean}
  4575. */
  4576. validate: function(validator, $field, options) {
  4577. var value = $field.val();
  4578. if (value === '') {
  4579. return true;
  4580. }
  4581. if (!/^IMO \d{7}$/i.test(value)) {
  4582. return false;
  4583. }
  4584. // Grab just the digits
  4585. var sum = 0,
  4586. digits = value.replace(/^.*(\d{7})$/, '$1');
  4587. // Go over each char, multiplying by the inverse of it's position
  4588. // IMO 9176187
  4589. // (9 * 7) + (1 * 6) + (7 * 5) + (6 * 4) + (1 * 3) + (8 * 2) = 147
  4590. // Take the last digit of that, that's the check digit (7)
  4591. for (var i = 6; i >= 1; i--) {
  4592. sum += (digits.slice((6 - i), -i) * (i + 1));
  4593. }
  4594. return sum % 10 === parseInt(digits.charAt(6), 10);
  4595. }
  4596. };
  4597. }(window.jQuery));
  4598. ;(function($) {
  4599. $.fn.bootstrapValidator.i18n.integer = $.extend($.fn.bootstrapValidator.i18n.integer || {}, {
  4600. 'default': 'Please enter a valid number'
  4601. });
  4602. $.fn.bootstrapValidator.validators.integer = {
  4603. enableByHtml5: function($field) {
  4604. return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
  4605. },
  4606. /**
  4607. * Return true if the input value is an integer
  4608. *
  4609. * @param {BootstrapValidator} validator The validator plugin instance
  4610. * @param {jQuery} $field Field element
  4611. * @param {Object} options Can consist of the following key:
  4612. * - message: The invalid message
  4613. * @returns {Boolean}
  4614. */
  4615. validate: function(validator, $field, options) {
  4616. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  4617. return false;
  4618. }
  4619. var value = $field.val();
  4620. if (value === '') {
  4621. return true;
  4622. }
  4623. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  4624. }
  4625. };
  4626. }(window.jQuery));
  4627. ;(function($) {
  4628. $.fn.bootstrapValidator.i18n.ip = $.extend($.fn.bootstrapValidator.i18n.ip || {}, {
  4629. 'default': 'Please enter a valid IP address',
  4630. ipv4: 'Please enter a valid IPv4 address',
  4631. ipv6: 'Please enter a valid IPv6 address'
  4632. });
  4633. $.fn.bootstrapValidator.validators.ip = {
  4634. html5Attributes: {
  4635. message: 'message',
  4636. ipv4: 'ipv4',
  4637. ipv6: 'ipv6'
  4638. },
  4639. /**
  4640. * Return true if the input value is a IP address.
  4641. *
  4642. * @param {BootstrapValidator} validator The validator plugin instance
  4643. * @param {jQuery} $field Field element
  4644. * @param {Object} options Can consist of the following keys:
  4645. * - ipv4: Enable IPv4 validator, default to true
  4646. * - ipv6: Enable IPv6 validator, default to true
  4647. * - message: The invalid message
  4648. * @returns {Boolean|Object}
  4649. */
  4650. validate: function(validator, $field, options) {
  4651. var value = $field.val();
  4652. if (value === '') {
  4653. return true;
  4654. }
  4655. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  4656. 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]?)$/,
  4657. 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*$/,
  4658. valid = false,
  4659. message;
  4660. switch (true) {
  4661. case (options.ipv4 && !options.ipv6):
  4662. valid = ipv4Regex.test(value);
  4663. message = options.message || $.fn.bootstrapValidator.i18n.ip.ipv4;
  4664. break;
  4665. case (!options.ipv4 && options.ipv6):
  4666. valid = ipv6Regex.test(value);
  4667. message = options.message || $.fn.bootstrapValidator.i18n.ip.ipv6;
  4668. break;
  4669. case (options.ipv4 && options.ipv6):
  4670. /* falls through */
  4671. default:
  4672. valid = ipv4Regex.test(value) || ipv6Regex.test(value);
  4673. message = options.message || $.fn.bootstrapValidator.i18n.ip['default'];
  4674. break;
  4675. }
  4676. return {
  4677. valid: valid,
  4678. message: message
  4679. };
  4680. }
  4681. };
  4682. }(window.jQuery));;(function($) {
  4683. $.fn.bootstrapValidator.i18n.isbn = $.extend($.fn.bootstrapValidator.i18n.isbn || {}, {
  4684. 'default': 'Please enter a valid ISBN number'
  4685. });
  4686. $.fn.bootstrapValidator.validators.isbn = {
  4687. /**
  4688. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  4689. * Examples:
  4690. * - Valid:
  4691. * 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
  4692. * ISBN 13: 978-0-306-40615-7
  4693. * - Invalid:
  4694. * ISBN 10: 99921-58-10-6
  4695. * ISBN 13: 978-0-306-40615-6
  4696. *
  4697. * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  4698. * @param {BootstrapValidator} validator The validator plugin instance
  4699. * @param {jQuery} $field Field element
  4700. * @param {Object} [options] Can consist of the following keys:
  4701. * - message: The invalid message
  4702. * @returns {Boolean}
  4703. */
  4704. validate: function(validator, $field, options) {
  4705. var value = $field.val();
  4706. if (value === '') {
  4707. return true;
  4708. }
  4709. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  4710. // Groups are separated by a hyphen or a space
  4711. var type;
  4712. switch (true) {
  4713. case /^\d{9}[\dX]$/.test(value):
  4714. case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  4715. case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  4716. type = 'ISBN10';
  4717. break;
  4718. case /^(978|979)\d{9}[\dX]$/.test(value):
  4719. case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  4720. case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  4721. type = 'ISBN13';
  4722. break;
  4723. default:
  4724. return false;
  4725. }
  4726. // Replace all special characters except digits and X
  4727. value = value.replace(/[^0-9X]/gi, '');
  4728. var chars = value.split(''),
  4729. length = chars.length,
  4730. sum = 0,
  4731. i,
  4732. checksum;
  4733. switch (type) {
  4734. case 'ISBN10':
  4735. sum = 0;
  4736. for (i = 0; i < length - 1; i++) {
  4737. sum += parseInt(chars[i], 10) * (10 - i);
  4738. }
  4739. checksum = 11 - (sum % 11);
  4740. if (checksum === 11) {
  4741. checksum = 0;
  4742. } else if (checksum === 10) {
  4743. checksum = 'X';
  4744. }
  4745. return (checksum + '' === chars[length - 1]);
  4746. case 'ISBN13':
  4747. sum = 0;
  4748. for (i = 0; i < length - 1; i++) {
  4749. sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
  4750. }
  4751. checksum = 10 - (sum % 10);
  4752. if (checksum === 10) {
  4753. checksum = '0';
  4754. }
  4755. return (checksum + '' === chars[length - 1]);
  4756. default:
  4757. return false;
  4758. }
  4759. }
  4760. };
  4761. }(window.jQuery));
  4762. ;(function($) {
  4763. $.fn.bootstrapValidator.i18n.isin = $.extend($.fn.bootstrapValidator.i18n.isin || {}, {
  4764. 'default': 'Please enter a valid ISIN number'
  4765. });
  4766. $.fn.bootstrapValidator.validators.isin = {
  4767. // Available country codes
  4768. // See http://isin.net/country-codes/
  4769. 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',
  4770. /**
  4771. * Validate an ISIN (International Securities Identification Number)
  4772. * Examples:
  4773. * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  4774. * - Invalid: US0378331004, AA0000XVGZA3
  4775. *
  4776. * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  4777. * @param {BootstrapValidator} validator The validator plugin instance
  4778. * @param {jQuery} $field Field element
  4779. * @param {Object} options Can consist of the following keys:
  4780. * - message: The invalid message
  4781. * @returns {Boolean}
  4782. */
  4783. validate: function(validator, $field, options) {
  4784. var value = $field.val();
  4785. if (value === '') {
  4786. return true;
  4787. }
  4788. value = value.toUpperCase();
  4789. var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  4790. if (!regex.test(value)) {
  4791. return false;
  4792. }
  4793. var converted = '',
  4794. length = value.length;
  4795. // Convert letters to number
  4796. for (var i = 0; i < length - 1; i++) {
  4797. var c = value.charCodeAt(i);
  4798. converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  4799. }
  4800. var digits = '',
  4801. n = converted.length,
  4802. group = (n % 2 !== 0) ? 0 : 1;
  4803. for (i = 0; i < n; i++) {
  4804. digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
  4805. }
  4806. var sum = 0;
  4807. for (i = 0; i < digits.length; i++) {
  4808. sum += parseInt(digits.charAt(i), 10);
  4809. }
  4810. sum = (10 - (sum % 10)) % 10;
  4811. return sum + '' === value.charAt(length - 1);
  4812. }
  4813. };
  4814. }(window.jQuery));
  4815. ;(function($) {
  4816. $.fn.bootstrapValidator.i18n.ismn = $.extend($.fn.bootstrapValidator.i18n.ismn || {}, {
  4817. 'default': 'Please enter a valid ISMN number'
  4818. });
  4819. $.fn.bootstrapValidator.validators.ismn = {
  4820. /**
  4821. * Validate ISMN (International Standard Music Number)
  4822. * Examples:
  4823. * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  4824. * - Invalid: 9790060115614
  4825. *
  4826. * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  4827. * @param {BootstrapValidator} validator The validator plugin instance
  4828. * @param {jQuery} $field Field element
  4829. * @param {Object} options Can consist of the following keys:
  4830. * - message: The invalid message
  4831. * @returns {Boolean}
  4832. */
  4833. validate: function(validator, $field, options) {
  4834. var value = $field.val();
  4835. if (value === '') {
  4836. return true;
  4837. }
  4838. // Groups are separated by a hyphen or a space
  4839. var type;
  4840. switch (true) {
  4841. case /^M\d{9}$/.test(value):
  4842. case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  4843. case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  4844. type = 'ISMN10';
  4845. break;
  4846. case /^9790\d{9}$/.test(value):
  4847. case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  4848. case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  4849. type = 'ISMN13';
  4850. break;
  4851. default:
  4852. return false;
  4853. }
  4854. if ('ISMN10' === type) {
  4855. value = '9790' + value.substr(1);
  4856. }
  4857. // Replace all special characters except digits
  4858. value = value.replace(/[^0-9]/gi, '');
  4859. var length = value.length,
  4860. sum = 0,
  4861. weight = [1, 3];
  4862. for (var i = 0; i < length - 1; i++) {
  4863. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  4864. }
  4865. sum = 10 - sum % 10;
  4866. return (sum + '' === value.charAt(length - 1));
  4867. }
  4868. };
  4869. }(window.jQuery));
  4870. ;(function($) {
  4871. $.fn.bootstrapValidator.i18n.issn = $.extend($.fn.bootstrapValidator.i18n.issn || {}, {
  4872. 'default': 'Please enter a valid ISSN number'
  4873. });
  4874. $.fn.bootstrapValidator.validators.issn = {
  4875. /**
  4876. * Validate ISSN (International Standard Serial Number)
  4877. * Examples:
  4878. * - Valid: 0378-5955, 0024-9319, 0032-1478
  4879. * - Invalid: 0032-147X
  4880. *
  4881. * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  4882. * @param {BootstrapValidator} validator The validator plugin instance
  4883. * @param {jQuery} $field Field element
  4884. * @param {Object} options Can consist of the following keys:
  4885. * - message: The invalid message
  4886. * @returns {Boolean}
  4887. */
  4888. validate: function(validator, $field, options) {
  4889. var value = $field.val();
  4890. if (value === '') {
  4891. return true;
  4892. }
  4893. // Groups are separated by a hyphen or a space
  4894. if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  4895. return false;
  4896. }
  4897. // Replace all special characters except digits and X
  4898. value = value.replace(/[^0-9X]/gi, '');
  4899. var chars = value.split(''),
  4900. length = chars.length,
  4901. sum = 0;
  4902. if (chars[7] === 'X') {
  4903. chars[7] = 10;
  4904. }
  4905. for (var i = 0; i < length; i++) {
  4906. sum += parseInt(chars[i], 10) * (8 - i);
  4907. }
  4908. return (sum % 11 === 0);
  4909. }
  4910. };
  4911. }(window.jQuery));
  4912. ;(function($) {
  4913. $.fn.bootstrapValidator.i18n.lessThan = $.extend($.fn.bootstrapValidator.i18n.lessThan || {}, {
  4914. 'default': 'Please enter a value less than or equal to %s',
  4915. notInclusive: 'Please enter a value less than %s'
  4916. });
  4917. $.fn.bootstrapValidator.validators.lessThan = {
  4918. html5Attributes: {
  4919. message: 'message',
  4920. value: 'value',
  4921. inclusive: 'inclusive'
  4922. },
  4923. enableByHtml5: function($field) {
  4924. var type = $field.attr('type'),
  4925. max = $field.attr('max');
  4926. if (max && type !== 'date') {
  4927. return {
  4928. value: max
  4929. };
  4930. }
  4931. return false;
  4932. },
  4933. /**
  4934. * Return true if the input value is less than or equal to given number
  4935. *
  4936. * @param {BootstrapValidator} validator The validator plugin instance
  4937. * @param {jQuery} $field Field element
  4938. * @param {Object} options Can consist of the following keys:
  4939. * - value: The number used to compare to. It can be
  4940. * - A number
  4941. * - Name of field which its value defines the number
  4942. * - Name of callback function that returns the number
  4943. * - A callback function that returns the number
  4944. *
  4945. * - inclusive [optional]: Can be true or false. Default is true
  4946. * - message: The invalid message
  4947. * @returns {Boolean|Object}
  4948. */
  4949. validate: function(validator, $field, options) {
  4950. var value = $field.val();
  4951. if (value === '') {
  4952. return true;
  4953. }
  4954. value = value.replace(',', '.');
  4955. if (!$.isNumeric(value)) {
  4956. return false;
  4957. }
  4958. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
  4959. value = parseFloat(value);
  4960. return (options.inclusive === true || options.inclusive === undefined)
  4961. ? {
  4962. valid: value <= compareTo,
  4963. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan['default'], compareTo)
  4964. }
  4965. : {
  4966. valid: value < compareTo,
  4967. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan.notInclusive, compareTo)
  4968. };
  4969. }
  4970. };
  4971. }(window.jQuery));
  4972. ;(function($) {
  4973. $.fn.bootstrapValidator.i18n.mac = $.extend($.fn.bootstrapValidator.i18n.mac || {}, {
  4974. 'default': 'Please enter a valid MAC address'
  4975. });
  4976. $.fn.bootstrapValidator.validators.mac = {
  4977. /**
  4978. * Return true if the input value is a MAC address.
  4979. *
  4980. * @param {BootstrapValidator} validator The validator plugin instance
  4981. * @param {jQuery} $field Field element
  4982. * @param {Object} options Can consist of the following keys:
  4983. * - message: The invalid message
  4984. * @returns {Boolean}
  4985. */
  4986. validate: function(validator, $field, options) {
  4987. var value = $field.val();
  4988. if (value === '') {
  4989. return true;
  4990. }
  4991. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  4992. }
  4993. };
  4994. }(window.jQuery));
  4995. ;(function($) {
  4996. $.fn.bootstrapValidator.i18n.meid = $.extend($.fn.bootstrapValidator.i18n.meid || {}, {
  4997. 'default': 'Please enter a valid MEID number'
  4998. });
  4999. $.fn.bootstrapValidator.validators.meid = {
  5000. /**
  5001. * Validate MEID (Mobile Equipment Identifier)
  5002. * Examples:
  5003. * - Valid: 293608736500703710, 29360-87365-0070-3710, AF0123450ABCDE, AF-012345-0ABCDE
  5004. * - Invalid: 2936087365007037101
  5005. *
  5006. * @see http://en.wikipedia.org/wiki/Mobile_equipment_identifier
  5007. * @param {BootstrapValidator} validator The validator plugin instance
  5008. * @param {jQuery} $field Field element
  5009. * @param {Object} options Can consist of the following keys:
  5010. * - message: The invalid message
  5011. * @returns {Boolean}
  5012. */
  5013. validate: function(validator, $field, options) {
  5014. var value = $field.val();
  5015. if (value === '') {
  5016. return true;
  5017. }
  5018. switch (true) {
  5019. // 14 digit hex representation (no check digit)
  5020. case /^[0-9A-F]{15}$/i.test(value):
  5021. // 14 digit hex representation + dashes or spaces (no check digit)
  5022. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}[- ][0-9A-F]$/i.test(value):
  5023. // 18 digit decimal representation (no check digit)
  5024. case /^\d{19}$/.test(value):
  5025. // 18 digit decimal representation + dashes or spaces (no check digit)
  5026. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}[- ]\d$/.test(value):
  5027. // Grab the check digit
  5028. var cd = value.charAt(value.length - 1);
  5029. // Strip any non-hex chars
  5030. value = value.replace(/[- ]/g, '');
  5031. // If it's all digits, luhn base 10 is used
  5032. if (value.match(/^\d*$/i)) {
  5033. return $.fn.bootstrapValidator.helpers.luhn(value);
  5034. }
  5035. // Strip the check digit
  5036. value = value.slice(0, -1);
  5037. // Get every other char, and double it
  5038. var cdCalc = '';
  5039. for (var i = 1; i <= 13; i += 2) {
  5040. cdCalc += (parseInt(value.charAt(i), 16) * 2).toString(16);
  5041. }
  5042. // Get the sum of each char in the string
  5043. var sum = 0;
  5044. for (i = 0; i < cdCalc.length; i++) {
  5045. sum += parseInt(cdCalc.charAt(i), 16);
  5046. }
  5047. // If the last digit of the calc is 0, the check digit is 0
  5048. return (sum % 10 === 0)
  5049. ? (cd === '0')
  5050. // Subtract it from the next highest 10s number (64 goes to 70) and subtract the sum
  5051. // Double it and turn it into a hex char
  5052. : (cd === ((Math.floor((sum + 10) / 10) * 10 - sum) * 2).toString(16));
  5053. // 14 digit hex representation (no check digit)
  5054. case /^[0-9A-F]{14}$/i.test(value):
  5055. // 14 digit hex representation + dashes or spaces (no check digit)
  5056. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}$/i.test(value):
  5057. // 18 digit decimal representation (no check digit)
  5058. case /^\d{18}$/.test(value):
  5059. // 18 digit decimal representation + dashes or spaces (no check digit)
  5060. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}$/.test(value):
  5061. return true;
  5062. default:
  5063. return false;
  5064. }
  5065. }
  5066. };
  5067. }(window.jQuery));
  5068. ;(function($) {
  5069. $.fn.bootstrapValidator.i18n.notEmpty = $.extend($.fn.bootstrapValidator.i18n.notEmpty || {}, {
  5070. 'default': 'Please enter a value'
  5071. });
  5072. $.fn.bootstrapValidator.validators.notEmpty = {
  5073. enableByHtml5: function($field) {
  5074. var required = $field.attr('required') + '';
  5075. return ('required' === required || 'true' === required);
  5076. },
  5077. /**
  5078. * Check if input value is empty or not
  5079. *
  5080. * @param {BootstrapValidator} validator The validator plugin instance
  5081. * @param {jQuery} $field Field element
  5082. * @param {Object} options
  5083. * @returns {Boolean}
  5084. */
  5085. validate: function(validator, $field, options) {
  5086. var type = $field.attr('type');
  5087. if ('radio' === type || 'checkbox' === type) {
  5088. return validator
  5089. .getFieldElements($field.attr('data-bv-field'))
  5090. .filter(':checked')
  5091. .length > 0;
  5092. }
  5093. if ('number' === type && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  5094. return true;
  5095. }
  5096. return $.trim($field.val()) !== '';
  5097. }
  5098. };
  5099. }(window.jQuery));
  5100. ;(function($) {
  5101. $.fn.bootstrapValidator.i18n.numeric = $.extend($.fn.bootstrapValidator.i18n.numeric || {}, {
  5102. 'default': 'Please enter a valid float number'
  5103. });
  5104. $.fn.bootstrapValidator.validators.numeric = {
  5105. html5Attributes: {
  5106. message: 'message',
  5107. separator: 'separator'
  5108. },
  5109. enableByHtml5: function($field) {
  5110. return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
  5111. },
  5112. /**
  5113. * Validate decimal number
  5114. *
  5115. * @param {BootstrapValidator} validator The validator plugin instance
  5116. * @param {jQuery} $field Field element
  5117. * @param {Object} options Consist of key:
  5118. * - message: The invalid message
  5119. * - separator: The decimal separator. Can be "." (default), ","
  5120. * @returns {Boolean}
  5121. */
  5122. validate: function(validator, $field, options) {
  5123. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  5124. return false;
  5125. }
  5126. var value = $field.val();
  5127. if (value === '') {
  5128. return true;
  5129. }
  5130. var separator = options.separator || '.';
  5131. if (separator !== '.') {
  5132. value = value.replace(separator, '.');
  5133. }
  5134. return !isNaN(parseFloat(value)) && isFinite(value);
  5135. }
  5136. };
  5137. }(window.jQuery));
  5138. ;(function($) {
  5139. $.fn.bootstrapValidator.i18n.phone = $.extend($.fn.bootstrapValidator.i18n.phone || {}, {
  5140. 'default': 'Please enter a valid phone number',
  5141. countryNotSupported: 'The country code %s is not supported',
  5142. country: 'Please enter a valid phone number in %s',
  5143. countries: {
  5144. BR: 'Brazil',
  5145. CN: 'China',
  5146. CZ: 'Czech Republic',
  5147. DK: 'Denmark',
  5148. ES: 'Spain',
  5149. FR: 'France',
  5150. GB: 'United Kingdom',
  5151. MA: 'Morocco',
  5152. PK: 'Pakistan',
  5153. RO: 'Romania',
  5154. RU: 'Russia',
  5155. SK: 'Slovakia',
  5156. TH: 'Thailand',
  5157. US: 'USA',
  5158. VE: 'Venezuela'
  5159. }
  5160. });
  5161. $.fn.bootstrapValidator.validators.phone = {
  5162. html5Attributes: {
  5163. message: 'message',
  5164. country: 'country'
  5165. },
  5166. // The supported countries
  5167. COUNTRY_CODES: ['BR', 'CN', 'CZ', 'DK', 'ES', 'FR', 'GB', 'MA', 'PK', 'RO', 'RU', 'SK', 'TH', 'US', 'VE'],
  5168. /**
  5169. * Return true if the input value contains a valid phone number for the country
  5170. * selected in the options
  5171. *
  5172. * @param {BootstrapValidator} validator Validate plugin instance
  5173. * @param {jQuery} $field Field element
  5174. * @param {Object} options Consist of key:
  5175. * - message: The invalid message
  5176. * - country: The ISO-3166 country code. It can be
  5177. * - A country code
  5178. * - Name of field which its value defines the country code
  5179. * - Name of callback function that returns the country code
  5180. * - A callback function that returns the country code
  5181. *
  5182. * @returns {Boolean|Object}
  5183. */
  5184. validate: function(validator, $field, options) {
  5185. var value = $field.val();
  5186. if (value === '') {
  5187. return true;
  5188. }
  5189. var country = options.country;
  5190. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  5191. // Try to determine the country
  5192. country = validator.getDynamicOption($field, country);
  5193. }
  5194. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  5195. return {
  5196. valid: false,
  5197. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.phone.countryNotSupported, country)
  5198. };
  5199. }
  5200. var isValid = true;
  5201. switch (country.toUpperCase()) {
  5202. case 'BR':
  5203. // Test: http://regexr.com/399m1
  5204. value = $.trim(value);
  5205. 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);
  5206. break;
  5207. case 'CN':
  5208. // http://regexr.com/39dq4
  5209. value = $.trim(value);
  5210. 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);
  5211. break;
  5212. case 'CZ':
  5213. // Test: http://regexr.com/39hhl
  5214. isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  5215. break;
  5216. case 'DK':
  5217. // Mathing DK phone numbers with country code in 1 of 3 formats and an
  5218. // 8 digit phone number not starting with a 0 or 1. Can have 1 space
  5219. // between each character except inside the country code.
  5220. // Test: http://regex101.com/r/sS8fO4/1
  5221. value = $.trim(value);
  5222. isValid = (/^(\+45|0045|\(45\))?\s?[2-9](\s?\d){7}$/).test(value);
  5223. break;
  5224. case 'ES':
  5225. // http://regex101.com/r/rB9mA9/1
  5226. value = $.trim(value);
  5227. isValid = (/^(?:(?:(?:\+|00)34\D?))?(?:9|6)(?:\d\D?){8}$/).test(value);
  5228. break;
  5229. case 'FR':
  5230. // http://regexr.com/39a2p
  5231. value = $.trim(value);
  5232. isValid = (/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/).test(value);
  5233. break;
  5234. case 'GB':
  5235. // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
  5236. // Test: http://regexr.com/38uhv
  5237. value = $.trim(value);
  5238. 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);
  5239. break;
  5240. case 'MA':
  5241. // http://en.wikipedia.org/wiki/Telephone_numbers_in_Morocco
  5242. // Test: http://regexr.com/399n8
  5243. value = $.trim(value);
  5244. 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);
  5245. break;
  5246. case 'PK':
  5247. // http://regex101.com/r/yH8aV9/2
  5248. value = $.trim(value);
  5249. isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
  5250. break;
  5251. case 'RO':
  5252. // All mobile network and land line
  5253. // http://regexr.com/39fv1
  5254. 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);
  5255. break;
  5256. case 'RU':
  5257. // http://regex101.com/r/gW7yT5/5
  5258. isValid = (/^((8|\+7|007)[\-\.\/ ]?)?([\(\/\.]?\d{3}[\)\/\.]?[\-\.\/ ]?)?[\d\-\.\/ ]{7,10}$/g).test(value);
  5259. break;
  5260. case 'SK':
  5261. // Test: http://regexr.com/39hhl
  5262. isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  5263. break;
  5264. case 'TH':
  5265. // http://regex101.com/r/vM5mZ4/2
  5266. isValid = (/^0\(?([6|8-9]{2})*-([0-9]{3})*-([0-9]{4})$/).test(value);
  5267. break;
  5268. case 'VE':
  5269. // http://regex101.com/r/eM2yY0/6
  5270. value = $.trim(value);
  5271. 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);
  5272. break;
  5273. case 'US':
  5274. /* falls through */
  5275. default:
  5276. // Make sure US phone numbers have 10 digits
  5277. // May start with 1, +1, or 1-; should discard
  5278. // Area code may be delimited with (), & sections may be delimited with . or -
  5279. // Test: http://regexr.com/38mqi
  5280. value = value.replace(/\D/g, '');
  5281. isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length === 10);
  5282. break;
  5283. }
  5284. return {
  5285. valid: isValid,
  5286. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.phone.country, $.fn.bootstrapValidator.i18n.phone.countries[country])
  5287. };
  5288. }
  5289. };
  5290. }(window.jQuery));
  5291. ;(function($) {
  5292. $.fn.bootstrapValidator.i18n.regexp = $.extend($.fn.bootstrapValidator.i18n.regexp || {}, {
  5293. 'default': 'Please enter a value matching the pattern'
  5294. });
  5295. $.fn.bootstrapValidator.validators.regexp = {
  5296. html5Attributes: {
  5297. message: 'message',
  5298. regexp: 'regexp'
  5299. },
  5300. enableByHtml5: function($field) {
  5301. var pattern = $field.attr('pattern');
  5302. if (pattern) {
  5303. return {
  5304. regexp: pattern
  5305. };
  5306. }
  5307. return false;
  5308. },
  5309. /**
  5310. * Check if the element value matches given regular expression
  5311. *
  5312. * @param {BootstrapValidator} validator The validator plugin instance
  5313. * @param {jQuery} $field Field element
  5314. * @param {Object} options Consists of the following key:
  5315. * - regexp: The regular expression you need to check
  5316. * @returns {Boolean}
  5317. */
  5318. validate: function(validator, $field, options) {
  5319. var value = $field.val();
  5320. if (value === '') {
  5321. return true;
  5322. }
  5323. var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  5324. return regexp.test(value);
  5325. }
  5326. };
  5327. }(window.jQuery));
  5328. ;(function($) {
  5329. $.fn.bootstrapValidator.i18n.remote = $.extend($.fn.bootstrapValidator.i18n.remote || {}, {
  5330. 'default': 'Please enter a valid value'
  5331. });
  5332. $.fn.bootstrapValidator.validators.remote = {
  5333. html5Attributes: {
  5334. message: 'message',
  5335. name: 'name',
  5336. type: 'type',
  5337. url: 'url',
  5338. delay: 'delay'
  5339. },
  5340. /**
  5341. * Destroy the timer when destroying the bootstrapValidator (using validator.destroy() method)
  5342. */
  5343. destroy: function(validator, $field, options) {
  5344. if ($field.data('bv.remote.timer')) {
  5345. clearTimeout($field.data('bv.remote.timer'));
  5346. $field.removeData('bv.remote.timer');
  5347. }
  5348. },
  5349. /**
  5350. * Request a remote server to check the input value
  5351. *
  5352. * @param {BootstrapValidator} validator Plugin instance
  5353. * @param {jQuery} $field Field element
  5354. * @param {Object} options Can consist of the following keys:
  5355. * - url {String|Function}
  5356. * - type {String} [optional] Can be GET or POST (default)
  5357. * - data {Object|Function} [optional]: By default, it will take the value
  5358. * {
  5359. * <fieldName>: <fieldValue>
  5360. * }
  5361. * - delay
  5362. * - name {String} [optional]: Override the field name for the request.
  5363. * - message: The invalid message
  5364. * - headers: Additional headers
  5365. * @returns {Deferred}
  5366. */
  5367. validate: function(validator, $field, options) {
  5368. var value = $field.val(),
  5369. dfd = new $.Deferred();
  5370. if (value === '') {
  5371. dfd.resolve($field, 'remote', { valid: true });
  5372. return dfd;
  5373. }
  5374. var name = $field.attr('data-bv-field'),
  5375. data = options.data || {},
  5376. url = options.url,
  5377. type = options.type || 'GET',
  5378. headers = options.headers || {};
  5379. // Support dynamic data
  5380. if ('function' === typeof data) {
  5381. data = data.call(this, validator);
  5382. }
  5383. // Support dynamic url
  5384. if ('function' === typeof url) {
  5385. url = url.call(this, validator);
  5386. }
  5387. data[options.name || name] = value;
  5388. function runCallback() {
  5389. var xhr = $.ajax({
  5390. type: type,
  5391. headers: headers,
  5392. url: url,
  5393. dataType: 'json',
  5394. data: data
  5395. });
  5396. xhr.then(function(response) {
  5397. response.valid = response.valid === true || response.valid === 'true';
  5398. dfd.resolve($field, 'remote', response);
  5399. });
  5400. dfd.fail(function() {
  5401. xhr.abort();
  5402. });
  5403. return dfd;
  5404. }
  5405. if (options.delay) {
  5406. // Since the form might have multiple fields with the same name
  5407. // I have to attach the timer to the field element
  5408. if ($field.data('bv.remote.timer')) {
  5409. clearTimeout($field.data('bv.remote.timer'));
  5410. }
  5411. $field.data('bv.remote.timer', setTimeout(runCallback, options.delay));
  5412. return dfd;
  5413. } else {
  5414. return runCallback();
  5415. }
  5416. }
  5417. };
  5418. }(window.jQuery));
  5419. ;(function($) {
  5420. $.fn.bootstrapValidator.i18n.rtn = $.extend($.fn.bootstrapValidator.i18n.rtn || {}, {
  5421. 'default': 'Please enter a valid RTN number'
  5422. });
  5423. $.fn.bootstrapValidator.validators.rtn = {
  5424. /**
  5425. * Validate a RTN (Routing transit number)
  5426. * Examples:
  5427. * - Valid: 021200025, 789456124
  5428. *
  5429. * @see http://en.wikipedia.org/wiki/Routing_transit_number
  5430. * @param {BootstrapValidator} validator The validator plugin instance
  5431. * @param {jQuery} $field Field element
  5432. * @param {Object} options Can consist of the following keys:
  5433. * - message: The invalid message
  5434. * @returns {Boolean}
  5435. */
  5436. validate: function(validator, $field, options) {
  5437. var value = $field.val();
  5438. if (value === '') {
  5439. return true;
  5440. }
  5441. if (!/^\d{9}$/.test(value)) {
  5442. return false;
  5443. }
  5444. var sum = 0;
  5445. for (var i = 0; i < value.length; i += 3) {
  5446. sum += parseInt(value.charAt(i), 10) * 3
  5447. + parseInt(value.charAt(i + 1), 10) * 7
  5448. + parseInt(value.charAt(i + 2), 10);
  5449. }
  5450. return (sum !== 0 && sum % 10 === 0);
  5451. }
  5452. };
  5453. }(window.jQuery));
  5454. ;(function($) {
  5455. $.fn.bootstrapValidator.i18n.sedol = $.extend($.fn.bootstrapValidator.i18n.sedol || {}, {
  5456. 'default': 'Please enter a valid SEDOL number'
  5457. });
  5458. $.fn.bootstrapValidator.validators.sedol = {
  5459. /**
  5460. * Validate a SEDOL (Stock Exchange Daily Official List)
  5461. * Examples:
  5462. * - Valid: 0263494, B0WNLY7
  5463. *
  5464. * @see http://en.wikipedia.org/wiki/SEDOL
  5465. * @param {BootstrapValidator} validator The validator plugin instance
  5466. * @param {jQuery} $field Field element
  5467. * @param {Object} options Can consist of the following keys:
  5468. * - message: The invalid message
  5469. * @returns {Boolean}
  5470. */
  5471. validate: function(validator, $field, options) {
  5472. var value = $field.val();
  5473. if (value === '') {
  5474. return true;
  5475. }
  5476. value = value.toUpperCase();
  5477. if (!/^[0-9A-Z]{7}$/.test(value)) {
  5478. return false;
  5479. }
  5480. var sum = 0,
  5481. weight = [1, 3, 1, 7, 3, 9, 1],
  5482. length = value.length;
  5483. for (var i = 0; i < length - 1; i++) {
  5484. sum += weight[i] * parseInt(value.charAt(i), 36);
  5485. }
  5486. sum = (10 - sum % 10) % 10;
  5487. return sum + '' === value.charAt(length - 1);
  5488. }
  5489. };
  5490. }(window.jQuery));
  5491. ;(function($) {
  5492. $.fn.bootstrapValidator.i18n.siren = $.extend($.fn.bootstrapValidator.i18n.siren || {}, {
  5493. 'default': 'Please enter a valid SIREN number'
  5494. });
  5495. $.fn.bootstrapValidator.validators.siren = {
  5496. /**
  5497. * Check if a string is a siren number
  5498. *
  5499. * @param {BootstrapValidator} validator The validator plugin instance
  5500. * @param {jQuery} $field Field element
  5501. * @param {Object} options Consist of key:
  5502. * - message: The invalid message
  5503. * @returns {Boolean}
  5504. */
  5505. validate: function(validator, $field, options) {
  5506. var value = $field.val();
  5507. if (value === '') {
  5508. return true;
  5509. }
  5510. if (!/^\d{9}$/.test(value)) {
  5511. return false;
  5512. }
  5513. return $.fn.bootstrapValidator.helpers.luhn(value);
  5514. }
  5515. };
  5516. }(window.jQuery));
  5517. ;(function($) {
  5518. $.fn.bootstrapValidator.i18n.siret = $.extend($.fn.bootstrapValidator.i18n.siret || {}, {
  5519. 'default': 'Please enter a valid SIRET number'
  5520. });
  5521. $.fn.bootstrapValidator.validators.siret = {
  5522. /**
  5523. * Check if a string is a siret number
  5524. *
  5525. * @param {BootstrapValidator} validator The validator plugin instance
  5526. * @param {jQuery} $field Field element
  5527. * @param {Object} options Consist of key:
  5528. * - message: The invalid message
  5529. * @returns {Boolean}
  5530. */
  5531. validate: function(validator, $field, options) {
  5532. var value = $field.val();
  5533. if (value === '') {
  5534. return true;
  5535. }
  5536. var sum = 0,
  5537. length = value.length,
  5538. tmp;
  5539. for (var i = 0; i < length; i++) {
  5540. tmp = parseInt(value.charAt(i), 10);
  5541. if ((i % 2) === 0) {
  5542. tmp = tmp * 2;
  5543. if (tmp > 9) {
  5544. tmp -= 9;
  5545. }
  5546. }
  5547. sum += tmp;
  5548. }
  5549. return (sum % 10 === 0);
  5550. }
  5551. };
  5552. }(window.jQuery));
  5553. ;(function($) {
  5554. $.fn.bootstrapValidator.i18n.step = $.extend($.fn.bootstrapValidator.i18n.step || {}, {
  5555. 'default': 'Please enter a valid step of %s'
  5556. });
  5557. $.fn.bootstrapValidator.validators.step = {
  5558. html5Attributes: {
  5559. message: 'message',
  5560. base: 'baseValue',
  5561. step: 'step'
  5562. },
  5563. /**
  5564. * Return true if the input value is valid step one
  5565. *
  5566. * @param {BootstrapValidator} validator The validator plugin instance
  5567. * @param {jQuery} $field Field element
  5568. * @param {Object} options Can consist of the following keys:
  5569. * - baseValue: The base value
  5570. * - step: The step
  5571. * - message: The invalid message
  5572. * @returns {Boolean|Object}
  5573. */
  5574. validate: function(validator, $field, options) {
  5575. var value = $field.val();
  5576. if (value === '') {
  5577. return true;
  5578. }
  5579. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  5580. value = parseFloat(value);
  5581. if (!$.isNumeric(value)) {
  5582. return false;
  5583. }
  5584. var round = function(x, precision) {
  5585. var m = Math.pow(10, precision);
  5586. x = x * m;
  5587. var sign = (x > 0) | -(x < 0),
  5588. isHalf = (x % 1 === 0.5 * sign);
  5589. if (isHalf) {
  5590. return (Math.floor(x) + (sign > 0)) / m;
  5591. } else {
  5592. return Math.round(x) / m;
  5593. }
  5594. },
  5595. floatMod = function(x, y) {
  5596. if (y === 0.0) {
  5597. return 1.0;
  5598. }
  5599. var dotX = (x + '').split('.'),
  5600. dotY = (y + '').split('.'),
  5601. precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
  5602. return round(x - y * Math.floor(x / y), precision);
  5603. };
  5604. var mod = floatMod(value - options.baseValue, options.step);
  5605. return {
  5606. valid: mod === 0.0 || mod === options.step,
  5607. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.step['default'], [options.step])
  5608. };
  5609. }
  5610. };
  5611. }(window.jQuery));
  5612. ;(function($) {
  5613. $.fn.bootstrapValidator.i18n.stringCase = $.extend($.fn.bootstrapValidator.i18n.stringCase || {}, {
  5614. 'default': 'Please enter only lowercase characters',
  5615. upper: 'Please enter only uppercase characters'
  5616. });
  5617. $.fn.bootstrapValidator.validators.stringCase = {
  5618. html5Attributes: {
  5619. message: 'message',
  5620. 'case': 'case'
  5621. },
  5622. /**
  5623. * Check if a string is a lower or upper case one
  5624. *
  5625. * @param {BootstrapValidator} validator The validator plugin instance
  5626. * @param {jQuery} $field Field element
  5627. * @param {Object} options Consist of key:
  5628. * - message: The invalid message
  5629. * - case: Can be 'lower' (default) or 'upper'
  5630. * @returns {Object}
  5631. */
  5632. validate: function(validator, $field, options) {
  5633. var value = $field.val();
  5634. if (value === '') {
  5635. return true;
  5636. }
  5637. var stringCase = (options['case'] || 'lower').toLowerCase();
  5638. return {
  5639. valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
  5640. message: options.message || (('upper' === stringCase) ? $.fn.bootstrapValidator.i18n.stringCase.upper : $.fn.bootstrapValidator.i18n.stringCase['default'])
  5641. };
  5642. }
  5643. };
  5644. }(window.jQuery));
  5645. ;(function($) {
  5646. $.fn.bootstrapValidator.i18n.stringLength = $.extend($.fn.bootstrapValidator.i18n.stringLength || {}, {
  5647. 'default': 'Please enter a value with valid length',
  5648. less: 'Please enter less than %s characters',
  5649. more: 'Please enter more than %s characters',
  5650. between: 'Please enter value between %s and %s characters long'
  5651. });
  5652. $.fn.bootstrapValidator.validators.stringLength = {
  5653. html5Attributes: {
  5654. message: 'message',
  5655. min: 'min',
  5656. max: 'max',
  5657. trim: 'trim',
  5658. utf8bytes: 'utf8Bytes'
  5659. },
  5660. enableByHtml5: function($field) {
  5661. var options = {},
  5662. maxLength = $field.attr('maxlength'),
  5663. minLength = $field.attr('minlength');
  5664. if (maxLength) {
  5665. options.max = parseInt(maxLength, 10);
  5666. }
  5667. if (minLength) {
  5668. options.min = parseInt(minLength, 10);
  5669. }
  5670. return $.isEmptyObject(options) ? false : options;
  5671. },
  5672. /**
  5673. * Check if the length of element value is less or more than given number
  5674. *
  5675. * @param {BootstrapValidator} validator The validator plugin instance
  5676. * @param {jQuery} $field Field element
  5677. * @param {Object} options Consists of following keys:
  5678. * - min
  5679. * - max
  5680. * At least one of two keys is required
  5681. * The min, max keys define the number which the field value compares to. min, max can be
  5682. * - A number
  5683. * - Name of field which its value defines the number
  5684. * - Name of callback function that returns the number
  5685. * - A callback function that returns the number
  5686. *
  5687. * - message: The invalid message
  5688. * - trim: Indicate the length will be calculated after trimming the value or not. It is false, by default
  5689. * - utf8bytes: Evaluate string length in UTF-8 bytes, default to false
  5690. * @returns {Object}
  5691. */
  5692. validate: function(validator, $field, options) {
  5693. var value = $field.val();
  5694. if (options.trim === true || options.trim === 'true') {
  5695. value = $.trim(value);
  5696. }
  5697. if (value === '') {
  5698. return true;
  5699. }
  5700. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  5701. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
  5702. // Credit to http://stackoverflow.com/a/23329386 (@lovasoa) for UTF-8 byte length code
  5703. utf8Length = function(str) {
  5704. var s = str.length;
  5705. for (var i = str.length - 1; i >= 0; i--) {
  5706. var code = str.charCodeAt(i);
  5707. if (code > 0x7f && code <= 0x7ff) {
  5708. s++;
  5709. } else if (code > 0x7ff && code <= 0xffff) {
  5710. s += 2;
  5711. }
  5712. if (code >= 0xDC00 && code <= 0xDFFF) {
  5713. i--;
  5714. }
  5715. }
  5716. return s;
  5717. },
  5718. length = options.utf8Bytes ? utf8Length(value) : value.length,
  5719. isValid = true,
  5720. message = options.message || $.fn.bootstrapValidator.i18n.stringLength['default'];
  5721. if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
  5722. isValid = false;
  5723. }
  5724. switch (true) {
  5725. case (!!min && !!max):
  5726. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
  5727. break;
  5728. case (!!min):
  5729. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.more, parseInt(min, 10));
  5730. break;
  5731. case (!!max):
  5732. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.less, parseInt(max, 10));
  5733. break;
  5734. default:
  5735. break;
  5736. }
  5737. return { valid: isValid, message: message };
  5738. }
  5739. };
  5740. }(window.jQuery));
  5741. ;(function($) {
  5742. $.fn.bootstrapValidator.i18n.uri = $.extend($.fn.bootstrapValidator.i18n.uri || {}, {
  5743. 'default': 'Please enter a valid URI'
  5744. });
  5745. $.fn.bootstrapValidator.validators.uri = {
  5746. html5Attributes: {
  5747. message: 'message',
  5748. allowlocal: 'allowLocal',
  5749. protocol: 'protocol'
  5750. },
  5751. enableByHtml5: function($field) {
  5752. return ('url' === $field.attr('type'));
  5753. },
  5754. /**
  5755. * Return true if the input value is a valid URL
  5756. *
  5757. * @param {BootstrapValidator} validator The validator plugin instance
  5758. * @param {jQuery} $field Field element
  5759. * @param {Object} options
  5760. * - message: The error message
  5761. * - allowLocal: Allow the private and local network IP. Default to false
  5762. * - protocol: The protocols, separated by a comma. Default to "http, https, ftp"
  5763. * @returns {Boolean}
  5764. */
  5765. validate: function(validator, $field, options) {
  5766. var value = $field.val();
  5767. if (value === '') {
  5768. return true;
  5769. }
  5770. // Credit to https://gist.github.com/dperini/729294
  5771. //
  5772. // Regular Expression for URL validation
  5773. //
  5774. // Author: Diego Perini
  5775. // Updated: 2010/12/05
  5776. //
  5777. // the regular expression composed & commented
  5778. // could be easily tweaked for RFC compliance,
  5779. // it was expressly modified to fit & satisfy
  5780. // these test for an URL shortener:
  5781. //
  5782. // http://mathiasbynens.be/demo/url-regex
  5783. //
  5784. // Notes on possible differences from a standard/generic validation:
  5785. //
  5786. // - utf-8 char class take in consideration the full Unicode range
  5787. // - TLDs are mandatory unless `allowLocal` is true
  5788. // - protocols have been restricted to ftp, http and https only as requested
  5789. //
  5790. // Changes:
  5791. //
  5792. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  5793. // first and last IP address of each class is considered invalid
  5794. // (since they are broadcast/network addresses)
  5795. //
  5796. // - Added exclusion of private, reserved and/or local networks ranges
  5797. // unless `allowLocal` is true
  5798. //
  5799. // - Added possibility of choosing a custom protocol
  5800. //
  5801. var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
  5802. protocol = (options.protocol || 'http, https, ftp').split(',').join('|').replace(/\s/g, ''),
  5803. urlExp = new RegExp(
  5804. "^" +
  5805. // protocol identifier
  5806. "(?:(?:" + protocol + ")://)" +
  5807. // user:pass authentication
  5808. "(?:\\S+(?::\\S*)?@)?" +
  5809. "(?:" +
  5810. // IP address exclusion
  5811. // private & local networks
  5812. (allowLocal
  5813. ? ''
  5814. : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  5815. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  5816. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
  5817. // IP address dotted notation octets
  5818. // excludes loopback network 0.0.0.0
  5819. // excludes reserved space >= 224.0.0.0
  5820. // excludes network & broadcast addresses
  5821. // (first & last IP address of each class)
  5822. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  5823. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  5824. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  5825. "|" +
  5826. // host name
  5827. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  5828. // domain name
  5829. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  5830. // TLD identifier
  5831. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  5832. // Allow intranet sites (no TLD) if `allowLocal` is true
  5833. (allowLocal ? '?' : '') +
  5834. ")" +
  5835. // port number
  5836. "(?::\\d{2,5})?" +
  5837. // resource path
  5838. "(?:/[^\\s]*)?" +
  5839. "$", "i"
  5840. );
  5841. return urlExp.test(value);
  5842. }
  5843. };
  5844. }(window.jQuery));
  5845. ;(function($) {
  5846. $.fn.bootstrapValidator.i18n.uuid = $.extend($.fn.bootstrapValidator.i18n.uuid || {}, {
  5847. 'default': 'Please enter a valid UUID number',
  5848. version: 'Please enter a valid UUID version %s number'
  5849. });
  5850. $.fn.bootstrapValidator.validators.uuid = {
  5851. html5Attributes: {
  5852. message: 'message',
  5853. version: 'version'
  5854. },
  5855. /**
  5856. * Return true if and only if the input value is a valid UUID string
  5857. *
  5858. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  5859. * @param {BootstrapValidator} validator The validator plugin instance
  5860. * @param {jQuery} $field Field element
  5861. * @param {Object} options Consist of key:
  5862. * - message: The invalid message
  5863. * - version: Can be 3, 4, 5, null
  5864. * @returns {Boolean|Object}
  5865. */
  5866. validate: function(validator, $field, options) {
  5867. var value = $field.val();
  5868. if (value === '') {
  5869. return true;
  5870. }
  5871. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  5872. var patterns = {
  5873. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  5874. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  5875. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  5876. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  5877. },
  5878. version = options.version ? (options.version + '') : 'all';
  5879. return {
  5880. valid: (null === patterns[version]) ? true : patterns[version].test(value),
  5881. message: options.version
  5882. ? $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.uuid.version, options.version)
  5883. : (options.message || $.fn.bootstrapValidator.i18n.uuid['default'])
  5884. };
  5885. }
  5886. };
  5887. }(window.jQuery));
  5888. ;(function($) {
  5889. $.fn.bootstrapValidator.i18n.vat = $.extend($.fn.bootstrapValidator.i18n.vat || {}, {
  5890. 'default': 'Please enter a valid VAT number',
  5891. countryNotSupported: 'The country code %s is not supported',
  5892. country: 'Please enter a valid VAT number in %s',
  5893. countries: {
  5894. AT: 'Austria',
  5895. BE: 'Belgium',
  5896. BG: 'Bulgaria',
  5897. BR: 'Brazil',
  5898. CH: 'Switzerland',
  5899. CY: 'Cyprus',
  5900. CZ: 'Czech Republic',
  5901. DE: 'Germany',
  5902. DK: 'Denmark',
  5903. EE: 'Estonia',
  5904. ES: 'Spain',
  5905. FI: 'Finland',
  5906. FR: 'France',
  5907. GB: 'United Kingdom',
  5908. GR: 'Greek',
  5909. EL: 'Greek',
  5910. HU: 'Hungary',
  5911. HR: 'Croatia',
  5912. IE: 'Ireland',
  5913. IS: 'Iceland',
  5914. IT: 'Italy',
  5915. LT: 'Lithuania',
  5916. LU: 'Luxembourg',
  5917. LV: 'Latvia',
  5918. MT: 'Malta',
  5919. NL: 'Netherlands',
  5920. NO: 'Norway',
  5921. PL: 'Poland',
  5922. PT: 'Portugal',
  5923. RO: 'Romania',
  5924. RU: 'Russia',
  5925. RS: 'Serbia',
  5926. SE: 'Sweden',
  5927. SI: 'Slovenia',
  5928. SK: 'Slovakia',
  5929. VE: 'Venezuela',
  5930. ZA: 'South Africa'
  5931. }
  5932. });
  5933. $.fn.bootstrapValidator.validators.vat = {
  5934. html5Attributes: {
  5935. message: 'message',
  5936. country: 'country'
  5937. },
  5938. // Supported country codes
  5939. COUNTRY_CODES: [
  5940. 'AT', 'BE', 'BG', 'BR', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU',
  5941. 'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SE', 'SK', 'SI', 'VE',
  5942. 'ZA'
  5943. ],
  5944. /**
  5945. * Validate an European VAT number
  5946. *
  5947. * @param {BootstrapValidator} validator The validator plugin instance
  5948. * @param {jQuery} $field Field element
  5949. * @param {Object} options Consist of key:
  5950. * - message: The invalid message
  5951. * - country: The ISO 3166-1 country code. It can be
  5952. * - One of country code defined in COUNTRY_CODES
  5953. * - Name of field which its value defines the country code
  5954. * - Name of callback function that returns the country code
  5955. * - A callback function that returns the country code
  5956. * @returns {Boolean|Object}
  5957. */
  5958. validate: function(validator, $field, options) {
  5959. var value = $field.val();
  5960. if (value === '') {
  5961. return true;
  5962. }
  5963. var country = options.country;
  5964. if (!country) {
  5965. country = value.substr(0, 2);
  5966. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  5967. // Determine the country code
  5968. country = validator.getDynamicOption($field, country);
  5969. }
  5970. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  5971. return {
  5972. valid: false,
  5973. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.vat.countryNotSupported, country)
  5974. };
  5975. }
  5976. var method = ['_', country.toLowerCase()].join('');
  5977. return this[method](value)
  5978. ? true
  5979. : {
  5980. valid: false,
  5981. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.vat.country, $.fn.bootstrapValidator.i18n.vat.countries[country.toUpperCase()])
  5982. };
  5983. },
  5984. // VAT validators
  5985. /**
  5986. * Validate Austrian VAT number
  5987. * Example:
  5988. * - Valid: ATU13585627
  5989. * - Invalid: ATU13585626
  5990. *
  5991. * @param {String} value VAT number
  5992. * @returns {Boolean}
  5993. */
  5994. _at: function(value) {
  5995. if (/^ATU[0-9]{8}$/.test(value)) {
  5996. value = value.substr(2);
  5997. }
  5998. if (!/^U[0-9]{8}$/.test(value)) {
  5999. return false;
  6000. }
  6001. value = value.substr(1);
  6002. var sum = 0,
  6003. weight = [1, 2, 1, 2, 1, 2, 1],
  6004. temp = 0;
  6005. for (var i = 0; i < 7; i++) {
  6006. temp = parseInt(value.charAt(i), 10) * weight[i];
  6007. if (temp > 9) {
  6008. temp = Math.floor(temp / 10) + temp % 10;
  6009. }
  6010. sum += temp;
  6011. }
  6012. sum = 10 - (sum + 4) % 10;
  6013. if (sum === 10) {
  6014. sum = 0;
  6015. }
  6016. return (sum + '' === value.substr(7, 1));
  6017. },
  6018. /**
  6019. * Validate Belgian VAT number
  6020. * Example:
  6021. * - Valid: BE0428759497
  6022. * - Invalid: BE431150351
  6023. *
  6024. * @param {String} value VAT number
  6025. * @returns {Boolean}
  6026. */
  6027. _be: function(value) {
  6028. if (/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  6029. value = value.substr(2);
  6030. }
  6031. if (!/^[0]{0,1}[0-9]{9}$/.test(value)) {
  6032. return false;
  6033. }
  6034. if (value.length === 9) {
  6035. value = '0' + value;
  6036. }
  6037. if (value.substr(1, 1) === '0') {
  6038. return false;
  6039. }
  6040. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  6041. return (sum % 97 === 0);
  6042. },
  6043. /**
  6044. * Validate Bulgarian VAT number
  6045. * Example:
  6046. * - Valid: BG175074752,
  6047. * BG7523169263, BG8032056031,
  6048. * BG7542011030,
  6049. * BG7111042925
  6050. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  6051. *
  6052. * @param {String} value VAT number
  6053. * @returns {Boolean}
  6054. */
  6055. _bg: function(value) {
  6056. if (/^BG[0-9]{9,10}$/.test(value)) {
  6057. value = value.substr(2);
  6058. }
  6059. if (!/^[0-9]{9,10}$/.test(value)) {
  6060. return false;
  6061. }
  6062. var sum = 0, i = 0;
  6063. // Legal entities
  6064. if (value.length === 9) {
  6065. for (i = 0; i < 8; i++) {
  6066. sum += parseInt(value.charAt(i), 10) * (i + 1);
  6067. }
  6068. sum = sum % 11;
  6069. if (sum === 10) {
  6070. sum = 0;
  6071. for (i = 0; i < 8; i++) {
  6072. sum += parseInt(value.charAt(i), 10) * (i + 3);
  6073. }
  6074. }
  6075. sum = sum % 10;
  6076. return (sum + '' === value.substr(8));
  6077. }
  6078. // Physical persons, foreigners and others
  6079. else if (value.length === 10) {
  6080. // Validate Bulgarian national identification numbers
  6081. var egn = function(value) {
  6082. // Check the birth date
  6083. var year = parseInt(value.substr(0, 2), 10) + 1900,
  6084. month = parseInt(value.substr(2, 2), 10),
  6085. day = parseInt(value.substr(4, 2), 10);
  6086. if (month > 40) {
  6087. year += 100;
  6088. month -= 40;
  6089. } else if (month > 20) {
  6090. year -= 100;
  6091. month -= 20;
  6092. }
  6093. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  6094. return false;
  6095. }
  6096. var sum = 0,
  6097. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  6098. for (var i = 0; i < 9; i++) {
  6099. sum += parseInt(value.charAt(i), 10) * weight[i];
  6100. }
  6101. sum = (sum % 11) % 10;
  6102. return (sum + '' === value.substr(9, 1));
  6103. },
  6104. // Validate Bulgarian personal number of a foreigner
  6105. pnf = function(value) {
  6106. var sum = 0,
  6107. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  6108. for (var i = 0; i < 9; i++) {
  6109. sum += parseInt(value.charAt(i), 10) * weight[i];
  6110. }
  6111. sum = sum % 10;
  6112. return (sum + '' === value.substr(9, 1));
  6113. },
  6114. // Finally, consider it as a VAT number
  6115. vat = function(value) {
  6116. var sum = 0,
  6117. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  6118. for (var i = 0; i < 9; i++) {
  6119. sum += parseInt(value.charAt(i), 10) * weight[i];
  6120. }
  6121. sum = 11 - sum % 11;
  6122. if (sum === 10) {
  6123. return false;
  6124. }
  6125. if (sum === 11) {
  6126. sum = 0;
  6127. }
  6128. return (sum + '' === value.substr(9, 1));
  6129. };
  6130. return (egn(value) || pnf(value) || vat(value));
  6131. }
  6132. return false;
  6133. },
  6134. /**
  6135. * Validate Brazilian VAT number (CNPJ)
  6136. *
  6137. * @param {String} value VAT number
  6138. * @returns {Boolean}
  6139. */
  6140. _br: function(value) {
  6141. if (value === '') {
  6142. return true;
  6143. }
  6144. var cnpj = value.replace(/[^\d]+/g, '');
  6145. if (cnpj === '' || cnpj.length !== 14) {
  6146. return false;
  6147. }
  6148. // Remove invalids CNPJs
  6149. if (cnpj === '00000000000000' || cnpj === '11111111111111' || cnpj === '22222222222222' ||
  6150. cnpj === '33333333333333' || cnpj === '44444444444444' || cnpj === '55555555555555' ||
  6151. cnpj === '66666666666666' || cnpj === '77777777777777' || cnpj === '88888888888888' ||
  6152. cnpj === '99999999999999')
  6153. {
  6154. return false;
  6155. }
  6156. // Validate verification digits
  6157. var length = cnpj.length - 2,
  6158. numbers = cnpj.substring(0, length),
  6159. digits = cnpj.substring(length),
  6160. sum = 0,
  6161. pos = length - 7;
  6162. for (var i = length; i >= 1; i--) {
  6163. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  6164. if (pos < 2) {
  6165. pos = 9;
  6166. }
  6167. }
  6168. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  6169. if (result !== parseInt(digits.charAt(0), 10)) {
  6170. return false;
  6171. }
  6172. length = length + 1;
  6173. numbers = cnpj.substring(0, length);
  6174. sum = 0;
  6175. pos = length - 7;
  6176. for (i = length; i >= 1; i--) {
  6177. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  6178. if (pos < 2) {
  6179. pos = 9;
  6180. }
  6181. }
  6182. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  6183. return (result === parseInt(digits.charAt(1), 10));
  6184. },
  6185. /**
  6186. * Validate Swiss VAT number
  6187. *
  6188. * @param {String} value VAT number
  6189. * @returns {Boolean}
  6190. */
  6191. _ch: function(value) {
  6192. if (/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  6193. value = value.substr(2);
  6194. }
  6195. if (!/^E[0-9]{9}(MWST)?$/.test(value)) {
  6196. return false;
  6197. }
  6198. value = value.substr(1);
  6199. var sum = 0,
  6200. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  6201. for (var i = 0; i < 8; i++) {
  6202. sum += parseInt(value.charAt(i), 10) * weight[i];
  6203. }
  6204. sum = 11 - sum % 11;
  6205. if (sum === 10) {
  6206. return false;
  6207. }
  6208. if (sum === 11) {
  6209. sum = 0;
  6210. }
  6211. return (sum + '' === value.substr(8, 1));
  6212. },
  6213. /**
  6214. * Validate Cypriot VAT number
  6215. * Examples:
  6216. * - Valid: CY10259033P
  6217. * - Invalid: CY10259033Z
  6218. *
  6219. * @param {String} value VAT number
  6220. * @returns {Boolean}
  6221. */
  6222. _cy: function(value) {
  6223. if (/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  6224. value = value.substr(2);
  6225. }
  6226. if (!/^[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  6227. return false;
  6228. }
  6229. // Do not allow to start with "12"
  6230. if (value.substr(0, 2) === '12') {
  6231. return false;
  6232. }
  6233. // Extract the next digit and multiply by the counter.
  6234. var sum = 0,
  6235. translation = {
  6236. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  6237. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  6238. };
  6239. for (var i = 0; i < 8; i++) {
  6240. var temp = parseInt(value.charAt(i), 10);
  6241. if (i % 2 === 0) {
  6242. temp = translation[temp + ''];
  6243. }
  6244. sum += temp;
  6245. }
  6246. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  6247. return (sum + '' === value.substr(8, 1));
  6248. },
  6249. /**
  6250. * Validate Czech Republic VAT number
  6251. * Can be:
  6252. * i) Legal entities (8 digit numbers)
  6253. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  6254. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  6255. *
  6256. * Examples:
  6257. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  6258. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  6259. *
  6260. * @param {String} value VAT number
  6261. * @returns {Boolean}
  6262. */
  6263. _cz: function(value) {
  6264. if (/^CZ[0-9]{8,10}$/.test(value)) {
  6265. value = value.substr(2);
  6266. }
  6267. if (!/^[0-9]{8,10}$/.test(value)) {
  6268. return false;
  6269. }
  6270. var sum = 0,
  6271. i = 0;
  6272. if (value.length === 8) {
  6273. // Do not allow to start with '9'
  6274. if (value.charAt(0) + '' === '9') {
  6275. return false;
  6276. }
  6277. sum = 0;
  6278. for (i = 0; i < 7; i++) {
  6279. sum += parseInt(value.charAt(i), 10) * (8 - i);
  6280. }
  6281. sum = 11 - sum % 11;
  6282. if (sum === 10) {
  6283. sum = 0;
  6284. }
  6285. if (sum === 11) {
  6286. sum = 1;
  6287. }
  6288. return (sum + '' === value.substr(7, 1));
  6289. } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
  6290. sum = 0;
  6291. // Skip the first (which is 6)
  6292. for (i = 0; i < 7; i++) {
  6293. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  6294. }
  6295. sum = 11 - sum % 11;
  6296. if (sum === 10) {
  6297. sum = 0;
  6298. }
  6299. if (sum === 11) {
  6300. sum = 1;
  6301. }
  6302. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  6303. return (sum + '' === value.substr(8, 1));
  6304. } else if (value.length === 9 || value.length === 10) {
  6305. // Validate Czech birth number (Rodné číslo), which is also national identifier
  6306. var year = 1900 + parseInt(value.substr(0, 2), 10),
  6307. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  6308. day = parseInt(value.substr(4, 2), 10);
  6309. if (value.length === 9) {
  6310. if (year >= 1980) {
  6311. year -= 100;
  6312. }
  6313. if (year > 1953) {
  6314. return false;
  6315. }
  6316. } else if (year < 1954) {
  6317. year += 100;
  6318. }
  6319. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  6320. return false;
  6321. }
  6322. // Check that the birth date is not in the future
  6323. if (value.length === 10) {
  6324. var check = parseInt(value.substr(0, 9), 10) % 11;
  6325. if (year < 1985) {
  6326. check = check % 10;
  6327. }
  6328. return (check + '' === value.substr(9, 1));
  6329. }
  6330. return true;
  6331. }
  6332. return false;
  6333. },
  6334. /**
  6335. * Validate German VAT number
  6336. * Examples:
  6337. * - Valid: DE136695976
  6338. * - Invalid: DE136695978
  6339. *
  6340. * @param {String} value VAT number
  6341. * @returns {Boolean}
  6342. */
  6343. _de: function(value) {
  6344. if (/^DE[0-9]{9}$/.test(value)) {
  6345. value = value.substr(2);
  6346. }
  6347. if (!/^[0-9]{9}$/.test(value)) {
  6348. return false;
  6349. }
  6350. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  6351. },
  6352. /**
  6353. * Validate Danish VAT number
  6354. * Example:
  6355. * - Valid: DK13585628
  6356. * - Invalid: DK13585627
  6357. *
  6358. * @param {String} value VAT number
  6359. * @returns {Boolean}
  6360. */
  6361. _dk: function(value) {
  6362. if (/^DK[0-9]{8}$/.test(value)) {
  6363. value = value.substr(2);
  6364. }
  6365. if (!/^[0-9]{8}$/.test(value)) {
  6366. return false;
  6367. }
  6368. var sum = 0,
  6369. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  6370. for (var i = 0; i < 8; i++) {
  6371. sum += parseInt(value.charAt(i), 10) * weight[i];
  6372. }
  6373. return (sum % 11 === 0);
  6374. },
  6375. /**
  6376. * Validate Estonian VAT number
  6377. * Examples:
  6378. * - Valid: EE100931558, EE100594102
  6379. * - Invalid: EE100594103
  6380. *
  6381. * @param {String} value VAT number
  6382. * @returns {Boolean}
  6383. */
  6384. _ee: function(value) {
  6385. if (/^EE[0-9]{9}$/.test(value)) {
  6386. value = value.substr(2);
  6387. }
  6388. if (!/^[0-9]{9}$/.test(value)) {
  6389. return false;
  6390. }
  6391. var sum = 0,
  6392. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  6393. for (var i = 0; i < 9; i++) {
  6394. sum += parseInt(value.charAt(i), 10) * weight[i];
  6395. }
  6396. return (sum % 10 === 0);
  6397. },
  6398. /**
  6399. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  6400. * Can be:
  6401. * i) DNI (Documento nacional de identidad), for Spaniards
  6402. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  6403. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  6404. *
  6405. * Examples:
  6406. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  6407. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  6408. *
  6409. * @param {String} value VAT number
  6410. * @returns {Boolean}
  6411. */
  6412. _es: function(value) {
  6413. if (/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  6414. value = value.substr(2);
  6415. }
  6416. if (!/^[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  6417. return false;
  6418. }
  6419. var dni = function(value) {
  6420. var check = parseInt(value.substr(0, 8), 10);
  6421. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  6422. return (check + '' === value.substr(8, 1));
  6423. },
  6424. nie = function(value) {
  6425. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  6426. check = parseInt(check, 10);
  6427. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  6428. return (check + '' === value.substr(8, 1));
  6429. },
  6430. cif = function(value) {
  6431. var first = value.charAt(0), check;
  6432. if ('KLM'.indexOf(first) !== -1) {
  6433. // K: Spanish younger than 14 year old
  6434. // L: Spanish living outside Spain without DNI
  6435. // M: Granted the tax to foreigners who have no NIE
  6436. check = parseInt(value.substr(1, 8), 10);
  6437. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  6438. return (check + '' === value.substr(8, 1));
  6439. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
  6440. var sum = 0,
  6441. weight = [2, 1, 2, 1, 2, 1, 2],
  6442. temp = 0;
  6443. for (var i = 0; i < 7; i++) {
  6444. temp = parseInt(value.charAt(i + 1), 10) * weight[i];
  6445. if (temp > 9) {
  6446. temp = Math.floor(temp / 10) + temp % 10;
  6447. }
  6448. sum += temp;
  6449. }
  6450. sum = 10 - sum % 10;
  6451. return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
  6452. }
  6453. return false;
  6454. };
  6455. var first = value.charAt(0);
  6456. if (/^[0-9]$/.test(first)) {
  6457. return dni(value);
  6458. } else if (/^[XYZ]$/.test(first)) {
  6459. return nie(value);
  6460. } else {
  6461. return cif(value);
  6462. }
  6463. },
  6464. /**
  6465. * Validate Finnish VAT number
  6466. * Examples:
  6467. * - Valid: FI20774740
  6468. * - Invalid: FI20774741
  6469. *
  6470. * @param {String} value VAT number
  6471. * @returns {Boolean}
  6472. */
  6473. _fi: function(value) {
  6474. if (/^FI[0-9]{8}$/.test(value)) {
  6475. value = value.substr(2);
  6476. }
  6477. if (!/^[0-9]{8}$/.test(value)) {
  6478. return false;
  6479. }
  6480. var sum = 0,
  6481. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  6482. for (var i = 0; i < 8; i++) {
  6483. sum += parseInt(value.charAt(i), 10) * weight[i];
  6484. }
  6485. return (sum % 11 === 0);
  6486. },
  6487. /**
  6488. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  6489. * It's constructed by a SIREN number, prefixed by two characters.
  6490. *
  6491. * Examples:
  6492. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  6493. * - Invalid: FR84323140391
  6494. *
  6495. * @param {String} value VAT number
  6496. * @returns {Boolean}
  6497. */
  6498. _fr: function(value) {
  6499. if (/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  6500. value = value.substr(2);
  6501. }
  6502. if (!/^[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  6503. return false;
  6504. }
  6505. if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
  6506. return false;
  6507. }
  6508. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  6509. // First two characters are digits
  6510. return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
  6511. } else {
  6512. // The first characters cann't be O and I
  6513. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  6514. check;
  6515. // First one is digit
  6516. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  6517. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  6518. } else {
  6519. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  6520. }
  6521. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
  6522. }
  6523. },
  6524. /**
  6525. * Validate United Kingdom VAT number
  6526. * Example:
  6527. * - Valid: GB980780684
  6528. * - Invalid: GB802311781
  6529. *
  6530. * @param {String} value VAT number
  6531. * @returns {Boolean}
  6532. */
  6533. _gb: function(value) {
  6534. if (/^GB[0-9]{9}$/.test(value) /* Standard */
  6535. || /^GB[0-9]{12}$/.test(value) /* Branches */
  6536. || /^GBGD[0-9]{3}$/.test(value) /* Government department */
  6537. || /^GBHA[0-9]{3}$/.test(value) /* Health authority */
  6538. || /^GB(GD|HA)8888[0-9]{5}$/.test(value))
  6539. {
  6540. value = value.substr(2);
  6541. }
  6542. if (!/^[0-9]{9}$/.test(value)
  6543. && !/^[0-9]{12}$/.test(value)
  6544. && !/^GD[0-9]{3}$/.test(value)
  6545. && !/^HA[0-9]{3}$/.test(value)
  6546. && !/^(GD|HA)8888[0-9]{5}$/.test(value))
  6547. {
  6548. return false;
  6549. }
  6550. var length = value.length;
  6551. if (length === 5) {
  6552. var firstTwo = value.substr(0, 2),
  6553. lastThree = parseInt(value.substr(2), 10);
  6554. return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
  6555. } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
  6556. if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
  6557. || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
  6558. {
  6559. return false;
  6560. }
  6561. return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
  6562. } else if (length === 9 || length === 12) {
  6563. var sum = 0,
  6564. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  6565. for (var i = 0; i < 9; i++) {
  6566. sum += parseInt(value.charAt(i), 10) * weight[i];
  6567. }
  6568. sum = sum % 97;
  6569. if (parseInt(value.substr(0, 3), 10) >= 100) {
  6570. return (sum === 0 || sum === 42 || sum === 55);
  6571. } else {
  6572. return (sum === 0);
  6573. }
  6574. }
  6575. return true;
  6576. },
  6577. /**
  6578. * Validate Greek VAT number
  6579. * Examples:
  6580. * - Valid: GR023456780, EL094259216
  6581. * - Invalid: EL123456781
  6582. *
  6583. * @param {String} value VAT number
  6584. * @returns {Boolean}
  6585. */
  6586. _gr: function(value) {
  6587. if (/^(GR|EL)[0-9]{9}$/.test(value)) {
  6588. value = value.substr(2);
  6589. }
  6590. if (!/^[0-9]{9}$/.test(value)) {
  6591. return false;
  6592. }
  6593. if (value.length === 8) {
  6594. value = '0' + value;
  6595. }
  6596. var sum = 0,
  6597. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  6598. for (var i = 0; i < 8; i++) {
  6599. sum += parseInt(value.charAt(i), 10) * weight[i];
  6600. }
  6601. sum = (sum % 11) % 10;
  6602. return (sum + '' === value.substr(8, 1));
  6603. },
  6604. // EL is traditionally prefix of Greek VAT numbers
  6605. _el: function(value) {
  6606. return this._gr(value);
  6607. },
  6608. /**
  6609. * Validate Hungarian VAT number
  6610. * Examples:
  6611. * - Valid: HU12892312
  6612. * - Invalid: HU12892313
  6613. *
  6614. * @param {String} value VAT number
  6615. * @returns {Boolean}
  6616. */
  6617. _hu: function(value) {
  6618. if (/^HU[0-9]{8}$/.test(value)) {
  6619. value = value.substr(2);
  6620. }
  6621. if (!/^[0-9]{8}$/.test(value)) {
  6622. return false;
  6623. }
  6624. var sum = 0,
  6625. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  6626. for (var i = 0; i < 8; i++) {
  6627. sum += parseInt(value.charAt(i), 10) * weight[i];
  6628. }
  6629. return (sum % 10 === 0);
  6630. },
  6631. /**
  6632. * Validate Croatian VAT number
  6633. * Examples:
  6634. * - Valid: HR33392005961
  6635. * - Invalid: HR33392005962
  6636. *
  6637. * @param {String} value VAT number
  6638. * @returns {Boolean}
  6639. */
  6640. _hr: function(value) {
  6641. if (/^HR[0-9]{11}$/.test(value)) {
  6642. value = value.substr(2);
  6643. }
  6644. if (!/^[0-9]{11}$/.test(value)) {
  6645. return false;
  6646. }
  6647. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  6648. },
  6649. /**
  6650. * Validate Irish VAT number
  6651. * Examples:
  6652. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  6653. * - Invalid: IE8D79738J
  6654. *
  6655. * @param {String} value VAT number
  6656. * @returns {Boolean}
  6657. */
  6658. _ie: function(value) {
  6659. if (/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  6660. value = value.substr(2);
  6661. }
  6662. if (!/^[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  6663. return false;
  6664. }
  6665. var getCheckDigit = function(value) {
  6666. while (value.length < 7) {
  6667. value = '0' + value;
  6668. }
  6669. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  6670. sum = 0;
  6671. for (var i = 0; i < 7; i++) {
  6672. sum += parseInt(value.charAt(i), 10) * (8 - i);
  6673. }
  6674. sum += 9 * alphabet.indexOf(value.substr(7));
  6675. return alphabet[sum % 23];
  6676. };
  6677. // The first 7 characters are digits
  6678. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  6679. // New system
  6680. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  6681. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
  6682. // Old system
  6683. return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  6684. }
  6685. return true;
  6686. },
  6687. /**
  6688. * Validate Icelandic VAT (VSK) number
  6689. * Examples:
  6690. * - Valid: 12345, 123456
  6691. * - Invalid: 1234567
  6692. *
  6693. * @params {String} value VAT number
  6694. * @returns {Boolean}
  6695. */
  6696. _is: function(value) {
  6697. if (/^IS[0-9]{5,6}$/.test(value)) {
  6698. value = value.substr(2);
  6699. }
  6700. return /^[0-9]{5,6}$/.test(value);
  6701. },
  6702. /**
  6703. * Validate Italian VAT number, which consists of 11 digits.
  6704. * - First 7 digits are a company identifier
  6705. * - Next 3 are the province of residence
  6706. * - The last one is a check digit
  6707. *
  6708. * Examples:
  6709. * - Valid: IT00743110157
  6710. * - Invalid: IT00743110158
  6711. *
  6712. * @param {String} value VAT number
  6713. * @returns {Boolean}
  6714. */
  6715. _it: function(value) {
  6716. if (/^IT[0-9]{11}$/.test(value)) {
  6717. value = value.substr(2);
  6718. }
  6719. if (!/^[0-9]{11}$/.test(value)) {
  6720. return false;
  6721. }
  6722. if (parseInt(value.substr(0, 7), 10) === 0) {
  6723. return false;
  6724. }
  6725. var lastThree = parseInt(value.substr(7, 3), 10);
  6726. if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
  6727. return false;
  6728. }
  6729. return $.fn.bootstrapValidator.helpers.luhn(value);
  6730. },
  6731. /**
  6732. * Validate Lithuanian VAT number
  6733. * It can be:
  6734. * - 9 digits, for legal entities
  6735. * - 12 digits, for temporarily registered taxpayers
  6736. *
  6737. * Examples:
  6738. * - Valid: LT119511515, LT100001919017, LT100004801610
  6739. * - Invalid: LT100001919018
  6740. *
  6741. * @param {String} value VAT number
  6742. * @returns {Boolean}
  6743. */
  6744. _lt: function(value) {
  6745. if (/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  6746. value = value.substr(2);
  6747. }
  6748. if (!/^([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  6749. return false;
  6750. }
  6751. var length = value.length,
  6752. sum = 0,
  6753. i;
  6754. for (i = 0; i < length - 1; i++) {
  6755. sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
  6756. }
  6757. var check = sum % 11;
  6758. if (check === 10) {
  6759. sum = 0;
  6760. for (i = 0; i < length - 1; i++) {
  6761. sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
  6762. }
  6763. }
  6764. check = check % 11 % 10;
  6765. return (check + '' === value.charAt(length - 1));
  6766. },
  6767. /**
  6768. * Validate Luxembourg VAT number
  6769. * Examples:
  6770. * - Valid: LU15027442
  6771. * - Invalid: LU15027443
  6772. *
  6773. * @param {String} value VAT number
  6774. * @returns {Boolean}
  6775. */
  6776. _lu: function(value) {
  6777. if (/^LU[0-9]{8}$/.test(value)) {
  6778. value = value.substr(2);
  6779. }
  6780. if (!/^[0-9]{8}$/.test(value)) {
  6781. return false;
  6782. }
  6783. return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
  6784. },
  6785. /**
  6786. * Validate Latvian VAT number
  6787. * Examples:
  6788. * - Valid: LV40003521600, LV16117519997
  6789. * - Invalid: LV40003521601, LV16137519997
  6790. *
  6791. * @param {String} value VAT number
  6792. * @returns {Boolean}
  6793. */
  6794. _lv: function(value) {
  6795. if (/^LV[0-9]{11}$/.test(value)) {
  6796. value = value.substr(2);
  6797. }
  6798. if (!/^[0-9]{11}$/.test(value)) {
  6799. return false;
  6800. }
  6801. var first = parseInt(value.charAt(0), 10),
  6802. sum = 0,
  6803. weight = [],
  6804. i,
  6805. length = value.length;
  6806. if (first > 3) {
  6807. // Legal entity
  6808. sum = 0;
  6809. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  6810. for (i = 0; i < length; i++) {
  6811. sum += parseInt(value.charAt(i), 10) * weight[i];
  6812. }
  6813. sum = sum % 11;
  6814. return (sum === 3);
  6815. } else {
  6816. // Check birth date
  6817. var day = parseInt(value.substr(0, 2), 10),
  6818. month = parseInt(value.substr(2, 2), 10),
  6819. year = parseInt(value.substr(4, 2), 10);
  6820. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  6821. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  6822. return false;
  6823. }
  6824. // Check personal code
  6825. sum = 0;
  6826. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  6827. for (i = 0; i < length - 1; i++) {
  6828. sum += parseInt(value.charAt(i), 10) * weight[i];
  6829. }
  6830. sum = (sum + 1) % 11 % 10;
  6831. return (sum + '' === value.charAt(length - 1));
  6832. }
  6833. },
  6834. /**
  6835. * Validate Maltese VAT number
  6836. * Examples:
  6837. * - Valid: MT11679112
  6838. * - Invalid: MT11679113
  6839. *
  6840. * @param {String} value VAT number
  6841. * @returns {Boolean}
  6842. */
  6843. _mt: function(value) {
  6844. if (/^MT[0-9]{8}$/.test(value)) {
  6845. value = value.substr(2);
  6846. }
  6847. if (!/^[0-9]{8}$/.test(value)) {
  6848. return false;
  6849. }
  6850. var sum = 0,
  6851. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  6852. for (var i = 0; i < 8; i++) {
  6853. sum += parseInt(value.charAt(i), 10) * weight[i];
  6854. }
  6855. return (sum % 37 === 0);
  6856. },
  6857. /**
  6858. * Validate Dutch VAT number
  6859. * Examples:
  6860. * - Valid: NL004495445B01
  6861. * - Invalid: NL123456789B90
  6862. *
  6863. * @param {String} value VAT number
  6864. * @returns {Boolean}
  6865. */
  6866. _nl: function(value) {
  6867. if (/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  6868. value = value.substr(2);
  6869. }
  6870. if (!/^[0-9]{9}B[0-9]{2}$/.test(value)) {
  6871. return false;
  6872. }
  6873. var sum = 0,
  6874. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  6875. for (var i = 0; i < 8; i++) {
  6876. sum += parseInt(value.charAt(i), 10) * weight[i];
  6877. }
  6878. sum = sum % 11;
  6879. if (sum > 9) {
  6880. sum = 0;
  6881. }
  6882. return (sum + '' === value.substr(8, 1));
  6883. },
  6884. /**
  6885. * Validate Norwegian VAT number
  6886. *
  6887. * @see http://www.brreg.no/english/coordination/number.html
  6888. * @param {String} value VAT number
  6889. * @returns {Boolean}
  6890. */
  6891. _no: function(value) {
  6892. if (/^NO[0-9]{9}$/.test(value)) {
  6893. value = value.substr(2);
  6894. }
  6895. if (!/^[0-9]{9}$/.test(value)) {
  6896. return false;
  6897. }
  6898. var sum = 0,
  6899. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  6900. for (var i = 0; i < 8; i++) {
  6901. sum += parseInt(value.charAt(i), 10) * weight[i];
  6902. }
  6903. sum = 11 - sum % 11;
  6904. if (sum === 11) {
  6905. sum = 0;
  6906. }
  6907. return (sum + '' === value.substr(8, 1));
  6908. },
  6909. /**
  6910. * Validate Polish VAT number
  6911. * Examples:
  6912. * - Valid: PL8567346215
  6913. * - Invalid: PL8567346216
  6914. *
  6915. * @param {String} value VAT number
  6916. * @returns {Boolean}
  6917. */
  6918. _pl: function(value) {
  6919. if (/^PL[0-9]{10}$/.test(value)) {
  6920. value = value.substr(2);
  6921. }
  6922. if (!/^[0-9]{10}$/.test(value)) {
  6923. return false;
  6924. }
  6925. var sum = 0,
  6926. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  6927. for (var i = 0; i < 10; i++) {
  6928. sum += parseInt(value.charAt(i), 10) * weight[i];
  6929. }
  6930. return (sum % 11 === 0);
  6931. },
  6932. /**
  6933. * Validate Portuguese VAT number
  6934. * Examples:
  6935. * - Valid: PT501964843
  6936. * - Invalid: PT501964842
  6937. *
  6938. * @param {String} value VAT number
  6939. * @returns {Boolean}
  6940. */
  6941. _pt: function(value) {
  6942. if (/^PT[0-9]{9}$/.test(value)) {
  6943. value = value.substr(2);
  6944. }
  6945. if (!/^[0-9]{9}$/.test(value)) {
  6946. return false;
  6947. }
  6948. var sum = 0,
  6949. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  6950. for (var i = 0; i < 8; i++) {
  6951. sum += parseInt(value.charAt(i), 10) * weight[i];
  6952. }
  6953. sum = 11 - sum % 11;
  6954. if (sum > 9) {
  6955. sum = 0;
  6956. }
  6957. return (sum + '' === value.substr(8, 1));
  6958. },
  6959. /**
  6960. * Validate Romanian VAT number
  6961. * Examples:
  6962. * - Valid: RO18547290
  6963. * - Invalid: RO18547291
  6964. *
  6965. * @param {String} value VAT number
  6966. * @returns {Boolean}
  6967. */
  6968. _ro: function(value) {
  6969. if (/^RO[1-9][0-9]{1,9}$/.test(value)) {
  6970. value = value.substr(2);
  6971. }
  6972. if (!/^[1-9][0-9]{1,9}$/.test(value)) {
  6973. return false;
  6974. }
  6975. var length = value.length,
  6976. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  6977. sum = 0;
  6978. for (var i = 0; i < length - 1; i++) {
  6979. sum += parseInt(value.charAt(i), 10) * weight[i];
  6980. }
  6981. sum = (10 * sum) % 11 % 10;
  6982. return (sum + '' === value.substr(length - 1, 1));
  6983. },
  6984. /**
  6985. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  6986. *
  6987. * @param {String} value VAT number
  6988. * @returns {Boolean}
  6989. */
  6990. _ru: function(value) {
  6991. if (/^RU([0-9]{10}|[0-9]{12})$/.test(value)) {
  6992. value = value.substr(2);
  6993. }
  6994. if (!/^([0-9]{10}|[0-9]{12})$/.test(value)) {
  6995. return false;
  6996. }
  6997. var i = 0;
  6998. if (value.length === 10) {
  6999. var sum = 0,
  7000. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  7001. for (i = 0; i < 10; i++) {
  7002. sum += parseInt(value.charAt(i), 10) * weight[i];
  7003. }
  7004. sum = sum % 11;
  7005. if (sum > 9) {
  7006. sum = sum % 10;
  7007. }
  7008. return (sum + '' === value.substr(9, 1));
  7009. } else if (value.length === 12) {
  7010. var sum1 = 0,
  7011. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  7012. sum2 = 0,
  7013. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  7014. for (i = 0; i < 11; i++) {
  7015. sum1 += parseInt(value.charAt(i), 10) * weight1[i];
  7016. sum2 += parseInt(value.charAt(i), 10) * weight2[i];
  7017. }
  7018. sum1 = sum1 % 11;
  7019. if (sum1 > 9) {
  7020. sum1 = sum1 % 10;
  7021. }
  7022. sum2 = sum2 % 11;
  7023. if (sum2 > 9) {
  7024. sum2 = sum2 % 10;
  7025. }
  7026. return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
  7027. }
  7028. return false;
  7029. },
  7030. /**
  7031. * Validate Serbian VAT number
  7032. *
  7033. * @param {String} value VAT number
  7034. * @returns {Boolean}
  7035. */
  7036. _rs: function(value) {
  7037. if (/^RS[0-9]{9}$/.test(value)) {
  7038. value = value.substr(2);
  7039. }
  7040. if (!/^[0-9]{9}$/.test(value)) {
  7041. return false;
  7042. }
  7043. var sum = 10,
  7044. temp = 0;
  7045. for (var i = 0; i < 8; i++) {
  7046. temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  7047. if (temp === 0) {
  7048. temp = 10;
  7049. }
  7050. sum = (2 * temp) % 11;
  7051. }
  7052. return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
  7053. },
  7054. /**
  7055. * Validate Swedish VAT number
  7056. * Examples:
  7057. * - Valid: SE123456789701
  7058. * - Invalid: SE123456789101
  7059. *
  7060. * @param {String} value VAT number
  7061. * @returns {Boolean}
  7062. */
  7063. _se: function(value) {
  7064. if (/^SE[0-9]{10}01$/.test(value)) {
  7065. value = value.substr(2);
  7066. }
  7067. if (!/^[0-9]{10}01$/.test(value)) {
  7068. return false;
  7069. }
  7070. value = value.substr(0, 10);
  7071. return $.fn.bootstrapValidator.helpers.luhn(value);
  7072. },
  7073. /**
  7074. * Validate Slovenian VAT number
  7075. * Examples:
  7076. * - Valid: SI50223054
  7077. * - Invalid: SI50223055
  7078. *
  7079. * @param {String} value VAT number
  7080. * @returns {Boolean}
  7081. */
  7082. _si: function(value) {
  7083. if (/^SI[0-9]{8}$/.test(value)) {
  7084. value = value.substr(2);
  7085. }
  7086. if (!/^[0-9]{8}$/.test(value)) {
  7087. return false;
  7088. }
  7089. var sum = 0,
  7090. weight = [8, 7, 6, 5, 4, 3, 2];
  7091. for (var i = 0; i < 7; i++) {
  7092. sum += parseInt(value.charAt(i), 10) * weight[i];
  7093. }
  7094. sum = 11 - sum % 11;
  7095. if (sum === 10) {
  7096. sum = 0;
  7097. }
  7098. return (sum + '' === value.substr(7, 1));
  7099. },
  7100. /**
  7101. * Validate Slovak VAT number
  7102. * Examples:
  7103. * - Valid: SK2022749619
  7104. * - Invalid: SK2022749618
  7105. *
  7106. * @param {String} value VAT number
  7107. * @returns {Boolean}
  7108. */
  7109. _sk: function(value) {
  7110. if (/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  7111. value = value.substr(2);
  7112. }
  7113. if (!/^[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  7114. return false;
  7115. }
  7116. return (parseInt(value, 10) % 11 === 0);
  7117. },
  7118. /**
  7119. * Validate Venezuelan VAT number (RIF)
  7120. * Examples:
  7121. * - Valid: VEJ309272292, VEV242818101, VEJ000126518, VEJ000458324, J309272292, V242818101, J000126518, J000458324
  7122. * - Invalid: VEJ309272293, VEV242818100, J000126519, J000458323
  7123. *
  7124. * @param {String} value VAT number
  7125. * @returns {Boolean}
  7126. */
  7127. _ve: function(value) {
  7128. if (/^VE[VEJPG][0-9]{9}$/.test(value)) {
  7129. value = value.substr(2);
  7130. }
  7131. if (!/^[VEJPG][0-9]{9}$/.test(value)) {
  7132. return false;
  7133. }
  7134. var types = {
  7135. 'V': 4,
  7136. 'E': 8,
  7137. 'J': 12,
  7138. 'P': 16,
  7139. 'G': 20
  7140. },
  7141. sum = types[value.charAt(0)],
  7142. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  7143. for (var i = 0; i < 8; i++) {
  7144. sum += parseInt(value.charAt(i + 1), 10) * weight[i];
  7145. }
  7146. sum = 11 - sum % 11;
  7147. if (sum === 11 || sum === 10) {
  7148. sum = 0;
  7149. }
  7150. return (sum + '' === value.substr(9, 1));
  7151. },
  7152. /**
  7153. * Validate South African VAT number
  7154. * Examples:
  7155. * - Valid: 4012345678
  7156. * - Invalid: 40123456789, 3012345678
  7157. *
  7158. * @params {String} value VAT number
  7159. * @returns {Boolean}
  7160. */
  7161. _za: function(value) {
  7162. if (/^ZA4[0-9]{9}$/.test(value)) {
  7163. value = value.substr(2);
  7164. }
  7165. return /^4[0-9]{9}$/.test(value);
  7166. }
  7167. };
  7168. }(window.jQuery));
  7169. ;(function($) {
  7170. $.fn.bootstrapValidator.i18n.vin = $.extend($.fn.bootstrapValidator.i18n.vin || {}, {
  7171. 'default': 'Please enter a valid VIN number'
  7172. });
  7173. $.fn.bootstrapValidator.validators.vin = {
  7174. /**
  7175. * Validate an US VIN (Vehicle Identification Number)
  7176. *
  7177. * @param {BootstrapValidator} validator The validator plugin instance
  7178. * @param {jQuery} $field Field element
  7179. * @param {Object} options Consist of key:
  7180. * - message: The invalid message
  7181. * @returns {Boolean}
  7182. */
  7183. validate: function(validator, $field, options) {
  7184. var value = $field.val();
  7185. if (value === '') {
  7186. return true;
  7187. }
  7188. // Don't accept I, O, Q characters
  7189. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  7190. return false;
  7191. }
  7192. value = value.toUpperCase();
  7193. var chars = {
  7194. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  7195. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  7196. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  7197. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  7198. },
  7199. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  7200. sum = 0,
  7201. length = value.length;
  7202. for (var i = 0; i < length; i++) {
  7203. sum += chars[value.charAt(i) + ''] * weights[i];
  7204. }
  7205. var reminder = sum % 11;
  7206. if (reminder === 10) {
  7207. reminder = 'X';
  7208. }
  7209. return (reminder + '') === value.charAt(8);
  7210. }
  7211. };
  7212. }(window.jQuery));
  7213. ;(function($) {
  7214. $.fn.bootstrapValidator.i18n.zipCode = $.extend($.fn.bootstrapValidator.i18n.zipCode || {}, {
  7215. 'default': 'Please enter a valid postal code',
  7216. countryNotSupported: 'The country code %s is not supported',
  7217. country: 'Please enter a valid postal code in %s',
  7218. countries: {
  7219. BR: 'Brazil',
  7220. CA: 'Canada',
  7221. CZ: 'Czech Republic',
  7222. DK: 'Denmark',
  7223. GB: 'United Kingdom',
  7224. IT: 'Italy',
  7225. MA: 'Morocco',
  7226. NL: 'Netherlands',
  7227. RO: 'Romania',
  7228. RU: 'Russia',
  7229. SE: 'Sweden',
  7230. SG: 'Singapore',
  7231. SK: 'Slovakia',
  7232. US: 'USA'
  7233. }
  7234. });
  7235. $.fn.bootstrapValidator.validators.zipCode = {
  7236. html5Attributes: {
  7237. message: 'message',
  7238. country: 'country'
  7239. },
  7240. COUNTRY_CODES: ['BR', 'CA', 'CZ', 'DK', 'GB', 'IT', 'MA', 'NL', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
  7241. /**
  7242. * Return true if and only if the input value is a valid country zip code
  7243. *
  7244. * @param {BootstrapValidator} validator The validator plugin instance
  7245. * @param {jQuery} $field Field element
  7246. * @param {Object} options Consist of key:
  7247. * - message: The invalid message
  7248. * - country: The country
  7249. *
  7250. * The country can be defined by:
  7251. * - An ISO 3166 country code
  7252. * - Name of field which its value defines the country code
  7253. * - Name of callback function that returns the country code
  7254. * - A callback function that returns the country code
  7255. *
  7256. * callback: function(value, validator, $field) {
  7257. * // value is the value of field
  7258. * // validator is the BootstrapValidator instance
  7259. * // $field is jQuery element representing the field
  7260. * }
  7261. *
  7262. * @returns {Boolean|Object}
  7263. */
  7264. validate: function(validator, $field, options) {
  7265. var value = $field.val();
  7266. if (value === '' || !options.country) {
  7267. return true;
  7268. }
  7269. var country = options.country;
  7270. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  7271. // Try to determine the country
  7272. country = validator.getDynamicOption($field, country);
  7273. }
  7274. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  7275. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, country) };
  7276. }
  7277. var isValid = false;
  7278. country = country.toUpperCase();
  7279. switch (country) {
  7280. case 'BR':
  7281. isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
  7282. break;
  7283. case 'CA':
  7284. 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);
  7285. break;
  7286. case 'CZ':
  7287. // Test: http://regexr.com/39hhr
  7288. isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  7289. break;
  7290. case 'DK':
  7291. isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
  7292. break;
  7293. case 'GB':
  7294. isValid = this._gb(value);
  7295. break;
  7296. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  7297. case 'IT':
  7298. isValid = /^(I-|IT-)?\d{5}$/i.test(value);
  7299. break;
  7300. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Morocco
  7301. case 'MA':
  7302. isValid = /^[1-9][0-9]{4}$/i.test(value);
  7303. break;
  7304. // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  7305. case 'NL':
  7306. isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  7307. break;
  7308. case 'RO':
  7309. isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})?[0-9]{4}$/i.test(value);
  7310. break;
  7311. case 'RU':
  7312. isValid = /^[0-9]{6}$/i.test(value);
  7313. break;
  7314. case 'SE':
  7315. isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  7316. break;
  7317. case 'SG':
  7318. isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
  7319. break;
  7320. case 'SK':
  7321. // Test: http://regexr.com/39hhr
  7322. isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  7323. break;
  7324. case 'US':
  7325. /* falls through */
  7326. default:
  7327. isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
  7328. break;
  7329. }
  7330. return {
  7331. valid: isValid,
  7332. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.zipCode.country, $.fn.bootstrapValidator.i18n.zipCode.countries[country])
  7333. };
  7334. },
  7335. /**
  7336. * Validate United Kingdom postcode
  7337. * Examples:
  7338. * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  7339. * - Special cases:
  7340. * AI-2640, ASCN 1ZZ, GIR 0AA
  7341. *
  7342. * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  7343. * @param {String} value The postcode
  7344. * @returns {Boolean}
  7345. */
  7346. _gb: function(value) {
  7347. var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
  7348. secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
  7349. thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
  7350. fourthChar = '[ABEHMNPRVWXY]',
  7351. fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
  7352. regexps = [
  7353. // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  7354. new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  7355. // ANA NAA
  7356. new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  7357. // AANA NAA
  7358. new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  7359. new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
  7360. /^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
  7361. /^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
  7362. /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
  7363. /^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
  7364. /^(AI-2640)$/i // Anguilla
  7365. ];
  7366. for (var i = 0; i < regexps.length; i++) {
  7367. if (regexps[i].test(value)) {
  7368. return true;
  7369. }
  7370. }
  7371. return false;
  7372. }
  7373. };
  7374. }(window.jQuery));