| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064 |
- describe('api', function() {
- // Override the options
- $.extend($.fn.bootstrapValidator.DEFAULT_OPTIONS, {
- feedbackIcons: {
- valid: 'glyphicon glyphicon-ok',
- invalid: 'glyphicon glyphicon-remove',
- validating: 'glyphicon glyphicon-refresh'
- }
- });
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="apiForm">',
- '<div class="form-group">',
- '<input type="text" name="username" data-bv-notempty data-bv-stringlength data-bv-stringlength-min="8" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-notempty data-bv-emailaddress />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="note"/>',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#apiForm').bootstrapValidator();
- this.bv = $('#apiForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- this.$note = $('#apiForm').find('input[name="note"]');
- });
- afterEach(function() {
- $('#apiForm').bootstrapValidator('destroy').remove();
- });
- it('revalidateField()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect(this.bv.isValidField('email')).toBeTruthy();
- this.$email.val('invalid#email.address');
- this.bv.revalidateField('email');
- expect(this.bv.isValidField(this.$email)).toEqual(false);
- });
- it('destroy()', function() {
- this.bv.destroy();
- expect($('#apiForm').data('bootstrapValidator')).toBeUndefined();
- expect($('#apiForm').find('i[data-bv-icon-for]').length).toEqual(0);
- expect($('#apiForm').find('.help-block[data-bv-for]').length).toEqual(0);
- expect($('#apiForm').find('.has-feedback').length).toEqual(0);
- expect($('#apiForm').find('.has-success').length).toEqual(0);
- expect($('#apiForm').find('.has-error').length).toEqual(0);
- expect($('#apiForm').find('[data-bv-field]').length).toEqual(0);
- });
- it('getOptions()', function() {
- // Form options
- expect(this.bv.getOptions().feedbackIcons.valid).toEqual('glyphicon glyphicon-ok');
- // Field options
- expect(this.bv.getOptions('username', 'stringlength')).toBeNull();
- expect(this.bv.getOptions('username', 'stringlength', 'min')).toBeNull();
- expect(this.bv.getOptions('username', 'stringLength')).toBeDefined();
- expect(this.bv.getOptions('username', 'stringLength', 'min')).toEqual('8');
- expect(this.bv.getOptions('username', 'stringlength', 'max')).toBeNull();
- });
- // #1014
- it('isValidField()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect(this.bv.isValidField(this.$note)).toBeTruthy();
- expect(this.bv.isValidField(this.$email)).toBeTruthy();
- });
- // #1014
- it('validateField()', function() {
- this.$email.val('email@domain.com');
- this.bv.validateField(this.$email);
- this.bv.validateField(this.$note);
- expect(this.bv.isValidField(this.$email)).toBeTruthy();
- expect(this.bv.isValidField(this.$note)).toBeTruthy();
- });
- });
- describe('container form option', function() {
- beforeEach(function() {
- $([
- '<form id="containerForm" class="form-horizontal">',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Full name</label>',
- '<div class="col-lg-4">',
- '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" />',
- '</div>',
- '<div class="col-lg-4">',
- '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
- '</div>',
- '</div>',
- '<div id="errors"></div>',
- '</form>'
- ].join('')).appendTo('body');
- });
- afterEach(function() {
- $('#containerForm').bootstrapValidator('destroy').remove();
- });
- it('form container declarative', function() {
- $('#containerForm')
- .attr('data-bv-container', '#errors')
- .bootstrapValidator();
- this.bv = $('#containerForm').data('bootstrapValidator');
- this.$firstName = this.bv.getFieldElements('firstName');
- this.$lastName = this.bv.getFieldElements('lastName');
- expect($('#errors').find('.help-block').length).toBeGreaterThan(0);
- this.$firstName.val('First');
- this.$lastName.val('');
- this.bv.validate();
- expect($('#errors').find('.help-block:visible[data-bv-for="firstName"]').length).toEqual(0);
- expect($('#errors').find('.help-block:visible[data-bv-for="lastName"]').length).toBeGreaterThan(0);
- });
- it('form container programmatically', function() {
- $('#containerForm').bootstrapValidator({
- container: '#errors'
- });
- this.bv = $('#containerForm').data('bootstrapValidator');
- this.$firstName = this.bv.getFieldElements('firstName');
- this.$lastName = this.bv.getFieldElements('lastName');
- expect($('#errors').find('.help-block').length).toBeGreaterThan(0);
- this.$firstName.val('');
- this.$lastName.val('Last');
- this.bv.validate();
- expect($('#errors').find('.help-block:visible[data-bv-for="firstName"]').length).toBeGreaterThan(0);
- expect($('#errors').find('.help-block:visible[data-bv-for="lastName"]').length).toEqual(0);
- this.bv.resetForm();
- this.$firstName.val('First');
- this.$lastName.val('Last');
- this.bv.validate();
- expect($('#errors').find('.help-block:visible').length).toEqual(0);
- });
- });
- describe('container field option', function() {
- beforeEach(function() {
- $([
- '<form id="containerForm" class="form-horizontal">',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Full name</label>',
- '<div class="col-lg-4">',
- '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" data-bv-container="#firstNameMessage" />',
- '<span class="help-block" id="firstNameMessage" />',
- '</div>',
- '<div class="col-lg-4">',
- '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
- '<span class="help-block lastNameMessage" />',
- '</div>',
- '</div>',
- '</form>'
- ].join('')).appendTo('body');
- $('#containerForm').bootstrapValidator({
- feedbackIcons: {
- valid: 'glyphicon glyphicon-ok',
- invalid: 'glyphicon glyphicon-remove',
- validating: 'glyphicon glyphicon-refresh'
- },
- fields: {
- lastName: {
- container: '.lastNameMessage'
- }
- }
- });
- this.bv = $('#containerForm').data('bootstrapValidator');
- this.$firstName = this.bv.getFieldElements('firstName');
- this.$lastName = this.bv.getFieldElements('lastName');
- });
- afterEach(function() {
- $('#containerForm').bootstrapValidator('destroy').remove();
- });
- it('field container declarative', function() {
- expect($.trim($('#firstNameMessage').text())).toEqual('The first name is required');
- expect($.trim($('.lastNameMessage').text())).toEqual('The last name is required');
- });
- it('field container programmatically', function() {
- this.$firstName.val('First');
- this.$lastName.val('');
- this.bv.validate();
- expect($('#firstNameMessage').find('.help-block:visible').length).toEqual(0);
- expect($('.lastNameMessage').find('.help-block:visible').length).toBeGreaterThan(0);
- this.bv.resetForm();
- this.$firstName.val('');
- this.$lastName.val('Last');
- this.bv.validate();
- expect($('#firstNameMessage').find('.help-block:visible').length).toBeGreaterThan(0);
- expect($('.lastNameMessage').find('.help-block:visible').length).toEqual(0);
- });
- });
- describe('container tooltip/popover', function() {
- beforeEach(function() {
- $([
- '<form id="containerForm" class="form-horizontal">',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Full name</label>',
- '<div class="col-lg-4">',
- '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" />',
- '</div>',
- '<div class="col-lg-4">',
- '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
- '</div>',
- '</div>',
- '<div id="errors"></div>',
- '</form>'
- ].join('')).appendTo('body');
- });
- afterEach(function() {
- $('#containerForm').bootstrapValidator('destroy').remove();
- });
- it('container declarative', function() {
- $('#containerForm')
- .attr('data-bv-container', 'tooltip')
- .find('[name="lastName"]')
- .attr('data-bv-container', 'popover')
- .end()
- .bootstrapValidator();
- this.bv = $('#containerForm').data('bootstrapValidator');
- this.$firstName = this.bv.getFieldElements('firstName');
- this.$lastName = this.bv.getFieldElements('lastName');
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
- expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
- expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
- expect(this.$lastName.parent().find('i').data('bs.popover').type).toEqual('popover');
- this.bv.resetForm();
- this.$firstName.val('First');
- this.$lastName.val('Last');
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
- expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
- });
- it('container programmatically', function() {
- $('#containerForm').bootstrapValidator({
- container: 'tooltip',
- fields: {
- lastName: {
- container: 'popover'
- }
- }
- });
- this.bv = $('#containerForm').data('bootstrapValidator');
- this.$firstName = this.bv.getFieldElements('firstName');
- this.$lastName = this.bv.getFieldElements('lastName');
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
- expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
- expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
- expect(this.$lastName.parent().find('i').data('bs.popover').type).toEqual('popover');
- this.bv.resetForm();
- this.$firstName.val('First');
- this.$lastName.val('Last');
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
- expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
- });
- // #991: Validate once when setting trigger: blur, container: tooltip
- it('trigger: blur, container: tooltip', function() {
- $('#containerForm').bootstrapValidator({
- container: 'tooltip',
- trigger: 'blur',
- fields: {
- firstName: {
- validators: {
- stringLength: {
- min: 5,
- message: 'The first name must be more than 5 characters'
- },
- notEmpty: {
- message: 'The first name is required'
- },
- regexp: {
- regexp: /^[a-z]+$/i,
- message: 'The first name must consist of a-z, A-Z characters only'
- }
- }
- },
- lastName: {
- validators: {
- stringLength: {
- min: 5,
- message: 'The last name must be more than 5 characters'
- },
- notEmpty: {
- message: 'The last name is required'
- },
- regexp: {
- regexp: /^[a-z]+$/i,
- message: 'The last name must consist of a-z, A-Z characters only'
- }
- }
- }
- }
- });
- this.bv = $('#containerForm').data('bootstrapValidator');
- this.$firstName = this.bv.getFieldElements('firstName');
- this.$lastName = this.bv.getFieldElements('lastName');
- this.$firstName.val('').trigger('blur');
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
- expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
- expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name is required');
- this.bv.resetForm();
- this.$firstName.val('@not#valid');
- this.$lastName.val('').focus();
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
- expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
- expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must consist of a-z, A-Z characters only');
- this.bv.resetForm();
- this.$firstName.val('Phuo');
- this.$lastName.val('').focus();
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
- expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
- expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must be more than 5 characters');
- this.bv.resetForm();
- this.$firstName.val('Phuoc');
- this.$lastName.val('').focus();
- this.bv.validate();
- expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
- });
- });
- describe('dynamic fields', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="dynamicForm">',
- '<div class="form-group">',
- '<input type="text" name="fullName" class="form-control" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#dynamicForm').bootstrapValidator({
- fields: {
- fullName: {
- validators: {
- notEmpty: {
- message: 'The full name is required and cannot be empty'
- },
- stringLength: {
- min: 8,
- max: 40,
- message: 'The full name must be more than %s and less than %s characters long'
- },
- regexp: {
- enabled: false,
- regexp: /^[a-zA-Z\s]+$/,
- message: 'The full name can only consist of alphabetical, number, and space'
- }
- }
- },
- // #725: Note that the email field isn't available in the form yet
- email: {
- validators: {
- emailAddress: {
- message: 'The email address is not valid'
- }
- }
- }
- }
- });
- this.bv = $('#dynamicForm').data('bootstrapValidator');
- this.$fullName = this.bv.getFieldElements('fullName');
- });
- afterEach(function() {
- $('#dynamicForm').bootstrapValidator('destroy').remove();
- });
- // https://github.com/nghuuphuoc/bootstrapvalidator/pull/725
- it('adding field [does not exist but is already set in "fields" option]', function() {
- var $div = $('<div/>').addClass('form-group').appendTo($('#dynamicForm'));
- $email = $('<input/>')
- .attr('type', 'text')
- .addClass('form-control')
- .attr('name', 'email')
- .appendTo($div);
- this.bv.addField('email');
- this.$fullName.val('Phuoc Nguyen');
- $email.val('not valid@email');
- this.bv.validate();
- expect(this.bv.isValidField('email')).toBeFalsy();
- expect(this.bv.isValid()).toBeFalsy();
- this.bv.resetForm();
- $email.val('valid@email.com');
- this.bv.validate();
- expect(this.bv.isValidField('email')).toBeTruthy();
- expect(this.bv.isValid()).toBeTruthy();
- });
- });
- describe('enable validators', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="enableForm">',
- '<div class="form-group">',
- '<input type="text" name="fullName" class="form-control" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#enableForm').bootstrapValidator({
- fields: {
- fullName: {
- validators: {
- notEmpty: {
- message: 'The full name is required and cannot be empty'
- },
- stringLength: {
- min: 8,
- max: 40,
- message: 'The full name must be more than %s and less than %s characters long'
- },
- regexp: {
- enabled: false,
- regexp: /^[a-zA-Z\s]+$/,
- message: 'The full name can only consist of alphabetical, number, and space'
- }
- }
- }
- }
- });
- this.bv = $('#enableForm').data('bootstrapValidator');
- this.$fullName = this.bv.getFieldElements('fullName');
- });
- afterEach(function() {
- $('#enableForm').bootstrapValidator('destroy').remove();
- });
- it('enable all validators', function() {
- this.$fullName.val('@ $full N@m3');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$fullName.val('Contain#$@');
- this.bv.enableFieldValidators('fullName', true);
- this.bv.validate();
- expect(this.bv.isValidField('fullName')).toEqual(false);
- expect(this.bv.isValid()).toEqual(false);
- });
- it('disable all validators', function() {
- this.bv.resetForm();
- this.bv.enableFieldValidators('fullName', false);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('enabled option particular validator', function() {
- this.$fullName.val('Contain@#$');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- var messages = this.bv.getMessages('fullName');
- expect(messages.length).toEqual(0);
- });
- it('enable particular validators', function() {
- // Enable stringLength validator
- this.bv.resetForm();
- this.bv.enableFieldValidators('fullName', true, 'stringLength');
- this.bv.enableFieldValidators('fullName', true, 'regexp');
- this.$fullName.val('Full@');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- var messages = this.bv.getMessages('fullName');
- expect($.inArray('The full name must be more than 8 and less than 40 characters long', messages)).toBeGreaterThan(-1);
- expect($.inArray('The full name can only consist of alphabetical, number, and space', messages)).toBeGreaterThan(-1);
- });
- it('disable particular validators', function() {
- // Disable stringLength validator
- this.bv.enableFieldValidators('fullName', false, 'stringLength');
- this.$fullName.val('Full');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- var messages = this.bv.getMessages('fullName');
- expect($.inArray('The full name must be more than 8 and less than 40 characters long', messages)).toEqual(-1);
- // Disable regexp validator
- this.bv.enableFieldValidators('fullName', false, 'regexp');
- this.$fullName.val('Special@#$');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- var messages = this.bv.getMessages('fullName');
- expect($.inArray('The full name can only consist of alphabetical, number, and space', messages)).toEqual(-1);
- });
- });
- TestSuite = $.extend({}, TestSuite, {
- Event: {
- onEmailValid: function(e, data) {
- $('#msg').html('TestSuite.Event.onEmailValid() called, ' + data.field + ' is valid');
- },
- onEmailInvalid: function(e, data) {
- $('#msg').html('TestSuite.Event.onEmailInvalid() called, ' + data.field + ' is invalid');
- },
- onEmailStatus: function(e, data) {
- $('#status').html('TestSuite.Event.onEmailStatus() called; status = ' + data.status);
- },
- onFormValid: function(e) {
- $('#msg').html('TestSuite.Event.onFormValid() called, form ' + $(e.target).attr('id') + ' is valid');
- },
- onFormInvalid: function(e) {
- $('#msg').html('TestSuite.Event.onFormInvalid() called, form ' + $(e.target).attr('id') + ' is invalid');
- }
- }
- });
- // ---
- // Form events
- // ---
- function onFormValid(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' is valid');
- };
- function onFormInvalid(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' is invalid');
- };
- describe('event form attribute callback global', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="onFormValid" data-bv-onerror="onFormInvalid" >',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" required data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm is valid');
- });
- it('call data-bv-onerror', function() {
- this.$email.val('a@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm is invalid');
- });
- });
- describe('event form attribute callback namespace', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="TestSuite.Event.onFormValid" data-bv-onerror="TestSuite.Event.onFormInvalid" >',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" required data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onFormValid() called, form eventForm is valid');
- });
- it('call data-bv-onerror', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onFormInvalid() called, form eventForm is invalid');
- });
- });
- describe('event form trigger', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm')
- .bootstrapValidator()
- .on('success.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
- })
- .on('error.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('trigger success.form.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm triggered success.form.bv event');
- });
- it('trigger error.form.bv', function() {
- this.$email.val('this is"not\\allowed@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm triggered error.form.bv event');
- });
- });
- describe('event form programmatically', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator({
- onSuccess: function(e) {
- $('#msg').html('onSuccess() called');
- },
- onError: function(e) {
- $('#msg').html('onError() called');
- }
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call onSuccess()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onSuccess() called');
- });
- it('call onError()', function() {
- this.$email.val('Abc.example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onError() called');
- });
- });
- // ---
- // Field events
- // ---
- function onEmailValid(e, data) {
- $('#msg').html(data.field + ' is valid');
- };
- function onEmailInvalid(e, data) {
- $('#msg').html(data.field + ' is invalid');
- };
- function onEmailStatus(e, data) {
- $('#status').html(data.status);
- };
- describe('event field attribute callback global', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div id="status"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="onEmailValid" data-bv-onerror="onEmailInvalid" data-bv-onstatus="onEmailStatus" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('email is valid');
- expect($('#status').html()).toEqual(this.bv.STATUS_VALID);
- });
- it('call data-bv-onerror', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('email is invalid');
- expect($('#status').html()).toEqual(this.bv.STATUS_INVALID);
- });
- });
- describe('event field attribute callback namespace', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div id="status"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="TestSuite.Event.onEmailValid" data-bv-onerror="TestSuite.Event.onEmailInvalid" data-bv-onstatus="TestSuite.Event.onEmailStatus" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onEmailValid() called, email is valid');
- expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_VALID);
- });
- it('call data-bv-onerror', function() {
- this.$email.val('a"b(c)d,e:f;gi[j\\k]l@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onEmailInvalid() called, email is invalid');
- expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_INVALID);
- });
- });
- describe('event field trigger', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm')
- .bootstrapValidator()
- .on('success.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered success.field.bv on ' + data.field);
- })
- .on('error.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered error.field.bv on ' + data.field);
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('trigger success.field.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered success.field.bv on email');
- });
- it('trigger error.field.bv', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered error.field.bv on email');
- });
- });
- describe('event field programmatically', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator({
- fields: {
- email: {
- onSuccess: function(e, data) {
- $('#msg').html('onSuccess() called');
- },
- onError: function(e, data) {
- $('#msg').html('onError() called');
- }
- }
- }
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call onSuccess()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onSuccess() called');
- });
- it('call onError()', function() {
- this.$email.val('this is"not\\allowed@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onError() called');
- });
- });
- // ---
- // Modifying default events
- // ---
- describe('event form trigger with default events', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm1">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm1')
- .bootstrapValidator()
- .on('bv.form.success', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
- })
- .on('success.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
- })
- .on('bv.form.error', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
- })
- .on('error.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
- });
- this.bv = $('#eventForm1').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm1').bootstrapValidator('destroy').remove();
- });
- it('does not trigger bv.form.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.success event');
- });
- it('triggers success.form.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm1 triggered success.form.bv event');
- });
- it('does not trigger bv.form.error', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.error event');
- });
- it('triggers error.form.bv', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm1 triggered error.form.bv event');
- });
- });
- describe('event field trigger with default events', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm3">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm3')
- .bootstrapValidator()
- .on('success.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered success.field.bv on ' + data.field);
- })
- .on('error.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered error.field.bv on ' + data.field);
- })
- .on('bv.field.success', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.success on ' + data.field);
- })
- .on('bv.field.error', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.error on ' + data.field);
- });
- this.bv = $('#eventForm3').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm3').bootstrapValidator('destroy').remove();
- });
- it('triggers success.field.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered success.field.bv on email');
- });
- it('does not trigger bv.field.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered bv.field.success on email');
- });
- it('does not trigger error.field.bv', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered error.field.bv on email');
- });
- it('triggers bv.field.error', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered bv.field.error on email');
- });
- });
- describe('event form trigger with events changed', function() {
- var defaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
- beforeEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
- events: {
- formInit: 'init.form.bv',
- formError: 'bv.form.error',
- formSuccess: 'bv.form.success',
- fieldAdded: 'added.field.bv',
- fieldRemoved: 'removed.field.bv',
- fieldInit: 'init.field.bv',
- fieldError: 'bv.field.error',
- fieldSuccess: 'bv.field.success',
- fieldStatus: 'status.field.bv',
- validatorError: 'bv.validator.error',
- validatorSuccess: 'success.validator.bv'
- }
- });
- $([
- '<form class="form-horizontal" id="eventForm2">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm2')
- .bootstrapValidator()
- .on('bv.form.success', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
- })
- .on('success.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
- })
- .on('bv.form.error', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
- })
- .on('error.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
- });
- this.bv = $('#eventForm2').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
- $('#eventForm2').bootstrapValidator('destroy').remove();
- });
- it('triggers bv.form.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.success event');
- });
- it('does not trigger success.form.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('form eventForm2 triggered success.form.bv event');
- });
- it('triggers bv.form.error', function() {
- spyOn(window, 'onerror');
- this.$email.val('this is"not\\allowed@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.error event');
- expect(window.onerror).not.toHaveBeenCalled();
- });
- });
- describe('event field trigger with events changed', function() {
- var defaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
- beforeEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
- events: {
- formInit: 'init.form.bv',
- formError: 'bv.form.error',
- formSuccess: 'bv.form.success',
- fieldAdded: 'added.field.bv',
- fieldRemoved: 'removed.field.bv',
- fieldInit: 'init.field.bv',
- fieldError: 'bv.field.error',
- fieldSuccess: 'bv.field.success',
- fieldStatus: 'status.field.bv',
- validatorError: 'bv.validator.error',
- validatorSuccess: 'success.validator.bv'
- }
- });
- $([
- '<form class="form-horizontal" id="eventForm4">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm4')
- .bootstrapValidator()
- .on('success.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered success.field.bv on ' + data.field);
- })
- .on('error.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered error.field.bv on ' + data.field);
- })
- .on('bv.field.success', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.success on ' + data.field);
- })
- .on('bv.field.error', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.error on ' + data.field);
- });
- this.bv = $('#eventForm4').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
- $('#eventForm4').bootstrapValidator('destroy').remove();
- });
- it('triggers success.field.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered success.field.bv on email');
- });
- it('does not trigger bv.field.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered bv.field.success on email');
- });
- it('does not trigger error.field.bv', function() {
- this.$email.val('Abc.example.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered error.field.bv on email');
- });
- it('triggers bv.field.error', function() {
- spyOn(window, 'onerror');
- this.$email.val('Abc.example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered bv.field.error on email');
- expect(window.onerror).not.toHaveBeenCalled();
- });
- });
- // ---
- // Validator events
- // ---
- function onEmailAddressValidatorSuccess(e, data) {
- $('#msg').html(data.validator + ' validator passed');
- };
- function onEmailAddressValidatorError(e, data) {
- $('#msg').html(data.validator + ' validator did not pass');
- };
- describe('event validator declarative', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress data-bv-emailaddress-onsuccess="onEmailAddressValidatorSuccess" data-bv-emailaddress-onerror="onEmailAddressValidatorError" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('trigger data-bv-emailaddress-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator passed');
- });
- it('trigger data-bv-emailaddress-onerror', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator did not pass');
- });
- });
- describe('event validator programmatically', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator({
- fields: {
- email: {
- validators: {
- emailAddress: {
- onSuccess: function(e, data) {
- $('#msg').html('emailAddress validator: onSuccess() called');
- },
- onError: function(e, data) {
- $('#msg').html('emailAddress validator: onError() called');
- },
- message: 'The email address is not valid'
- }
- }
- }
- }
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call onSuccess()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator: onSuccess() called');
- });
- it('call onError()', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator: onError() called');
- });
- });
- describe('excluded', function() {
- beforeEach(function() {
- $([
- '<div class="container">',
- '<form class="form-horizontal" id="excludedForm" data-bv-excluded="[name=\'email\']">',
- '<div class="form-group">',
- '<input type="text" name="username" required />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="email" required data-bv-emailaddress />',
- '</div>',
- '</form>',
- '</div>'
- ].join('')).appendTo('body');
- $('#excludedForm').bootstrapValidator();
- this.bv = $('#excludedForm').data('bootstrapValidator');
- this.$username = this.bv.getFieldElements('username');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#excludedForm').bootstrapValidator('destroy').parent().remove();
- });
- it('excluded form declarative', function() {
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$username.val('your_user_name');
- this.$email.val('');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('excluded form programmatically', function() {
- this.bv.destroy();
- $('#excludedForm').removeAttr('data-bv-excluded');
- $('#excludedForm').bootstrapValidator({
- excluded: '[name="username"]'
- });
- this.bv = $('#excludedForm').data('bootstrapValidator');
- this.$username = this.bv.getFieldElements('username');
- this.$email = this.bv.getFieldElements('email');
- this.$username.val('');
- this.$email.val('invalid#email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$email.val('valid@email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('excluded field declarative', function() {
- this.bv.destroy();
- $('#excludedForm').removeAttr('data-bv-excluded');
- $('#excludedForm').find('[name="username"]').attr('data-bv-excluded', 'true');
- $('#excludedForm').find('[name="email"]').attr('data-bv-excluded', 'false');
- this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
- this.$username = this.bv.getFieldElements('username');
- this.$email = this.bv.getFieldElements('email');
- this.$username.val('');
- this.$email.val('');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$email.val('invalid#email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$email.val('valid@email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('excluded field programmatically true/false', function() {
- this.bv.destroy();
- $('#excludedForm').removeAttr('data-bv-excluded');
- $('#excludedForm').bootstrapValidator({
- fields: {
- username: {
- excluded: true
- },
- email: {
- excluded: false
- }
- }
- });
- this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
- this.$username = this.bv.getFieldElements('username');
- this.$email = this.bv.getFieldElements('email');
- this.$username.val('');
- this.$email.val('');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$email.val('invalid#email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$email.val('valid@email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('excluded field programmatically "true"/"false"', function() {
- this.bv.destroy();
- $('#excludedForm').removeAttr('data-bv-excluded');
- $('#excludedForm').bootstrapValidator({
- fields: {
- username: {
- excluded: 'false'
- },
- email: {
- excluded: 'true'
- }
- }
- });
- this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
- this.$username = this.bv.getFieldElements('username');
- this.$email = this.bv.getFieldElements('email');
- this.$username.val('');
- this.$email.val('valid@email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$username.val('your_user_name');
- this.$email.val('invalid#email.com');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- });
- describe('group option', function() {
- beforeEach(function() {
- $([
- '<form id="groupForm" method="post" class="form-horizontal">',
- '<div class="form-group">',
- '<div class="firstNameGroup">',
- '<label class="col-sm-2 control-label">First name</label>',
- '<div class="col-sm-4">',
- '<input type="text" class="form-control" name="firstName" />',
- '</div>',
- '</div>',
- '<div class="lastNameGroup">',
- '<label class="col-sm-2 control-label">Last name</label>',
- '<div class="col-sm-4">',
- '<input type="text" class="form-control" name="lastName" data-bv-group=".lastNameGroup" />',
- '</div>',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-sm-2 control-label">Username</label>',
- '<div class="col-sm-5">',
- '<input type="text" class="form-control" name="username" />',
- '</div>',
- '</div>',
- '</form>'
- ].join('')).appendTo('body');
- $('#groupForm').bootstrapValidator({
- fields: {
- firstName: {
- group: '.firstNameGroup',
- validators: {
- notEmpty: {
- message: 'The first name is required and cannot be empty'
- }
- }
- },
- lastName: {
- validators: {
- notEmpty: {
- message: 'The last name is required and cannot be empty'
- }
- }
- },
- username: {
- validators: {
- notEmpty: {
- message: 'The username is required and cannot be empty'
- },
- stringLength: {
- min: 6,
- max: 30,
- message: 'The username must be more than 6 and less than 30 characters long'
- },
- regexp: {
- regexp: /^[a-zA-Z0-9_\.]+$/,
- message: 'The username can only consist of alphabetical, number, dot and underscore'
- }
- }
- }
- }
- });
- this.bv = $('#groupForm').data('bootstrapValidator');
- this.$firstName = this.bv.getFieldElements('firstName');
- this.$lastName = this.bv.getFieldElements('lastName');
- this.$username = this.bv.getFieldElements('username');
- });
- afterEach(function() {
- $('#groupForm').bootstrapValidator('destroy').remove();
- });
- it('group default', function() {
- this.$username.val('123@#$');
- this.bv.validate();
- expect(this.$username.parents('.form-group').hasClass('has-error')).toBeTruthy();
- expect(this.$username.parents('.form-group').hasClass('has-success')).toEqual(false);
- this.bv.resetForm();
- this.$username.val('validUser.Name');
- this.bv.validate();
- expect(this.$username.parents('.form-group').hasClass('has-success')).toBeTruthy();
- expect(this.$username.parents('.form-group').hasClass('has-error')).toEqual(false);
- });
- it('group programmatically', function() {
- this.$firstName.val('');
- this.bv.validate();
- expect(this.$firstName.parents('.firstNameGroup').hasClass('has-error')).toBeTruthy();
- expect(this.$firstName.parents('.firstNameGroup').hasClass('has-success')).toEqual(false);
- expect(this.$firstName.parents('.form-group').hasClass('has-error')).toEqual(false);
- });
- it('group declarative', function() {
- this.$firstName.val('First');
- this.$lastName.val('Last');
- this.bv.validate();
- expect(this.$lastName.parents('.lastNameGroup').hasClass('has-success')).toBeTruthy();
- expect(this.$lastName.parents('.lastNameGroup').hasClass('has-error')).toEqual(false);
- expect(this.$lastName.parents('.form-group').hasClass('has-success')).toEqual(false);
- expect(this.$lastName.parents('.form-group').hasClass('has-error')).toEqual(false);
- });
- });
- describe('i18n', function() {
- beforeEach(function() {
- $([
- '<form id="i18nForm" class="form-horizontal">',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Full name</label>',
- '<div class="col-lg-5">',
- '<input type="text" class="form-control" name="fullName" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Username</label>',
- '<div class="col-lg-5">',
- '<input type="text" class="form-control" name="username" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Email address</label>',
- '<div class="col-lg-5">',
- '<input type="text" class="form-control" name="email" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Password</label>',
- '<div class="col-lg-5">',
- '<input type="password" class="form-control" name="password" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Retype password</label>',
- '<div class="col-lg-5">',
- '<input type="password" class="form-control" name="confirmPassword" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Gender</label>',
- '<div class="col-lg-5">',
- '<div class="radio">',
- '<label><input type="radio" name="gender" value="male" /> Male</label>',
- '</div>',
- '<div class="radio">',
- '<label><input type="radio" name="gender" value="female" /> Female</label>',
- '</div>',
- '<div class="radio">',
- '<label><input type="radio" name="gender" value="other" /> Other</label>',
- '</div>',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Age</label>',
- '<div class="col-lg-3">',
- '<input type="text" class="form-control" name="age" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Website</label>',
- '<div class="col-lg-5">',
- '<input type="text" class="form-control" name="website" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Phone number</label>',
- '<div class="col-lg-5">',
- '<input type="text" class="form-control" name="phoneNumber" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Languages</label>',
- '<div class="col-lg-5">',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="languages[]" value="english" /> English</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="languages[]" value="french" /> French</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="languages[]" value="german" /> German</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="languages[]" value="russian" /> Russian</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="languages[]" value="other" /> Other</label>',
- '</div>',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-lg-3 control-label">Programming Languages</label>',
- '<div class="col-lg-5">',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="net" /> .Net</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="java" /> Java</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="c" /> C/C++</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="php" /> PHP</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="perl" /> Perl</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="ruby" /> Ruby</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="python" /> Python</label>',
- '</div>',
- '<div class="checkbox">',
- '<label><input type="checkbox" name="programs[]" value="javascript" /> Javascript</label>',
- '</div>',
- '</div>',
- '</div>',
- '</form>'
- ].join('')).appendTo('body');
- $('#i18nForm').bootstrapValidator({
- feedbackIcons: {
- valid: 'glyphicon glyphicon-ok',
- invalid: 'glyphicon glyphicon-remove',
- validating: 'glyphicon glyphicon-refresh'
- },
- fields: {
- fullName: {
- validators: {
- notEmpty: {},
- stringCase: {
- 'case': 'upper'
- }
- }
- },
- username: {
- validators: {
- notEmpty: {},
- stringLength: {
- min: 6,
- max: 20
- },
- regexp: {
- regexp: /^[a-zA-Z0-9_\.]+$/
- },
- different: {
- field: 'password'
- }
- }
- },
- email: {
- validators: {
- emailAddress: {}
- }
- },
- password: {
- validators: {
- notEmpty: {},
- identical: {
- field: 'confirmPassword'
- },
- different: {
- field: 'username'
- }
- }
- },
- confirmPassword: {
- validators: {
- notEmpty: {},
- identical: {
- field: 'password'
- },
- different: {
- field: 'username'
- }
- }
- },
- age: {
- validators: {
- notEmpty: {},
- digits: {},
- greaterThan: {
- value: 18
- },
- lessThan: {
- value: 100
- }
- }
- },
- website: {
- validators: {
- notEmpty: {},
- uri: {}
- }
- },
- phoneNumber: {
- validators: {
- notEmpty: {},
- digits: {},
- phone: {
- country: 'US'
- }
- }
- },
- gender: {
- validators: {
- notEmpty: {}
- }
- },
- 'languages[]': {
- validators: {
- notEmpty: {}
- }
- },
- 'programs[]': {
- validators: {
- choice: {
- min: 2,
- max: 4
- }
- }
- }
- }
- });
- this.bv = $('#i18nForm').data('bootstrapValidator');
- this.$fullName = this.bv.getFieldElements('fullName');
- this.$email = this.bv.getFieldElements('email');
- this.$userName = this.bv.getFieldElements('username');
- this.$password = this.bv.getFieldElements('password');
- this.$confirm = this.bv.getFieldElements('confirmPassword');
- this.$age = this.bv.getFieldElements('age');
- this.$website = this.bv.getFieldElements('website');
- this.$phone = this.bv.getFieldElements('phoneNumber');
- this.$program = this.bv.getFieldElements('programs[]');
- });
- afterEach(function() {
- $('#i18nForm').bootstrapValidator('destroy').remove();
- });
- it('default message', function() {
- var format = $.fn.bootstrapValidator.helpers.format,
- i18n = $.fn.bootstrapValidator.i18n;
- this.bv.validate();
- expect(this.bv.getMessages(this.$fullName, 'notEmpty')[0]).toEqual(i18n.notEmpty['default']);
- this.$fullName.val('lowerName');
- this.bv.revalidateField('fullName');
- expect(this.bv.getMessages('fullName', 'stringCase')[0]).toEqual(i18n.stringCase.upper);
- this.bv.resetForm();
- this.$userName.val('123');
- this.bv.validate();
- expect(this.bv.getMessages('username', 'stringLength')[0]).toEqual(format(i18n.stringLength.between, [6, 20]));
- this.bv.resetForm();
- this.$userName.val('contain@#$');
- this.bv.validate();
- expect(this.bv.getMessages(this.$userName, 'regexp')[0]).toEqual(i18n.regexp['default']);
- this.bv.resetForm();
- this.$userName.val('validUserName');
- this.$password.val('validUserName');
- this.bv.validate();
- expect(this.bv.getMessages('username', 'different')[0]).toEqual(i18n.different['default']);
- this.bv.resetForm();
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect(this.bv.getMessages(this.$email, 'emailAddress')[0]).toEqual(i18n.emailAddress['default']);
- this.bv.resetForm();
- this.$password.val('@S3cur3P@@w0rd');
- this.$confirm.val('notMatch');
- this.bv.validate();
- expect(this.bv.getMessages('password', 'identical')[0]).toEqual(i18n.identical['default']);
- this.bv.resetForm();
- this.$age.val('notDigit');
- this.bv.validate();
- expect(this.bv.getMessages('age', 'digits')[0]).toEqual(i18n.digits['default']);
- this.bv.resetForm();
- this.$age.val(10);
- this.bv.validate();
- expect(this.bv.getMessages(this.$age, 'greaterThan')[0]).toEqual(format(i18n.greaterThan['default'], 18));
- this.bv.resetForm();
- this.$age.val(120);
- this.bv.validate();
- expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual(format(i18n.lessThan['default'], 100));
- this.bv.resetForm();
- this.$website.val('http://invalidWebsite');
- this.bv.validate();
- expect(this.bv.getMessages('website', 'uri')[0]).toEqual(i18n.uri['default']);
- this.bv.resetForm();
- this.$phone.val('123456');
- this.bv.validate();
- expect(this.bv.getMessages('phoneNumber', 'phone')[0]).toEqual(format(i18n.phone.country, i18n.phone.countries['US']));
- this.bv.resetForm();
- this.$program.eq(0).prop('checked', 'checked');
- this.bv.validate();
- expect(this.bv.getMessages(this.$program, 'choice')[0]).toEqual(format(i18n.choice.between, [2, 4]));
- this.bv.resetForm();
- this.$program.prop('checked', 'checked');
- this.bv.validate();
- expect(this.bv.getMessages('programs[]', 'choice')[0]).toEqual(format(i18n.choice.between, [2, 4]));
- });
- });
- describe('input', function() {
- beforeEach(function(done) {
- $([
- '<form class="form-horizontal" id="inputForm">',
- '<div class="form-group">',
- '<textarea name="text" data-bv-notempty placeholder="Text" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="input1" data-bv-notempty placeholder="Text" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="input2" data-bv-notempty placeholder="Text" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#inputForm').bootstrapValidator();
- this.bv = $('#inputForm').data('bootstrapValidator');
- this.$text = this.bv.getFieldElements('text');
- this.$input1 = this.bv.getFieldElements('input1');
- this.$input2 = this.bv.getFieldElements('input2');
- setTimeout(done, 0);
- });
- afterEach(function() {
- $('#inputForm').bootstrapValidator('destroy').remove();
- });
- // #1040, #1041
- it('Fields should not be validated on init', function() {
- expect(this.bv.getMessages(this.$text)).toEqual([]);
- expect(this.bv.getMessages(this.$input1)).toEqual([]);
- expect(this.bv.getMessages(this.$input2)).toEqual([]);
- });
- });
- describe('message', function() {
- beforeEach(function() {
- var html = [
- '<div class="container">',
- '<form class="form-horizontal" id="messageForm">',
- '<div class="form-group">',
- '<input type="password" class="form-control" name="password" placeholder="Enter secure password" />',
- '</div>',
- '</form>',
- '</div>'
- ].join('\n');
- $(html).appendTo('body');
- $('#messageForm').bootstrapValidator({
- fields: {
- password: {
- validators: {
- notEmpty: {
- message: 'The password is required'
- },
- callback: {
- callback: function(value, validator) {
- // Check the password strength
- if (value.length < 6) {
- return {
- valid: false,
- message: 'The password must be more than 6 characters'
- }
- }
- if (value === value.toLowerCase()) {
- return {
- valid: false,
- message: 'The password must contain at least one upper case character'
- }
- }
- if (value === value.toUpperCase()) {
- return {
- valid: false,
- message: 'The password must contain at least one lower case character'
- }
- }
- if (value.search(/[0-9]/) < 0) {
- return {
- valid: false,
- message: 'The password must contain at least one digit'
- }
- }
- return true;
- }
- }
- }
- }
- }
- });
- this.bv = $('#messageForm').data('bootstrapValidator');
- this.$password = this.bv.getFieldElements('password');
- });
- afterEach(function() {
- $('#messageForm').bootstrapValidator('destroy').parent().remove();
- });
- it('update message from callback', function() {
- this.bv.resetForm();
- this.$password.val('123');
- this.bv.validate();
- expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must be more than 6 characters');
- this.bv.resetForm();
- this.$password.val('no_upper_case!@#');
- this.bv.validate();
- expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one upper case character');
- this.bv.resetForm();
- this.$password.val('NO_LOWER_CASE123');
- this.bv.validate();
- expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one lower case character');
- this.bv.resetForm();
- this.$password.val('NoDigits!@#');
- this.bv.validate();
- expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one digit');
- });
- it('call updateMessage()', function() {
- this.bv.updateStatus('password', this.bv.STATUS_INVALID, 'callback');
- this.bv.updateMessage('password', 'callback', 'The password is weak');
- expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password is weak');
- this.bv.updateMessage(this.$password, 'callback', 'The password is not strong');
- expect(this.bv.getMessages(this.$password, 'callback')[0]).toEqual('The password is not strong');
- });
- });
- describe('verbose option', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="verboseForm">',
- '<div class="form-group">',
- '<input type="text" name="fullName" class="form-control" ',
- 'required data-bv-notempty-message="The full name is required and cannot be empty" ',
- 'data-bv-regexp="true" data-bv-regexp-regexp="^[a-zA-Z\\s]+$" data-bv-regexp-message="The full name can only consist of alphabetical, number, and space" ',
- 'data-bv-stringlength="true" data-bv-stringlength-min="8" data-bv-stringlength-max="40" data-bv-stringlength-message="The full name must be more than 8 and less than 40 characters long" ',
- '/>',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- // The order of validators are alphabetical:
- // - notEmpty
- // - regexp
- // - stringLength
- });
- afterEach(function() {
- $('#verboseForm').bootstrapValidator('destroy').remove();
- });
- it('set data-bv-verbose="false" for form', function() {
- var bv = $('#verboseForm')
- .attr('data-bv-verbose', 'false')
- .bootstrapValidator('destroy')
- .bootstrapValidator()
- .data('bootstrapValidator'),
- $fullName = bv.getFieldElements('fullName'),
- messages;
- $fullName.val('');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
- bv.resetForm();
- $fullName.val('Spe@#$');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
- bv.resetForm();
- $fullName.val('Full');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
- });
- it('set data-bv-verbose="false" for field', function() {
- var bv = $('#verboseForm')
- .attr('data-bv-verbose', 'true')
- .find('[name="fullName"]')
- .attr('data-bv-verbose', 'false')
- .end()
- .bootstrapValidator('destroy')
- .bootstrapValidator()
- .data('bootstrapValidator'),
- $fullName = bv.getFieldElements('fullName'),
- messages;
- $fullName.val('');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
- bv.resetForm();
- $fullName.val('Spe@#$');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
- bv.resetForm();
- $fullName.val('Full');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
- });
- it('set verbose: "false" for form', function() {
- var bv = $('#verboseForm')
- .bootstrapValidator('destroy')
- .bootstrapValidator({ verbose: false })
- .data('bootstrapValidator'),
- $fullName = bv.getFieldElements('fullName'),
- messages;
- $fullName.val('');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
- bv.resetForm();
- $fullName.val('Spe@#$');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
- bv.resetForm();
- $fullName.val('Full');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
- });
- // #1057
- it('set verbose: "false" for field', function() {
- var bv = $('#verboseForm')
- .attr('data-bv-verbose', 'true')
- .bootstrapValidator('destroy')
- .bootstrapValidator({
- verbose: true,
- fields: {
- fullName: {
- verbose: false
- }
- }
- })
- .data('bootstrapValidator'),
- $fullName = bv.getFieldElements('fullName'),
- messages;
- $fullName.val('');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
- bv.resetForm();
- $fullName.val('Spe@#$');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
- bv.resetForm();
- $fullName.val('Full');
- bv.validate();
- messages = bv.getMessages('fullName');
- expect(messages.length).toEqual(1);
- expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
- });
- // #1055
- it('trigger "error.field.bv" event', function() {
- var validators = [], // Array of not passed validators
- bv = $('#verboseForm')
- .attr('data-bv-verbose', 'true')
- .bootstrapValidator('destroy')
- .bootstrapValidator({
- verbose: true,
- fields: {
- fullName: {
- verbose: false
- }
- }
- })
- .on('error.field.bv', function(e, data) {
- validators.push(data.validator);
- })
- .data('bootstrapValidator'),
- $fullName = bv.getFieldElements('fullName');
- $fullName.val('');
- bv.validate();
- expect(validators.length).toEqual(1);
- expect(validators[0]).toEqual('notEmpty');
- validators = [];
- bv.resetForm();
- $fullName.val('Spe@#$');
- bv.validate();
- expect(validators.length).toEqual(1);
- expect(validators[0]).toEqual('regexp');
- validators = [];
- bv.resetForm();
- $fullName.val('Full');
- bv.validate();
- expect(validators.length).toEqual(1);
- expect(validators[0]).toEqual('stringLength');
- });
- });
- function betweenCompareMin() {
- var compareTo = $('#betweenForm').find('[name="minAge"]').val();
- $('#msgMin').html('betweenCompareMin() called; compare to ' + compareTo);
- return compareTo;
- };
- function betweenCompareMax() {
- var compareTo = $('#betweenForm').find('[name="maxAge"]').val();
- $('#msgMax').html('betweenCompareMax() called; compare to ' + compareTo);
- return compareTo;
- };
- TestSuite = $.extend({}, TestSuite, {
- between: {
- compareToMin: function(value, validator, $field) {
- var compareTo = $('#betweenForm').find('[name="minAge"]').val();
- $('#msgMin').html('TestSuite.between.compareToMin() called; compare to ' + compareTo);
- return compareTo;
- },
- compareToMax: function(value, validator, $field) {
- var compareTo = $('#betweenForm').find('[name="maxAge"]').val();
- $('#msgMax').html('TestSuite.between.compareToMax() called; compare to ' + compareTo);
- return compareTo;
- }
- }
- });
- describe('between', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="betweenForm">',
- '<div id="msgMin"></div>',
- '<div id="msgMax"></div>',
- '<div class="form-group">',
- '<input type="text" name="minAge" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="maxAge" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="age" data-bv-between data-bv-between-min="18" data-bv-between-max="100" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#betweenForm').bootstrapValidator();
- this.bv = $('#betweenForm').data('bootstrapValidator');
- this.$minAge = this.bv.getFieldElements('minAge');
- this.$maxAge = this.bv.getFieldElements('maxAge');
- this.$age = this.bv.getFieldElements('age');
- });
- afterEach(function() {
- $('#betweenForm').bootstrapValidator('destroy').remove();
- });
- it('not a number', function() {
- this.$age.val('50abc');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('compare to value', function() {
- this.$age.val(10);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$age.val(120);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$age.val(30);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('compare to other field', function() {
- this.bv.updateOption('age', 'between', 'min', 'minAge');
- this.bv.updateOption('age', 'between', 'max', 'maxAge');
- this.$minAge.val(2);
- this.$maxAge.val(10);
- this.$age.val(5);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$minAge.val(20);
- this.$maxAge.val(40);
- this.$age.val(50);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
- });
- // #1048
- it('compare to other field that value has comma', function() {
- this.bv.updateOption('age', 'between', 'min', 'minAge');
- this.bv.updateOption('age', 'between', 'max', 'maxAge');
- this.$minAge.val('2,5');
- this.$maxAge.val('10,5');
- this.$age.val(5);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$minAge.val('20,5');
- this.$maxAge.val('40,5');
- this.$age.val(50);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
- });
- it('compare to return value of a function', function() {
- this.bv.updateOption('age', 'between', 'min', 'betweenCompareMin');
- this.bv.updateOption('age', 'between', 'max', 'betweenCompareMax');
- this.$minAge.val(20);
- this.$maxAge.val(30);
- this.$age.val(18);
- this.bv.validate();
- expect($('#msgMin').html()).toEqual('betweenCompareMin() called; compare to 20');
- expect($('#msgMax').html()).toEqual('betweenCompareMax() called; compare to 30');
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
- this.bv.resetForm();
- this.$minAge.val(2);
- this.$maxAge.val(10);
- this.$age.val(6);
- this.bv.validate();
- expect($('#msgMin').html()).toEqual('betweenCompareMin() called; compare to 2');
- expect($('#msgMax').html()).toEqual('betweenCompareMax() called; compare to 10');
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('compare to return value of a namespace function', function() {
- this.bv.updateOption('age', 'between', 'min', 'TestSuite.between.compareToMin');
- this.bv.updateOption('age', 'between', 'max', 'TestSuite.between.compareToMax');
- this.$minAge.val(20);
- this.$maxAge.val(30);
- this.$age.val(40);
- this.bv.validate();
- expect($('#msgMin').html()).toEqual('TestSuite.between.compareToMin() called; compare to 20');
- expect($('#msgMax').html()).toEqual('TestSuite.between.compareToMax() called; compare to 30');
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
- this.bv.resetForm();
- this.$minAge.val(2);
- this.$maxAge.val(10);
- this.$age.val(5);
- this.bv.validate();
- expect($('#msgMin').html()).toEqual('TestSuite.between.compareToMin() called; compare to 2');
- expect($('#msgMax').html()).toEqual('TestSuite.between.compareToMax() called; compare to 10');
- expect(this.bv.isValid()).toBeTruthy();
- });
- });
- function validateCaptcha(value, validator, $field) {
- var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
- return value === sum + '';
- };
- describe('callback', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="callbackForm">',
- '<div class="form-group">',
- '<label class="col-md-3 control-label" id="captchaOperation"></label>',
- '<div class="col-md-2">',
- '<input type="text" class="form-control" name="captcha" />',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<div class="col-md-2 col-md-offset-3">',
- '<input type="text" class="form-control" name="declarativeCaptcha" data-bv-callback data-bv-callback-callback="validateCaptcha" />',
- '</div>',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#callbackForm').bootstrapValidator({
- fields: {
- captcha: {
- validators: {
- callback: {
- message: 'Wrong answer',
- callback: function(value, validator, $field) {
- return validateCaptcha(value, validator, $field);
- }
- }
- }
- }
- }
- });
- this.bv = $('#callbackForm').data('bootstrapValidator');
- this.$captcha = this.bv.getFieldElements('captcha');
- this.$declarativeCaptcha = this.bv.getFieldElements('declarativeCaptcha');
- });
- afterEach(function() {
- $('#callbackForm').bootstrapValidator('destroy').remove();
- });
- it('execute the callback', function() {
- $('#captchaOperation').html('1 + 2');
- this.$captcha.val('3');
- this.bv.validate();
- expect(this.bv.isValidField('captcha')).toBeTruthy();
- this.bv.resetForm();
- this.$captcha.val('5');
- this.bv.validate();
- expect(this.bv.isValidField('captcha')).toEqual(false);
- });
- it('callback declarative', function() {
- $('#captchaOperation').html('10 + 20');
- this.$declarativeCaptcha.val('40');
- this.bv.validate();
- expect(this.bv.isValidField('declarativeCaptcha')).toEqual(false);
- this.bv.resetForm();
- this.$declarativeCaptcha.val('30');
- this.bv.validate();
- expect(this.bv.isValidField('declarativeCaptcha')).toBeTruthy();
- });
- });
- describe('color', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="colorForm">',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="color" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="colorMultiple" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="colorHex" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="colorRgb" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="colorRgba" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="colorHsl" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="colorHsla" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" class="form-control" name="colorKeyword" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#colorForm').bootstrapValidator({
- fields: {
- color: {
- validators: {
- color: { }
- }
- },
- colorMultiple: {
- validators: {
- color: {
- type: [
- 'hex',
- 'rgb'
- ]
- }
- }
- },
- colorHex: {
- validators: {
- color: {
- type: ['hex']
- }
- }
- },
- colorRgb: {
- validators: {
- color: {
- type: ['rgb']
- }
- }
- },
- colorRgba: {
- validators: {
- color: {
- type: ['rgba']
- }
- }
- },
- colorHsl: {
- validators: {
- color: {
- type: ['hsl']
- }
- }
- },
- colorHsla: {
- validators: {
- color: {
- type: ['hsla']
- }
- }
- },
- colorKeyword: {
- validators: {
- color: {
- type: ['keyword']
- }
- }
- }
- }
- });
- this.bv = $('#colorForm').data('bootstrapValidator');
- this.$color = this.bv.getFieldElements('color');
- this.$colorMultiple = this.bv.getFieldElements('colorMultiple');
- this.$colorHex = this.bv.getFieldElements('colorHex');
- this.$colorRgb = this.bv.getFieldElements('colorRgb');
- this.$colorRgba = this.bv.getFieldElements('colorRgba');
- this.$colorHsl = this.bv.getFieldElements('colorHsl');
- this.$colorHsla = this.bv.getFieldElements('colorHsla');
- this.$colorKeyword = this.bv.getFieldElements('colorKeyword');
- });
- afterEach(function() {
- $('#colorForm').bootstrapValidator('destroy').remove();
- });
- // Start hsla() tests
- it('Run hsla() test suite on hsla only field', function() {
- this.$colorHsla.val('hsla(120,50%,50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla( 120 , 50% , 50%, 1 )');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla( 120, 50%, 50% , 1 )');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(-120,50%,50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(480,50%,50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,0)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,0.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,.524141)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,2)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,-1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,1.000000000001)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,-0.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,100%,2.3)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(10,-50%,50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(10,50%,-50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('120,50%,50%,1');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,100%,101%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla (120,50%,50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val(' hsla(120,50%,50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120,50%,50%,1) ');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(50%, 50%, 100%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120, 50, 100%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsla.val('hsla(120, 50%, 100,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- });
- // Start hsl() tests
- it('Run hsl() test suite on hsl only field', function() {
- this.$colorHsl.val('hsl(120,50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsl.val('hsl( 120 , 50% , 50% )');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsl.val('hsl( 120, 50%, 50% )');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsl.val('hsl(-120,50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsl.val('hsl(480,50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toBeTruthy();
- this.bv.resetForm();
- this.$colorHsl.val('hsl(10,-50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('hsl(10,50%,-50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('120,50%,50%');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('hsl(120,100%,101%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('hsl (120,50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val(' hsl(120,50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('hsl(120,50%,50%) ');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('hsl(50%, 50%, 100%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('hsl(120, 50, 100%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- this.bv.resetForm();
- this.$colorHsl.val('hsl(120, 50%, 100)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- });
- // Start keyword test
- it('Run keyword test suite on keyword only field', function() {
- this.$colorKeyword.val('transparent');
- this.bv.validate();
- expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
- this.bv.resetForm();
- this.$colorKeyword.val('transparent');
- this.bv.validate();
- expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
- this.bv.resetForm();
- this.$colorKeyword.val('blueviolet red');
- this.bv.validate();
- expect(this.bv.isValidField('colorKeyword')).toEqual(false);
- this.bv.resetForm();
- this.$colorKeyword.val('shady');
- this.bv.validate();
- expect(this.bv.isValidField('colorKeyword')).toEqual(false);
- this.bv.resetForm();
- this.$colorKeyword.val('blueish');
- this.bv.validate();
- expect(this.bv.isValidField('colorKeyword')).toEqual(false);
- });
- // Start rgba() test
- it('Run rgba() test suite on rgba only field', function() {
- this.$colorRgba.val('rgba(255,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba( 255 , 255 , 255 , 1 )');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba( 255 , 255 , 255 , 1 )');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,100%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,0)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,0.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,.524141)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,100%,0)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,100%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,100%,0.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,100%,.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,100%,.524141)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,100%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,2)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,-1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,1.000000000001)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,-0.5)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,2.3)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,100%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(-10,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(-10%,100%,100%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('255,255,255,1');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,256),1');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(100%,100%,101%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba (255,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val(' rgba(255,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgba.val('rgba(255,255,255,1) ');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- });
- // Start rgb() test
- it('Run rgb() test suite on rgb only field', function() {
- this.$colorRgb.val('rgb(255,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgb.val('rgb( 255 , 255 , 255 )');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgb.val('rgb( 255, 255, 255 )');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgb.val('rgb(255,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgb.val('rgb(100%,100%,100%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toBeTruthy();
- this.bv.resetForm();
- this.$colorRgb.val('rgb(255,255,100%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val('rgb(-10,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val('rgb(-10%,100%,100%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val('255,255,255');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val('rgb(255,255,256)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val('rgb(100%,100%,101%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val('rgb (255,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val(' rgb(255,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- this.bv.resetForm();
- this.$colorRgb.val('rgb(255,255,255) ');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- });
- /* Run individual tests */
- it('Individual field keyword: accept keyword', function() {
- this.$colorKeyword.val('blue');
- this.bv.validate();
- expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
- });
- it('Individual field keyword: reject rgb', function() {
- this.$colorKeyword.val('rgb(255,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorKeyword')).toEqual(false);
- });
- it('Individual field hex: accept 6 char hex', function() {
- this.$colorHex.val('#0000FF');
- this.bv.validate();
- expect(this.bv.isValidField('colorHex')).toBeTruthy();
- });
- it('Individual field hex: accept 3 char hex', function() {
- this.$colorHex.val('#00F');
- this.bv.validate();
- expect(this.bv.isValidField('colorHex')).toBeTruthy();
- });
- it('Individual field hex: reject keyword', function() {
- this.$colorHex.val('blue');
- this.bv.validate();
- expect(this.bv.isValidField('colorHex')).toEqual(false);
- });
- it('Individual field rgb(): accept rgb()', function() {
- this.$colorRgb.val('rgb(255,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toBeTruthy();
- });
- it('Individual field rgb(): reject hex', function() {
- this.$colorRgb.val('#0000FF');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgb')).toEqual(false);
- });
- it('Individual field rgba(): accept rgba()', function() {
- this.$colorRgba.val('rgba(255,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toBeTruthy();
- });
- it('Individual field rgba(): reject rgb()', function() {
- this.$colorRgba.val('rgb(255,255,255)');
- this.bv.validate();
- expect(this.bv.isValidField('colorRgba')).toEqual(false);
- });
- it('Individual field hsl(): accept hsl()', function() {
- this.$colorHsl.val('hsl(120,50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toBeTruthy();
- });
- it('Individual field hsl(): reject rgba()', function() {
- this.$colorHsl.val('rgba(255,255,255,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsl')).toEqual(false);
- });
- it('Individual field hsla(): accept hsla()', function() {
- this.$colorHsla.val('hsla(120,50%,50%,1)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toBeTruthy();
- });
- it('Individual field hsla(): reject hsl()', function() {
- this.$colorHsla.val('hsl(120,50%,50%)');
- this.bv.validate();
- expect(this.bv.isValidField('colorHsla')).toEqual(false);
- });
- /* Run validation message tests */
- it('Validation message tests', function() {
- this.$color.val('notacolor');
- this.bv.validate();
- expect(this.bv.isValidField('color')).toEqual(false);
- expect(this.bv.getMessages(this.$color, 'color')[0]).toEqual($.fn.bootstrapValidator.i18n.color.default);
- });
- });
- describe('creditCard', function() {
- // Get the fake credit card number at http://www.getcreditcardnumbers.com/
- beforeEach(function() {
- var html = [
- '<div class="container">',
- '<form class="form-horizontal" id="ccForm">',
- '<div class="form-group">',
- '<input type="text" name="cc" data-bv-creditcard />',
- '</div>',
- '</form>',
- '</div>'
- ].join('\n');
- $(html).appendTo('body');
- $('#ccForm').bootstrapValidator();
- this.bv = $('#ccForm').data('bootstrapValidator');
- this.$creditCard = this.bv.getFieldElements('cc');
- });
- afterEach(function() {
- $('#ccForm').bootstrapValidator('destroy').parent().remove();
- });
- it('accept spaces', function() {
- this.$creditCard.val('5267 9789 9451 9654');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('accept dashes', function() {
- this.$creditCard.val('6011-2649-6840-4521');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('invalid format', function() {
- this.$creditCard.val('4539.1870.2954.3862');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toEqual(false);
- });
- it('American Express', function() {
- this.$creditCard.val('340653705597107');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('American Express invalid length', function() {
- this.$creditCard.val('3744148309166730');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toEqual(false);
- });
- it('American Express invalid prefix', function() {
- this.$creditCard.val('356120148436654');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toEqual(false);
- });
- it('Diners Club', function() {
- this.$creditCard.val('30130708434187');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Diners Club (US)', function() {
- this.$creditCard.val('5517479515603901');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Discover', function() {
- this.$creditCard.val('6011734674929094');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('JCB', function() {
- this.$creditCard.val('3566002020360505');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Laser', function() {
- this.$creditCard.val('6304 9000 1774 0292 441');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Maestro', function() {
- this.$creditCard.val('6762835098779303');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Mastercard', function() {
- this.$creditCard.val('5303765013600904');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Solo', function() {
- this.$creditCard.val('6334580500000000');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Visa', function() {
- this.$creditCard.val('4929248980295542');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toBeTruthy();
- });
- it('Visa invalid check digit', function() {
- this.$creditCard.val('4532599916257826');
- this.bv.validate();
- expect(this.bv.isValidField('cc')).toEqual(false);
- });
- });
- function getDate(value, validator, $field) {
- return validator.getFieldElements('date').val();
- };
- TestSuite = $.extend({}, TestSuite, {
- Date: {
- getDate: function(value, validator, $field) {
- return validator.getFieldElements('date').val();
- }
- }
- });
- describe('date', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="dateForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="date" data-bv-date />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="minDate" data-bv-date data-bv-date-min="" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="maxDate" data-bv-date data-bv-date-max="" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="range" data-bv-date data-bv-date-min="" data-bv-date-max="" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#dateForm').bootstrapValidator();
- this.bv = $('#dateForm').data('bootstrapValidator');
- this.$date = this.bv.getFieldElements('date');
- this.$minDate = this.bv.getFieldElements('minDate');
- this.$maxDate = this.bv.getFieldElements('maxDate');
- this.$range = this.bv.getFieldElements('range');
- });
- afterEach(function() {
- $('#dateForm').bootstrapValidator('destroy').remove();
- });
- it('YYYY/MM/DD', function() {
- this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2000/01/30');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- // Invalid year
- this.bv.resetForm();
- this.$date.val('100/10/20');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- // Invalid month
- this.bv.resetForm();
- this.$date.val('2000/00/10');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2000/15/10');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- // Invalid day
- this.bv.resetForm();
- this.$date.val('2000/03/00');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2000/10/32');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- // Negative number
- this.bv.resetForm();
- this.$date.val('-2000/10/20');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2000/-10/20');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2000/10/-20');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- // Consist invalid characters
- // Issue #310
- this.bv.resetForm();
- this.$date.val('aaaa/');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2004df/1dd1/5ffg');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- // Issue #475
- this.bv.resetForm();
- this.$date.val('2014/09');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2014/09/');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2014//15');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('/09/15');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('MM/DD/YYYY', function() {
- this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
- this.$date.val('09/15/2020');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('09/15');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('09/15/');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('number of days in February', function() {
- this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2000/02/28');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2000/02/29');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2001/02/29');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- // Issue #681
- it('date, month, year are prefixed by zero', function() {
- this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
- this.$date.val('0012/08/2014');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('12/0008/2014');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('12/08/002014');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('12/08/2014');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('hours, minutes, seconds are prefixed by zero', function() {
- this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD h:m:s');
- this.$date.val('2014/08/17 0007:30:00');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2014/08/17 07:030:00');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2014/08/17 07:30:0000');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$date.val('2014/08/17 07:30:00');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- // min test suite
- it('min date format YYYY/MM/DD', function() {
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
- this.bv.updateOption('minDate', 'date', 'min', '2010/01/01');
- this.$minDate.val('2010/01/02');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('2010/01/002'); // day prefexid by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('2009/12/31');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2000/01/01');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- });
- it('min date format YYYY-MM-DD', function() {
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY-MM-DD');
- this.bv.updateOption('minDate', 'date', 'min', '2010-01-01');
- this.$minDate.val('2010-01-02');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('2010-001-02'); // month prefexid by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2014-08-17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('2009-12-31');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2000-01-01');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- });
- it('min date format DD/MM/YYYY', function() {
- this.bv.updateOption('minDate', 'date', 'format', 'DD/MM/YYYY');
- this.bv.updateOption('minDate', 'date', 'min', '01/01/2010');
- this.$minDate.val('02/01/2010');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('17/08/2014');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('02/01/02010'); // year prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('31/12/2009');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('01/01/2000');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- });
- it('min date format YYYY-MM-DD h:m:s', function() {
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY-MM-DD h:m:s');
- this.bv.updateOption('minDate', 'date', 'min', '2010-01-01 01:00:00');
- this.bv.resetForm();
- this.$minDate.val('2010-01-01 01:00:01');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.$minDate.val('2010-01-02 01:00:01');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('2014-08-17 12:00:00');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$minDate.val('2009-12-31 00:00:00');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2009-12-31 010:00:00'); // hours prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2009-12-31 10:001:00'); // minutes prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2009-12-31 10:01:012'); // seconds prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2009-12-31 00:00:00');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- this.bv.resetForm();
- this.$minDate.val('2000-01-01 23:00:12');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toEqual(false);
- });
- // max test suite
- it('max date format YYYY/MM/DD', function() {
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
- this.bv.updateOption('maxDate', 'date', 'max', '2014/09/10');
- this.$maxDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('02014/012/031'); // year, month or day prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('2014/12/31');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('2015/01/01');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- });
- it('max date format YYYY-MM-DD', function() {
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY-MM-DD');
- this.bv.updateOption('maxDate', 'date', 'max', '2014-09-10');
- this.$maxDate.val('2014-09-09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('2014-08-17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('02014-012-031'); // year, month or day prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('2014-12-31');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('2015-01-01');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- });
- it('max date format DD/MM/YYYY', function() {
- this.bv.updateOption('maxDate', 'date', 'format', 'DD/MM/YYYY');
- this.bv.updateOption('maxDate', 'date', 'max', '10/09/2014');
- this.$maxDate.val('09/09/2014');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('17/08/2014');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('031/012/02014'); // year, month or day prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('31/12/2014');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('01/01/2015');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- });
- it('max date format YYYY-MM-DD h:m:s', function() {
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY-MM-DD h:m:s');
- this.bv.updateOption('maxDate', 'date', 'max', '2014-09-10 01:00:00');
- this.$maxDate.val('2014-09-09 01:00:01');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('2014-08-17 12:00:00');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$maxDate.val('2014-09-09 001:001:001'); // hours, minutes or seconds prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('2014-12-31 00:00:00');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- this.bv.resetForm();
- this.$maxDate.val('2015-01-01 23:00:12');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toEqual(false);
- });
- // range test suite
- it('range format YYYY/MM/DD', function() {
- this.bv.updateOption('range', 'date', 'format', 'YYYY/MM/DD');
- this.bv.updateOption('range', 'date', 'min', '2010/09/10');
- this.bv.updateOption('range', 'date', 'max', '2014/09/10');
- this.$range.val('2011/01/01');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('02014/001/031'); // year, month or day prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('2010/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('2014/09/11');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- });
- it('range format YYYY-MM-DD', function() {
- this.bv.updateOption('range', 'date', 'format', 'YYYY-MM-DD');
- this.bv.updateOption('range', 'date', 'min', '2010-09-10');
- this.bv.updateOption('range', 'date', 'max', '2014-09-10');
- this.$range.val('2012-01-12');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('2014-09-09');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('02014-003-031'); // year, month or day prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('2009-12-31');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('2015-01-01');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- });
- it('range format DD/MM/YYYY', function() {
- this.bv.updateOption('range', 'date', 'format', 'DD/MM/YYYY');
- this.bv.updateOption('range', 'date', 'min', '10/09/2010');
- this.bv.updateOption('range', 'date', 'max', '10/09/2014');
- this.$range.val('11/11/2011');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('17/08/2014');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('031/012/02013'); // year, month or day prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('31/01/2010');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('25/03/2015');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- });
- it('range format YYYY-MM-DD h:m:s', function() {
- this.bv.updateOption('range', 'date', 'format', 'YYYY-MM-DD h:m:s');
- this.bv.updateOption('range', 'date', 'min', '2010-05-15 22:00:00');
- this.bv.updateOption('range', 'date', 'max', '2015-05-15 22:00:00');
- this.$range.val('2012-07-17 01:00:01');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('2013-08-17 12:00:00');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toBeTruthy();
- this.bv.resetForm();
- this.$range.val('2011-06-19 001:001:001'); // hours, minutes or seconds prefixed by 0 not allowed
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('2008-11-27 23:15:00');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- this.bv.resetForm();
- this.$range.val('2015-05-15 22:00:01');
- this.bv.validate();
- expect(this.bv.isValidField('range')).toEqual(false);
- });
- // dynamic min option
- it('dynamic min: name of field', function() {
- this.$minDate.attr('data-bv-date-min', 'date');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2014/09/08');
- this.$minDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/09/08');
- this.$minDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeFalsy();
- });
- it('dynamic min: callback declarative function', function() {
- this.$minDate.attr('data-bv-date-min', 'getDate');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2014/09/08');
- this.$minDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/10/01');
- this.$minDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeFalsy();
- });
- it('dynamic min: callback declarative function()', function() {
- this.$minDate.attr('data-bv-date-min', 'getDate()');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2014/09/08');
- this.$minDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/10/01');
- this.$minDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeFalsy();
- });
- it('dynamic min: callback declarative A.B.C', function() {
- this.$minDate.attr('data-bv-date-min', 'TestSuite.Date.getDate');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2014/09/08');
- this.$minDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/10/01');
- this.$minDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeFalsy();
- });
- it('dynamic min: callback declarative A.B.C()', function() {
- this.$minDate.attr('data-bv-date-min', 'TestSuite.Date.getDate()');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2014/09/08');
- this.$minDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/10/01');
- this.$minDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeFalsy();
- });
- it('dynamic min: callback programmatically', function() {
- this.$minDate.removeAttr('data-bv-date-min');
- this.bv.destroy();
- this.bv = $('#dateForm')
- .bootstrapValidator({
- fields: {
- minDate: {
- validators: {
- date: {
- min: function(value, validator, $field) {
- return getDate(value, validator, $field);
- }
- }
- }
- }
- }
- })
- .data('bootstrapValidator');
- this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2014/09/08');
- this.$minDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/10/01');
- this.$minDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('minDate')).toBeFalsy();
- });
- // dynamic max option
- it('dynamic max: name of field', function() {
- this.$maxDate.attr('data-bv-date-max', 'date');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2015/01/01');
- this.$maxDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/01/01');
- this.$maxDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeFalsy();
- });
- it('dynamic max: callback declarative function', function() {
- this.$maxDate.attr('data-bv-date-max', 'getDate');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2015/01/01');
- this.$maxDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/01/01');
- this.$maxDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeFalsy();
- });
- it('dynamic max: callback declarative function()', function() {
- this.$maxDate.attr('data-bv-date-max', 'getDate()');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2015/01/01');
- this.$maxDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/01/01');
- this.$maxDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeFalsy();
- });
- it('dynamic max: callback declarative A.B.C', function() {
- this.$maxDate.attr('data-bv-date-max', 'TestSuite.Date.getDate');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2015/01/01');
- this.$maxDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/01/01');
- this.$maxDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeFalsy();
- });
- it('dynamic max: callback declarative A.B.C()', function() {
- this.$maxDate.attr('data-bv-date-max', 'TestSuite.Date.getDate()');
- this.bv.destroy();
- this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2015/01/01');
- this.$maxDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/01/01');
- this.$maxDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeFalsy();
- });
- it('dynamic max: callback programmatically', function() {
- this.$maxDate.removeAttr('data-bv-date-max');
- this.bv.destroy();
- this.bv = $('#dateForm')
- .bootstrapValidator({
- fields: {
- maxDate: {
- validators: {
- date: {
- max: function(value, validator, $field) {
- return getDate(value, validator, $field);
- }
- }
- }
- }
- }
- })
- .data('bootstrapValidator');
- this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
- this.$date.val('2015/01/01');
- this.$maxDate.val('2014/09/09');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeTruthy();
- this.bv.resetForm();
- this.$date.val('2014/01/01');
- this.$maxDate.val('2014/08/17');
- this.bv.validate();
- expect(this.bv.isValidField('maxDate')).toBeFalsy();
- });
- });
- describe('ean', function() {
- beforeEach(function() {
- var html = [
- '<div class="container">',
- '<form class="form-horizontal" id="eanForm">',
- '<div class="form-group">',
- '<input type="text" name="ean" data-bv-ean />',
- '</div>',
- '</form>',
- '</div>'
- ].join('\n');
- $(html).appendTo('body');
- $('#eanForm').bootstrapValidator();
- this.bv = $('#eanForm').data('bootstrapValidator');
- this.$ean = this.bv.getFieldElements('ean');
- });
- afterEach(function() {
- $('#eanForm').bootstrapValidator('destroy').parent().remove();
- });
- it('valid', function() {
- var samples = ['73513537', '9780471117094', '4006381333931'];
- for (var i in samples) {
- this.$ean.val(samples[i]);
- this.bv.validate();
- expect(this.bv.isValidField('ean')).toBeTruthy();
- }
- });
- it('contains only digits', function() {
- this.$ean.val('123abcDEF!@#');
- this.bv.validate();
- expect(this.bv.isValidField('ean')).toEqual(false);
- });
- it('invalid length', function() {
- this.$ean.val('1234567');
- this.bv.validate();
- expect(this.bv.isValidField('ean')).toEqual(false);
- });
- it('invalid check digit', function() {
- this.$ean.val('73513536');
- this.bv.validate();
- expect(this.bv.isValidField('ean')).toEqual(false);
- });
- });
- describe('emailAddress', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="emailAddressForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email-address-or-addresses" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#emailAddressForm').bootstrapValidator();
- this.bv = $('#emailAddressForm').data('bootstrapValidator');
- this.$emailAddressOrAddresses = this.bv.getFieldElements('email-address-or-addresses');
- });
- afterEach(function() {
- $('#emailAddressForm').bootstrapValidator('destroy').remove();
- });
- var validEmailAddresses = [
- 'admin@mailserver1',
- 'niceandsimple@example.com',
- 'very.common@example.com',
- 'a.little.lengthy.but.fine@dept.example.com',
- 'disposable.style.email.with+symbol@example.com',
- 'other.email-with-dash@example.com',
- '"much.more unusual"@example.com',
- '"very.unusual.@.unusual.com"@example.com',
- '"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
- '" "@example.org',
- 'üñîçøðé@example.com'
- ];
- var invalidEmailAddresses = [
- // "!#$%&'*+-/=?^_`{}|~@example.org", // This is actually passing validation; see https://github.com/nghuuphuoc/bootstrapvalidator/issues/673
- 'üñîçøðé@üñîçøðé.com',
- 'Abc.example.com',
- 'A@b@c@example.com',
- 'a"b(c)d,e:f;gi[j\k]l@example.com',
- 'just"not"right@example.com',
- 'this is"not\allowed@example.com',
- 'this\ still\"not\\allowed@example.com'
- ];
- var validMultipleEmailAddressesForDefaultSeparators = [
- 'niceandsimple@example.com,very.common@example.com',
- 'niceandsimple@example.com;very.common@example.com',
- 'niceandsimple@example.com;very.common@example.com,a.little.lengthy.but.fine@dept.example.com'
- ];
- var invalidMultipleEmailAddressesForDefaultSeparators = [
- 'niceandsimple@example.com+very.common@example.com',
- 'niceandsimple@example.com|very.common@example.com'
- ];
- var validMultipleEmailAddressesForCommaOrDollarSignSeparators = [
- 'niceandsimple@example.com,very.common@example.com',
- 'niceandsimple@example.com$very.common@example.com',
- 'niceandsimple@example.com,very.common@example.com$a.little.lengthy.but.fine@dept.example.com'
- ];
- var invalidMultipleEmailAddressesForCommaOrDollarSignSeparators = [
- 'niceandsimple@example.com;very.common@example.com',
- 'niceandsimple@example.com;very.common@example.com,a.little.lengthy.but.fine@dept.example.com'
- ];
- it('Valid email addresses (multiple=false)', function() {
- var that = this;
- $.each(validEmailAddresses, function(index, emailAddress) {
- that.bv.resetForm();
- that.$emailAddressOrAddresses.val(emailAddress);
- that.bv.validate();
- expect(that.bv.isValid()).toBeTruthy();
- });
- });
- it('Invalid email addresses (multiple=false)', function() {
- var that = this;
- var addresses = invalidEmailAddresses
- .concat(validMultipleEmailAddressesForDefaultSeparators)
- .concat(invalidMultipleEmailAddressesForDefaultSeparators)
- .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators)
- .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
- $.each(addresses, function(index, emailAddress) {
- that.bv.resetForm();
- that.$emailAddressOrAddresses.val(emailAddress);
- that.bv.validate();
- expect(that.bv.isValid()).toEqual(false);
- });
- });
- it('Invalid email addresses (multiple=false,separator=/[,\$]/)', function() {
- var that = this;
- that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,;]/);
- var addresses = invalidEmailAddresses
- .concat(validMultipleEmailAddressesForDefaultSeparators)
- .concat(invalidMultipleEmailAddressesForDefaultSeparators)
- .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators)
- .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
- $.each(addresses, function(index, emailAddress) {
- that.bv.resetForm();
- that.$emailAddressOrAddresses.val(emailAddress);
- that.bv.validate();
- expect(that.bv.isValid()).toEqual(false);
- });
- });
- it('Valid email addresses (multiple=true)', function() {
- var that = this;
- that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
- var addresses = validEmailAddresses
- .concat(validMultipleEmailAddressesForDefaultSeparators);
- $.each(addresses, function(index, emailAddress) {
- that.bv.resetForm();
- that.$emailAddressOrAddresses.val(emailAddress);
- that.bv.validate();
- expect(that.bv.isValid()).toBeTruthy();
- });
- });
- it('Invalid email addresses (multiple=true)', function() {
- var that = this;
- that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
- var addresses = invalidEmailAddresses
- .concat(invalidMultipleEmailAddressesForDefaultSeparators);
- $.each(addresses, function(index, emailAddress) {
- that.bv.resetForm();
- that.$emailAddressOrAddresses.val(emailAddress);
- that.bv.validate();
- expect(that.bv.isValid()).toEqual(false);
- });
- });
- it('Valid email addresses (multiple=true,separator=/[,\$]/)', function() {
- var that = this;
- that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
- that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,\$]/);
- var addresses = validEmailAddresses
- .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators);
- $.each(addresses, function(index, emailAddress) {
- that.bv.resetForm();
- that.$emailAddressOrAddresses.val(emailAddress);
- that.bv.validate();
- expect(that.bv.isValid()).toBeTruthy();
- });
- });
- it('Invalid email addresses (multiple=true,separator=/[,\$]/)', function() {
- var that = this;
- that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
- that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,\$]/);
- var addresses = invalidEmailAddresses
- .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
- $.each(addresses, function(index, emailAddress) {
- that.bv.resetForm();
- that.$emailAddressOrAddresses.val(emailAddress);
- that.bv.validate();
- expect(that.bv.isValid()).toEqual(false);
- });
- });
- });
- function greaterThanCompare() {
- var compareTo = $('#greaterThanForm').find('[name="minAge"]').val();
- $('#msg').html('greaterThanCompare() called; compare to ' + compareTo);
- return compareTo;
- };
- TestSuite = $.extend({}, TestSuite, {
- greaterThan: {
- compareTo: function(value, validator, $field) {
- var compareTo = $('#greaterThanForm').find('[name="minAge"]').val();
- $('#msg').html('TestSuite.greaterThan.compareTo() called; compare to ' + compareTo);
- return compareTo;
- }
- }
- });
- describe('greaterThan', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="greaterThanForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="minAge" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="age" data-bv-greaterthan data-bv-greaterthan-value="18" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#greaterThanForm').bootstrapValidator();
- this.bv = $('#greaterThanForm').data('bootstrapValidator');
- this.$minAge = this.bv.getFieldElements('minAge');
- this.$age = this.bv.getFieldElements('age');
- });
- afterEach(function() {
- $('#greaterThanForm').bootstrapValidator('destroy').remove();
- });
- it('not a number', function() {
- this.$age.val('20abc');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('compare to value', function() {
- this.$age.val(10);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$age.val(20);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('value with comma separator', function() {
- this.$age.val('10,4');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$age.val('18,678');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('compare to other field', function() {
- this.bv.updateOption('age', 'greaterThan', 'value', 'minAge');
- this.$minAge.val(10);
- this.$age.val(20);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$minAge.val(20);
- this.$age.val(10);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
- });
- // #1048
- it('compare to other field that value has comma', function() {
- this.bv.updateOption('age', 'greaterThan', 'value', 'minAge');
- this.$minAge.val('10,5');
- this.$age.val(20);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$minAge.val('20,5');
- this.$age.val(10);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
- });
- it('compare to return value of a function', function() {
- this.bv.updateOption('age', 'greaterThan', 'value', 'greaterThanCompare');
- this.$minAge.val(20);
- this.$age.val(18);
- this.bv.validate();
- expect($('#msg').html()).toEqual('greaterThanCompare() called; compare to 20');
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
- this.bv.resetForm();
- this.$minAge.val(18);
- this.$age.val(20);
- this.bv.validate();
- expect($('#msg').html()).toEqual('greaterThanCompare() called; compare to 18');
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('compare to return value of a namespace function', function() {
- this.bv.updateOption('age', 'greaterThan', 'value', 'TestSuite.greaterThan.compareTo');
- this.$minAge.val(20);
- this.$age.val(18);
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.greaterThan.compareTo() called; compare to 20');
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
- this.bv.resetForm();
- this.$minAge.val(18);
- this.$age.val(20);
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.greaterThan.compareTo() called; compare to 18');
- expect(this.bv.isValid()).toBeTruthy();
- });
- });
- describe('iban', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="ibanForm">',
- '<div class="form-group">',
- '<select class="form-control" name="country">',
- '<option value="AD">Andorra</option>',
- '<option value="AE">United Arab Emirates</option>',
- '<option value="AL">Albania</option>',
- '<option value="AO">Angola</option>',
- '<option value="AT">Austria</option>',
- '<option value="AZ">Azerbaijan</option>',
- '<option value="BA">Bosnia and Herzegovina</option>',
- '<option value="BE">Belgium</option>',
- '<option value="BF">Burkina Faso</option>',
- '<option value="BG">Bulgaria</option>',
- '<option value="BH">Bahrain</option>',
- '<option value="BI">Burundi</option>',
- '<option value="BJ">Benin</option>',
- '<option value="BR">Brazil</option>',
- '<option value="CH">Switzerland</option>',
- '<option value="CM">Cameroon</option>',
- '<option value="CR">Costa Rica</option>',
- '<option value="CV">Cape Verde</option>',
- '<option value="CY">Cyprus</option>',
- '<option value="CZ">Czech Republic</option>',
- '<option value="DE">Germany</option>',
- '<option value="DK">Denmark</option>',
- '<option value="DO">Dominican Republic</option>',
- '<option value="DZ">Algeria</option>',
- '<option value="EE">Estonia</option>',
- '<option value="ES">Spain</option>',
- '<option value="FI">Finland</option>',
- '<option value="FO">Faroe Islands</option>',
- '<option value="FR">France</option>',
- '<option value="GB">United Kingdom</option>',
- '<option value="GE">Georgia</option>',
- '<option value="GI">Gibraltar</option>',
- '<option value="GL">Greenland</option>',
- '<option value="GR">Greece</option>',
- '<option value="GT">Guatemala</option>',
- '<option value="HR">Croatia</option>',
- '<option value="HU">Hungary</option>',
- '<option value="IE">Ireland</option>',
- '<option value="IL">Israel</option>',
- '<option value="IR">Iran</option>',
- '<option value="IS">Iceland</option>',
- '<option value="IT">Italy</option>',
- '<option value="JO">Jordan</option>',
- '<option value="KW">Kuwait</option>',
- '<option value="KZ">Kazakhstan</option>',
- '<option value="LB">Lebanon</option>',
- '<option value="LI">Liechtenstein</option>',
- '<option value="LT">Lithuania</option>',
- '<option value="LU">Luxembourg</option>',
- '<option value="LV">Latvia</option>',
- '<option value="MC">Monaco</option>',
- '<option value="MD">Moldova</option>',
- '<option value="ME">Montenegro</option>',
- '<option value="MG">Madagascar</option>',
- '<option value="MK">Macedonia</option>',
- '<option value="ML">Mali</option>',
- '<option value="MR">Mauritania</option>',
- '<option value="MT">Malta</option>',
- '<option value="MU">Mauritius</option>',
- '<option value="MZ">Mozambique</option>',
- '<option value="NL">Netherlands</option>',
- '<option value="NO">Norway</option>',
- '<option value="PK">Pakistan</option>',
- '<option value="PL">Poland</option>',
- '<option value="PS">Palestinian</option>',
- '<option value="PT">Portugal</option>',
- '<option value="QA">Qatar</option>',
- '<option value="RO">Romania</option>',
- '<option value="RS">Serbia</option>',
- '<option value="SA">Saudi Arabia</option>',
- '<option value="SE">Sweden</option>',
- '<option value="SE">Slovenia</option>',
- '<option value="SK">Slovakia</option>',
- '<option value="SM">San Marino</option>',
- '<option value="SN">Senegal</option>',
- '<option value="TN">Tunisia</option>',
- '<option value="TR">Turkey</option>',
- '<option value="VG">Virgin Islands, British</option>',
- '</select>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="iban" data-bv-iban />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#ibanForm').bootstrapValidator();
- this.bv = $('#ibanForm').data('bootstrapValidator');
- this.$country = this.bv.getFieldElements('country');
- this.$iban = this.bv.getFieldElements('iban');
- });
- afterEach(function() {
- $('#ibanForm').bootstrapValidator('destroy').remove();
- });
- it('not supported country', function() {
- this.$iban.val('US123456789');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toEqual(false);
- });
- it('dynamic country', function() {
- this.$iban.attr('data-bv-iban-country', 'country');
- this.bv.destroy();
- this.bv = $('#ibanForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('AT');
- this.$iban.val('AT611904300234573201');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$country.val('BG');
- this.$iban.val('HR1210010051863000160');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Albania', function() {
- this.$iban.val('AL47212110090000000235698741');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Algeria', function() {
- this.$iban.val('DZ4000400174401001050486');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Andorra', function() {
- this.$iban.val('AD1200012030200359100100');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Angola', function() {
- this.$iban.val('AO06000600000100037131174');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Austria', function() {
- this.$iban.val('AT611904300234573201');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Azerbaijan', function() {
- this.$iban.val('AZ21NABZ00000000137010001944');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Bahrain', function() {
- this.$iban.val('BH29BMAG1299123456BH00');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Belgium', function() {
- this.$iban.val('BE68539007547034');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Benin', function() {
- this.$iban.val('BJ11B00610100400271101192591');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Brazil', function() {
- this.$iban.val('BR9700360305000010009795493P1');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Bulgaria', function() {
- this.$iban.val('BG80BNBG96611020345678');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Burkina Faso', function() {
- this.$iban.val('BF1030134020015400945000643');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Burundi', function() {
- this.$iban.val('BI43201011067444');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Cameroon', function() {
- this.$iban.val('CM2110003001000500000605306');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Cape Verde', function() {
- this.$iban.val('CV64000300004547069110176');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Costa Rica', function() {
- this.$iban.val('CR0515202001026284066');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Croatia', function() {
- this.$iban.val('HR1210010051863000160');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Cyprus', function() {
- this.$iban.val('CY17002001280000001200527600');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Czech Republic', function() {
- this.$iban.val('CZ6508000000192000145399');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Denmark', function() {
- this.$iban.val('DK5000400440116243');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Dominican Republic', function() {
- this.$iban.val('DO28BAGR00000001212453611324');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Estonia', function() {
- this.$iban.val('EE382200221020145685');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Faroe Islands', function() {
- this.$iban.val('FO1464600009692713');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Finland', function() {
- this.$iban.val('FI2112345600000785');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('France', function() {
- this.$iban.val('FR1420041010050500013M02606');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Guatemala', function() {
- this.$iban.val('GT82TRAJ01020000001210029690');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Georgia', function() {
- this.$iban.val('GE29NB0000000101904917');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Germany', function() {
- this.$iban.val('DE89370400440532013000');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Gibraltar', function() {
- this.$iban.val('GI75NWBK000000007099453');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Greece', function() {
- this.$iban.val('GR1601101250000000012300695');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Greenland', function() {
- this.$iban.val('GL8964710001000206');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Hungary', function() {
- this.$iban.val('HU42117730161111101800000000');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Iceland', function() {
- this.$iban.val('IS140159260076545510730339');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Iran', function() {
- this.$iban.val('IR580540105180021273113007');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Ireland', function() {
- this.$iban.val('IE29AIBK93115212345678');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Israel', function() {
- this.$iban.val('IL620108000000099999999');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Italy', function() {
- this.$iban.val('IT60X0542811101000000123456');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Ivory Coast', function() {
- this.$iban.val('CI05A00060174100178530011852');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Jordan', function() {
- this.$iban.val('JO94CBJO0010000000000131000302');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Kazakhstan', function() {
- this.$iban.val('KZ176010251000042993');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Kuwait', function() {
- this.$iban.val('KW74NBOK0000000000001000372151');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Latvia', function() {
- this.$iban.val('LV80BANK0000435195001');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Lebanon', function() {
- this.$iban.val('LB30099900000001001925579115');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Liechtenstein', function() {
- this.$iban.val('LI21088100002324013AA');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Lithuania', function() {
- this.$iban.val('LT121000011101001000');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Luxembourg', function() {
- this.$iban.val('LU280019400644750000');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Macedonia', function() {
- this.$iban.val('MK07300000000042425');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Madagascar', function() {
- this.$iban.val('MG4600005030010101914016056');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Malta', function() {
- this.$iban.val('MT84MALT011000012345MTLCAST001S');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Mauritania', function() {
- this.$iban.val('MR1300012000010000002037372');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Mauritius', function() {
- this.$iban.val('MU17BOMM0101101030300200000MUR');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Mali', function() {
- this.$iban.val('ML03D00890170001002120000447');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Moldova', function() {
- this.$iban.val('MD24AG000225100013104168');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Monaco', function() {
- this.$iban.val('MC5813488000010051108001292');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Montenegro', function() {
- this.$iban.val('ME25505000012345678951');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Mozambique', function() {
- this.$iban.val('MZ59000100000011834194157');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Netherlands', function() {
- this.$iban.val('NL91ABNA0417164300');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Norway', function() {
- this.$iban.val('NO9386011117947');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Pakistan', function() {
- this.$iban.val('PK24SCBL0000001171495101');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Palestine', function() {
- this.$iban.val('PS92PALS000000000400123456702');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Poland', function() {
- this.$iban.val('PL27114020040000300201355387');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Portugal', function() {
- this.$iban.val('PT50000201231234567890154');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Qatar', function() {
- this.$iban.val('QA58DOHB00001234567890ABCDEFG');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Romania', function() {
- this.$iban.val('RO49AAAA1B31007593840000');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('San Marino', function() {
- this.$iban.val('SM86U0322509800000000270100');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Saudi Arabia', function() {
- this.$iban.val('SA0380000000608010167519');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Senegal', function() {
- this.$iban.val('SN12K00100152000025690007542');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Serbia', function() {
- this.$iban.val('RS35260005601001611379');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Slovakia', function() {
- this.$iban.val('SK3112000000198742637541');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Slovenia', function() {
- this.$iban.val('SI56191000000123438');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Spain', function() {
- this.$iban.val('ES9121000418450200051332');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Sweden', function() {
- this.$iban.val('SE3550000000054910000003');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Switzerland', function() {
- this.$iban.val('CH9300762011623852957');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Tunisia', function() {
- this.$iban.val('TN5914207207100707129648');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Turkey', function() {
- this.$iban.val('TR330006100519786457841326');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('United Arab Emirates', function() {
- this.$iban.val('AE260211000000230064016');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('United Kingdom', function() {
- this.$iban.val('GB29NWBK60161331926819');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('Virgin Islands, British', function() {
- this.$iban.val('VG96VPVG0000012345678901');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toBeTruthy();
- });
- it('invalid checksum', function() {
- this.$iban.val('TR330006100519786457841325');
- this.bv.validate();
- expect(this.bv.isValidField('iban')).toEqual(false);
- });
- });
- describe('id', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="idForm">',
- '<div class="form-group">',
- '<select class="form-control" name="country">',
- '<option value="BA">Bosnia and Herzegovina</option>',
- '<option value="BG">Bulgaria</option>',
- '<option value="BR">Brazil</option>',
- '<option value="CH">Switzerland</option>',
- '<option value="CL">Chile</option>',
- '<option value="CN">China</option>',
- '<option value="CZ">Czech</option>',
- '<option value="DK">Denmark</option>',
- '<option value="EE">Estonia</option>',
- '<option value="ES">Spain</option>',
- '<option value="FI">Finland</option>',
- '<option value="HR">Croatia</option>',
- '<option value="IE">Ireland</option>',
- '<option value="IS">Iceland</option>',
- '<option value="LT">Lithuania</option>',
- '<option value="LV">Latvia</option>',
- '<option value="ME">Montenegro</option>',
- '<option value="MK">Macedonia</option>',
- '<option value="NL">Netherlands</option>',
- '<option value="RO">Romania</option>',
- '<option value="RS">Serbia</option>',
- '<option value="SE">Sweden</option>',
- '<option value="SI">Slovenia</option>',
- '<option value="SK">Slovakia</option>',
- '<option value="SM">San Marino</option>',
- '<option value="TH">Thailand</option>',
- '<option value="ZA">South Africa</option>',
- '</select>',
- '</div>',
- '<div class="form-group">',
- '<input class="form-control" type="text" name="id" data-bv-id />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#idForm').bootstrapValidator();
- /**
- * @type {BootstrapValidator}
- */
- this.bv = $('#idForm').data('bootstrapValidator');
- this.$country = this.bv.getFieldElements('country');
- this.$id = this.bv.getFieldElements('id');
- });
- afterEach(function() {
- $('#idForm').bootstrapValidator('destroy').remove();
- });
- it('dynamic country', function() {
- this.$id.attr('data-bv-id-country', 'country');
- this.bv.destroy();
- this.bv = $('#idForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('BG');
- this.$id.val('7552010005');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$country.val('BR');
- this.$id.val('231.002.999-00');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Bulgarian national identification number (EGN)', function() {
- this.bv.updateOption('id', 'id', 'country', 'BG');
- // Valid samples
- var validSamples = ['7523169263', '8032056031', '803205 603 1', '8001010008', '7501020018', '7552010005', '7542011030'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['8019010008'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Brazilian national identification number (CPF)', function() {
- this.bv.updateOption('id', 'id', 'country', 'BR');
- // Valid samples
- var validSamples = ['39053344705', '390.533.447-05', '111.444.777-35'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['231.002.999-00'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Swiss Social Security Number (AHV-Nr/No AVS)', function() {
- this.bv.updateOption('id', 'id', 'country', 'CH');
- // Valid samples
- var validSamples = ['756.1234.5678.95', '7561234567895'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('Chilean national identification number (RUN/RUT)', function() {
- this.bv.updateOption('id', 'id', 'country', 'CL');
- // Valid samples
- var validSamples = ['76086428-5', '22060449-7', '12531909-2','12937893-K','12937893-k'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- // #793
- it('Chinese citizen identification number', function() {
- this.bv.updateOption('id', 'id', 'country', 'CN');
- // Valid samples
- var validSamples = ['450202201409072332', '22011219930407001X', '110108601017023'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['999999199304070016', '220112190002290016', '220112199304070019', '999999601017023', '110108999999023'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Czech national identification number (RC)', function() {
- this.bv.updateOption('id', 'id', 'country', 'CZ');
- // Valid samples
- var validSamples = ['7103192745', '991231123'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['1103492745', '590312123'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Danish Personal Identification number (CPR)', function() {
- this.bv.updateOption('id', 'id', 'country', 'DK');
- // Valid samples
- var validSamples = ['2110625629', '211062-5629'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['511062-5629'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Estonian Personal Identification Code (isikukood)', function() {
- this.bv.updateOption('id', 'id', 'country', 'EE');
- // Valid samples
- var validSamples = ['37605030299'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('Spanish personal identity code (DNI/NIE)', function() {
- this.bv.updateOption('id', 'id', 'country', 'ES');
- // Valid samples
- var validSamples = ['54362315K', '54362315-K', 'X2482300W', 'X-2482300W', 'X-2482300-W'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['54362315Z', 'X-2482300A'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Finnish Personal Identity Code (HETU)', function() {
- this.bv.updateOption('id', 'id', 'country', 'FI');
- // Valid samples
- var validSamples = ['311280-888Y', '131052-308T'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['131052-308U', '310252-308Y'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Croatian personal identification number (OIB)', function() {
- this.bv.updateOption('id', 'id', 'country', 'HR');
- // Valid samples
- var validSamples = ['33392005961'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['33392005962'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Irish Personal Public Service Number (PPS)', function() {
- this.bv.updateOption('id', 'id', 'country', 'IE');
- // Valid samples
- var validSamples = ['6433435F', '6433435FT', '6433435FW', '6433435OA', '6433435IH', '1234567TW', '1234567FA'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['6433435E', '6433435VH'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Iceland national identification number (Kennitala)', function() {
- this.bv.updateOption('id', 'id', 'country', 'IS');
- // Valid samples
- var validSamples = ['120174-3399', '1201743399', '0902862349'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('Lithuanian Personal Code (Asmens kodas)', function() {
- this.bv.updateOption('id', 'id', 'country', 'LT');
- // Valid samples
- var validSamples = ['38703181745'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['38703181746', '78703181745', '38703421745'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Latvian Personal Code (Personas kods)', function() {
- this.bv.updateOption('id', 'id', 'country', 'LV');
- // Valid samples
- var validSamples = ['161175-19997', '16117519997'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['161375-19997'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Dutch national identification number (BSN)', function() {
- this.bv.updateOption('id', 'id', 'country', 'NL');
- // Valid samples
- var validSamples = ['111222333', '941331490', '9413.31.490'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['111252333'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Romanian numerical personal code (CNP)', function() {
- this.bv.updateOption('id', 'id', 'country', 'RO');
- // Valid samples
- var validSamples = ['1630615123457', '1800101221144'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['8800101221144', '1632215123457', '1630615123458'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Swedish personal identity number (personnummer)', function() {
- this.bv.updateOption('id', 'id', 'country', 'SE');
- // Valid samples
- var validSamples = ['8112289874', '811228-9874', '811228+9874'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['811228-9873'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Slovak national identifier number (RC)', function() {
- this.bv.updateOption('id', 'id', 'country', 'SK');
- // Valid samples
- var validSamples = ['7103192745', '991231123'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['7103192746', '1103492745'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('South African ID', function() {
- this.bv.updateOption('id', 'id', 'country', 'ZA');
- // Valid samples
- var validSamples = ['8001015009087'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['8001015009287', '8001015009086'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Thailand citizen number', function() {
- this.bv.updateOption('id', 'id', 'country', 'TH');
- // Valid samples
- var validSamples = ['7145620509547', '3688699975685', '2368719339716'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$id.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['1100800092310'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$id.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- });
- describe('imo', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="imoForm">',
- '<div class="form-group">',
- '<input type="text" name="imo" data-bv-imo />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#imoForm').bootstrapValidator();
- this.bv = $('#imoForm').data('bootstrapValidator');
- this.$imo = this.bv.getFieldElements('imo');
- });
- afterEach(function() {
- $('#imoForm').bootstrapValidator('destroy').remove();
- });
- it('Valid IMO (upper)', function() {
- this.bv.resetForm();
- this.$imo.val('IMO 9074729');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid IMO (lower)', function() {
- this.bv.resetForm();
- this.$imo.val('imo 9074729');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Invalid IMO (bad format)', function() {
- this.bv.resetForm();
- this.$imo.val('9074729');
- this.bv.validate();
- expect(this.bv.isValid()).toBeFalsy();
- });
- it('Invalid IMO (bad check digit)', function() {
- this.bv.resetForm();
- this.$imo.val('IMO 9074728');
- this.bv.validate();
- expect(this.bv.isValid()).toBeFalsy();
- });
- });
- describe('ip', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="ipForm">',
- '<div class="form-group">',
- '<input type="text" name="ipv4" data-bv-ip data-bv-ip-ipv6="false" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="ipv6" data-bv-ip data-bv-ip-ipv4="false" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="both" data-bv-ip />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#ipForm').bootstrapValidator();
- this.bv = $('#ipForm').data('bootstrapValidator');
- this.$ipv4 = this.bv.getFieldElements('ipv4');
- this.$ipv6 = this.bv.getFieldElements('ipv6');
- this.$both = this.bv.getFieldElements('both');
- });
- afterEach(function() {
- $('#ipForm').bootstrapValidator('destroy').remove();
- });
- it('Valid ipv4', function() {
- this.$ipv4.val('0.0.0.0');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
-
- this.bv.resetForm();
- this.$ipv4.val('192.168.1.1');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
-
- this.bv.resetForm();
- this.$ipv4.val('255.255.255.255');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
-
- it('Invalid ipv4', function() {
- this.$ipv4.val('10.168.0001.100'); // extra 0 not allowed
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv4.val('0.0.0.256'); // 256 not allowed, max is 255
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv4.val('256.255.255.255'); // max is 255.255.255.255
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv4.val('192.168. 224.0'); // internal space
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv4.val('192.168.224.0 1'); // junk after valid address
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Valid ipv6', function() {
- this.$ipv6.val('0000:0000:0000:0000:0000:0000:0000:0000');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
-
- this.bv.resetForm();
- this.$ipv6.val('fe00::1');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
-
- this.bv.resetForm();
- this.$ipv6.val('fe80::217:f2ff:fe07:ed62');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
-
- this.bv.resetForm();
- this.$ipv6.val('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
-
- it('Invalid ipv6', function() {
- this.$ipv6.val('02001:0000:1234:0000:0000:C1C0:ABCD:0876'); // extra 0 not allowed
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv6.val('2001:0000:1234:0000:00001:C1C0:ABCD:0876'); // extra 0 not allowed
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv6.val('2001:0000:1234: 0000:0000:C1C0:ABCD:0876'); // internal space
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv6.val('2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'); // junk after valid address
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv6.val('3ffe:0b00:0000:0001:0000:0000:000a'); // seven segment
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv6.val('FF02:0000:0000:0000:0000:0000:0000:0000:0001'); // nine segment
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv6.val('::1111:2222:3333:4444:5555:6666::'); // double "::"
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
-
- this.bv.resetForm();
- this.$ipv6.val('3ffe:b00::1::a'); // double "::"
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Both', function() {
- this.$both.val('255.255.255.255'); // valid
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
-
- this.bv.resetForm();
- this.$both.val('256.0.0.0'); // 256 not allowed, max is 255
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$both.val('2001:0db8:0000:85a3:0000:0000:ac1f:8001'); // valid
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
-
- this.bv.resetForm();
- this.$both.val('2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'); // junk after valid address
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- });
- describe('isbn', function() {
- beforeEach(function() {
- var html = [
- '<div class="container">',
- '<form class="form-horizontal" id="isbnForm">',
- '<div class="form-group">',
- '<input type="text" name="isbn" data-bv-isbn />',
- '</div>',
- '</form>',
- '</div>'
- ].join('\n');
- $(html).appendTo('body');
- $('#isbnForm').bootstrapValidator();
- this.bv = $('#isbnForm').data('bootstrapValidator');
- this.$isbn = this.bv.getFieldElements('isbn');
- });
- afterEach(function() {
- $('#isbnForm').bootstrapValidator('destroy').parent().remove();
- });
- it('isbn10 hyphen', function() {
- var samples = ['99921-58-10-7', '9971-5-0210-0', '960-425-059-0', '80-902734-1-6'];
- for (var i in samples) {
- this.$isbn.val(samples[i]);
- this.bv.validate();
- expect(this.bv.isValidField('isbn')).toBeTruthy();
- }
- });
- it('isbn10 space', function() {
- var samples = ['85 359 0277 5', '1 84356 028 3', '0 684 84328 5', '0 85131 041 9', '0 943396 04 2'];
- for (var i in samples) {
- this.$isbn.val(samples[i]);
- this.bv.validate();
- expect(this.bv.isValidField('isbn')).toBeTruthy();
- }
- });
- it('isbn10 hyphen with X', function() {
- var samples = ['0-8044-2957-X', '0-9752298-0-X'];
- for (var i in samples) {
- this.$isbn.val(samples[i]);
- this.bv.validate();
- expect(this.bv.isValidField('isbn')).toBeTruthy();
- }
- });
- it('isbn10 invalid check digit', function() {
- this.$isbn.val('99921-58-10-6');
- this.bv.validate();
- expect(this.bv.isValidField('isbn')).toEqual(false);
- });
- it('isbn13', function() {
- this.$isbn.val('978-0-306-40615-7');
- this.bv.validate();
- expect(this.bv.isValidField('isbn')).toBeTruthy();
- });
- it('isbn13 invalid check digit', function() {
- this.$isbn.val('978-0-306-40615-6');
- this.bv.validate();
- expect(this.bv.isValidField('isbn')).toEqual(false);
- });
- });
- describe('isin', function() {
- beforeEach(function() {
- var html = [
- '<div class="container">',
- '<form class="form-horizontal" id="isinForm">',
- '<div class="form-group">',
- '<input type="text" name="isin" data-bv-isin />',
- '</div>',
- '</form>',
- '</div>'
- ].join('\n');
- $(html).appendTo('body');
- $('#isinForm').bootstrapValidator();
- this.bv = $('#isinForm').data('bootstrapValidator');
- this.$isin = this.bv.getFieldElements('isin');
- });
- afterEach(function() {
- $('#isinForm').bootstrapValidator('destroy').parent().remove();
- });
- it('valid', function() {
- var samples = ['US0378331005', 'AU0000XVGZA3', 'GB0002634946'];
- for (var i in samples) {
- this.$isin.val(samples[i]);
- this.bv.validate();
- expect(this.bv.isValidField('isin')).toBeTruthy();
- }
- });
- it('invalid country code', function() {
- this.$isin.val('AA0000XVGZA3');
- this.bv.validate();
- expect(this.bv.isValidField('isin')).toEqual(false);
- });
- it('contains only digits and alphabet', function() {
- this.$isin.val('US12345ABC@#$');
- this.bv.validate();
- expect(this.bv.isValidField('isin')).toEqual(false);
- });
- it('invalid length', function() {
- this.$isin.val('US1234567');
- this.bv.validate();
- expect(this.bv.isValidField('isin')).toEqual(false);
- });
- it('invalid check digit', function() {
- this.$isin.val('US0378331004');
- this.bv.validate();
- expect(this.bv.isValidField('isin')).toEqual(false);
- });
- });
- describe('ismn', function() {
- beforeEach(function() {
- var html = [
- '<div class="container">',
- '<form class="form-horizontal" id="ismnForm">',
- '<div class="form-group">',
- '<input type="text" name="ismn" data-bv-ismn />',
- '</div>',
- '</form>',
- '</div>'
- ].join('\n');
- $(html).appendTo('body');
- $('#ismnForm').bootstrapValidator();
- this.bv = $('#ismnForm').data('bootstrapValidator');
- this.$ismn = this.bv.getFieldElements('ismn');
- });
- afterEach(function() {
- $('#ismnForm').bootstrapValidator('destroy').parent().remove();
- });
- it('valid start with M', function() {
- this.$ismn.val('M230671187');
- this.bv.validate();
- expect(this.bv.isValidField('ismn')).toBeTruthy();
- });
- it('valid start with 979', function() {
- this.$ismn.val('9790060115615');
- this.bv.validate();
- expect(this.bv.isValidField('ismn')).toBeTruthy();
- });
- it('valid contains spaces', function() {
- this.$ismn.val('979 0 3452 4680 5');
- this.bv.validate();
- expect(this.bv.isValidField('ismn')).toBeTruthy();
- });
- it('valid contains dashes', function() {
- this.$ismn.val('979-0-0601-1561-5');
- this.bv.validate();
- expect(this.bv.isValidField('ismn')).toBeTruthy();
- });
- it('invalid format', function() {
- this.$ismn.val('N123456789');
- this.bv.validate();
- expect(this.bv.isValidField('ismn')).toEqual(false);
- });
- it('invalid check digit', function() {
- this.$ismn.val('9790060115614');
- this.bv.validate();
- expect(this.bv.isValidField('ismn')).toEqual(false);
- });
- });
- describe('issn', function() {
- beforeEach(function() {
- var html = [
- '<div class="container">',
- '<form class="form-horizontal" id="issnForm">',
- '<div class="form-group">',
- '<input type="text" name="issn" data-bv-issn />',
- '</div>',
- '</form>',
- '</div>'
- ].join('\n');
- $(html).appendTo('body');
- $('#issnForm').bootstrapValidator();
- this.bv = $('#issnForm').data('bootstrapValidator');
- this.$issn = this.bv.getFieldElements('issn');
- });
- afterEach(function() {
- $('#issnForm').bootstrapValidator('destroy').parent().remove();
- });
- it('valid', function() {
- var samples = ['0378-5955', '0024-9319', '0032-1478'];
- for (var i in samples) {
- this.$issn.val(samples[i]);
- this.bv.validate();
- expect(this.bv.isValidField('issn')).toBeTruthy();
- }
- });
- it('not contains hyphen', function() {
- this.$issn.val('03785955');
- this.bv.validate();
- expect(this.bv.isValidField('issn')).toEqual(false);
- });
- it('contains only digits, X', function() {
- this.$issn.val('1234-566A');
- this.bv.validate();
- expect(this.bv.isValidField('issn')).toEqual(false);
- });
- it('invalid check sum', function() {
- this.$issn.val('0032-147X');
- this.bv.validate();
- expect(this.bv.isValidField('issn')).toEqual(false);
- });
- });
- function lessThanCompare() {
- var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
- $('#msg').html('lessThanCompare() called; compare to ' + compareTo);
- return compareTo;
- };
- TestSuite = $.extend({}, TestSuite, {
- lessThan: {
- compareTo: function(value, validator, $field) {
- var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
- $('#msg').html('TestSuite.lessThan.compareTo() called; compare to ' + compareTo);
- return compareTo;
- }
- }
- });
- describe('lessThan', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="lessThanForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="maxAge" />',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="age" data-bv-lessthan data-bv-lessthan-value="100" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#lessThanForm').bootstrapValidator();
- this.bv = $('#lessThanForm').data('bootstrapValidator');
- this.$maxAge = this.bv.getFieldElements('maxAge');
- this.$age = this.bv.getFieldElements('age');
- });
- afterEach(function() {
- $('#lessThanForm').bootstrapValidator('destroy').remove();
- });
- it('not a number', function() {
- this.$age.val('20abc');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('value with comma separator', function() {
- this.$age.val('120,2234');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$age.val('30,2234');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('compare to value', function() {
- this.$age.val(120);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$age.val(30);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('compare to other field', function() {
- this.bv.updateOption('age', 'lessThan', 'value', 'maxAge');
- this.$maxAge.val(40);
- this.$age.val(20);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$maxAge.val(20);
- this.$age.val(30);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
- });
- // #1048
- it('compare to other field that value has comma', function() {
- this.bv.updateOption('age', 'lessThan', 'value', 'maxAge');
- this.$maxAge.val('30,5');
- this.$age.val(20);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$maxAge.val('20,5');
- this.$age.val(30);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
- });
- it('compare to return value of a function', function() {
- this.bv.updateOption('age', 'lessThan', 'value', 'lessThanCompare');
- this.$maxAge.val(50);
- this.$age.val(60);
- this.bv.validate();
- expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 50');
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
- this.bv.resetForm();
- this.$maxAge.val(60);
- this.$age.val(30);
- this.bv.validate();
- expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 60');
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('compare to return value of a namespace function', function() {
- this.bv.updateOption('age', 'lessThan', 'value', 'TestSuite.lessThan.compareTo');
- this.$maxAge.val(50);
- this.$age.val(60);
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 50');
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
- this.bv.resetForm();
- this.$maxAge.val(60);
- this.$age.val(30);
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 60');
- expect(this.bv.isValid()).toBeTruthy();
- });
- });
- describe('meid', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="meidForm">',
- '<div class="form-group">',
- '<input type="text" name="meid" data-bv-meid />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#meidForm').bootstrapValidator();
- this.bv = $('#meidForm').data('bootstrapValidator');
- this.$meid = this.bv.getFieldElements('meid');
- });
- afterEach(function() {
- $('#meidForm').bootstrapValidator('destroy').remove();
- });
- it('Valid MEID (14 hex, check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('A00000049259B16');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (14 hex, dashes, check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('A0-000004-9259B1-6');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (14 hex, spaces, check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('A0 000004 9259B1 6');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (18 dec, check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('2936087365007037100');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (18 dec, dashes, check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('29360-87365-0070-3710-0');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (18 dec, spaces, check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('29360 87365 0070 3710 0');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (14 hex)', function() {
- this.bv.resetForm();
- this.$meid.val('AF0123450ABCDE');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (14 hex, dashes)', function() {
- this.bv.resetForm();
- this.$meid.val('AF-012345-0ABCDE');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (14 hex, spaces)', function() {
- this.bv.resetForm();
- this.$meid.val('AF 012345 0ABCDE');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (18 dec)', function() {
- this.bv.resetForm();
- this.$meid.val('293608736500703710');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (18 dec, dashes)', function() {
- this.bv.resetForm();
- this.$meid.val('29360-87365-0070-3710');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid MEID (18 dec, spaces)', function() {
- this.bv.resetForm();
- this.$meid.val('29360 87365 0070 3710');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Invalid MEID (14 hex, bad check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('A00000049259B15');
- this.bv.validate();
- expect(this.bv.isValid()).toBeFalsy();
- });
- it('Invalid MEID (13 hex)', function() {
- this.bv.resetForm();
- this.$meid.val('A00000049259B');
- this.bv.validate();
- expect(this.bv.isValid()).toBeFalsy();
- });
- it('Invalid MEID (18 dec, bad check digit)', function() {
- this.bv.resetForm();
- this.$meid.val('2936087365007037101');
- this.bv.validate();
- expect(this.bv.isValid()).toBeFalsy();
- });
- it('Invalid MEID (17 dec)', function() {
- this.bv.resetForm();
- this.$meid.val('29360873650070371');
- this.bv.validate();
- expect(this.bv.isValid()).toBeFalsy();
- });
- });
- describe('phone', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="phoneForm">',
- '<div class="form-group">',
- '<select class="form-control" name="country">',
- '<option value="BR">Brazil</option>',
- '<option value="CN">China</option>',
- '<option value="CZ">Czech Republic</option>',
- '<option value="DE">Gemany</option>',
- '<option value="DK">Denmark</option>',
- '<option value="ES">Spain</option>',
- '<option value="FR">France</option>',
- '<option value="GB">United Kingdom</option>',
- '<option value="MA">Morocco</option>',
- '<option value="PK">Pakistan</option>',
- '<option value="RO">Romania</option>',
- '<option value="RU">Russia</option>',
- '<option value="SK">Slovakia</option>',
- '<option value="TH">Thailand</option>',
- '<option value="US">USA</option>',
- '<option value="VE">Venezuela</option>',
- '</select>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="phone" data-bv-phone />',
- '</div>',
- '</form>',
- ].join('\n')).appendTo('body');
- $('#phoneForm').bootstrapValidator();
- /**
- * @type {BootstrapValidator}
- */
- this.bv = $('#phoneForm').data('bootstrapValidator');
- this.$country = this.bv.getFieldElements('country');
- this.$phone = this.bv.getFieldElements('phone');
- });
- afterEach(function() {
- $('#phoneForm').bootstrapValidator('destroy').remove();
- });
- it('dynamic country', function() {
- this.$phone.attr('data-bv-phone-country', 'country');
- this.bv.destroy();
- this.bv = $('#phoneForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('BR');
- this.$phone.val('16920894635');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$country.val('FR');
- this.$phone.val('0644444444');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$country.val('GB');
- this.$phone.val('012345678900');
- this.bv.validate();
- expect(this.bv.isValid()).toBeFalsy();
- });
- it('Brazil phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'BR');
- // Valid samples
- var validSamples = [
- '0800.000.00.00', '0800-000-00-00', '0800 000 00 00', '0800-00-00-00', '0800.00.00.00', '0800 00 00 00',
- '0800-000-0000', '0800 000 0000', '0800.000.0000', '08000000000',
- '1692089-4635', '16920894635', '16992089-4635', '16 99202-4635', '(16)99202-4635', '(16)92089-4635',
- '(16) 92089-4635', '(15) 4343-4343', '+55 15 3702-7523', '(+55) 15 3702-7523', '(+55)1537027523',
- '(+55)(15)3702-7523', '(+55) 15 3702-7523', '(+55) 15 99202-7523', '99202-4635', '(16) 9208-4635'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('China phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'CN');
- // Valid samples
- var validSamples = [
- '18911111111', '189 1111 1111', '189-1111-1111', '0086-18911111111', '+86-18911111111',
- '86-18911111111', '0086 18911111111', '+86 18911111111', '86 18911111111', '0086 189-1111-1111',
- '+86 189-1111-1111', '86 189-1111-1111', '02011111111', '020-11111111', '020 11111111',
- '020 1111 1111', '020-1111-1111', '0086 020 82803159', '0086-020-82803159', '0086-020-82803159',
- '+86 20 61302222-8866', '+86 20 6130-2222-8866', '+86 10 59081185'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('Czech Republic phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'CZ');
- // Valid samples
- var validSamples = [
- '00420123456789', '00420 123456789', '00420 123 456 789', '00 420 123 456 789',
- '+420123456789', '+420 123456789', '+420 123 456 789', '123456789', '123 456 789'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = [
- '420123456789', '420 123456789', '420 123 456 789', '00421123456789', '00421 123456789',
- '00421 123 456 789', '00 421 123 456 789', '+421123456789', '+421 123456789',
- '+421 123 456 789'
- ];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$phone.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('France phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'FR');
- // Valid samples
- var validSamples = [
- // National formats
- '0644444444', '06 44 44 44 44', '06-44-44-44-44', '06.44.44.44.44',
- // International formats
- '+33644444444', '+336.44.44.44.44', '+33 6.44.44.44.44', '0033644444444', '00336.44.44.44.44',
- '0033 6.44.44.44.44',
- // Some times
- '+33(0)644444444', '+33 (0) 644444444'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = [
- // The separator between pairs of digits is not the same
- '06 44.44-44.44', '06 44 44-44.44', '06 44 44-4444', '06 44 44-4444',
- // Too many digits
- '06444444444444',
- // Missing leading 0
- '6644444444',
- // Too much non-numeric characters
- '06 44.44-44.44', '+33 (0) 644444444',
- // Bad parenthesis
- '(0)644444444',
- // Bad separator after the international prefix
- '+33-(0)-644444444', '+33 (0)-644444444', '+33-(0) 644444444',
- // Trailing separator
- '06.44.44.44.44.'
- ];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$phone.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Germany phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'DE');
- // Valid samples
- var validSamples = ['+49(89)123456', '089-1234567', '0891234567', '0049-89-123456', '089 123456-78'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('United Kingdom phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'GB');
- // Valid samples
- var validSamples = [
- // National formats
- '01611234567', '0161 123 4567', '(0161) 123 4567', '0161-123-4567',
- // International formats
- '+44 161 123 4567', '+441611234567', '+44(0)161234567', '00 44 161 1234567', '(011) 44 161 234567', '0161-158-5587',
- // Extensions
- '0161 123 4567 ext. 123', '01611234567x123', '+44161234567x123', '+44 (0) 161 1234567 ext 123'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = [
- '012345678900', // Too many digits
- '1611234567', // Missing trunk
- '012345678', // Not enough digits
- '123 4567', // Missing area code
- '061 123 4567' // Invalid area code
- ];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$phone.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Morocco phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'MA');
- // Valid samples
- var validSamples = [
- // National formats
- '0644444444', '0610245896', '0630548564', '06 44 44 44 44', '06-44-44-44-44', '06.44.44.44.44', '06 44.44-44.44',
- '0528254856', '0535484541', '05 28 44 44 44', '05-28-44.44.44', '05.28.44.44.44', '05 28.44-44.44',
- // International formats
- '+212644444444', '+2126.44.44.44.44', '+212 6.44.44.44.44', '00212644444444', '002126.44.44.44.44', '00212 6.44.44.44.44',
- // Some times
- '+212(0)644444444', '+212 (0) 644444444'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = [
- '0625468961', '0512548632', '0542564896', // Not a valid phone numbers
- '06444444444444', // Too many digits
- '6644444444', // Missing leading 0
- '06 44.44-44.44', '+212 (0) 644444444', // Too much non-numeric characters
- '(0)644444444' // Bad parenthesis
- ];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$phone.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Pakistan phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'PK');
- // Valid samples
- var validSamples = ['03336527366'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('Romania phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'RO');
- // Valid samples
- var validSamples = [
- '+40213-564-864', '+40213.564.864', '+40213 564 864', '0213-564-864',
- '0213564864', '0313564864',
- '0720512346', '0730512346', '0740512346', '0750512346', '+40750512346', '+40750.512.346',
- '0760512346', '0770512346', '0780512346'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = [
- '0213/564/864', // Invalid separator
- '0413564864', // Invalid land line number (The valid one should be +402, +403 or inside country 02 - 03)
- '0790512346' // Invalid mobile phone number (The valid one is 072xxxxxxx - 078xxxxxxx)
- ];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$phone.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Russia phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'RU');
- // Valid samples
- var validSamples = ['+7(911)976-91-04'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('Slovakia phone number', function() {
- this.bv.updateOption('phone', 'phone', 'country', 'SK');
- // Valid samples
- var validSamples = [
- '00420123456789', '00420 123456789', '00420 123 456 789', '00 420 123 456 789',
- '+420123456789', '+420 123456789', '+420 123 456 789', '123456789', '123 456 789'
- ];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$phone.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = [
- '420123456789', '420 123456789', '420 123 456 789', '00421123456789', '00421 123456789',
- '00421 123 456 789', '00 421 123 456 789', '+421123456789', '+421 123456789',
- '+421 123 456 789'
- ];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$phone.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- });
- describe('stringLength', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="stringLengthForm">',
- '<div class="form-group">',
- '<input type="text" name="textCharMaxLength" data-bv-stringlength data-bv-stringlength-max="10" />',
- '</div>',
- '<div class="form-group">',
- '<textarea name="textareaCharMaxLength" data-bv-stringlength data-bv-stringlength-max="10"></textarea>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="textUTF8BytesMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-max="10" />',
- '</div>',
- '<div class="form-group">',
- '<textarea name="textareaUTF8BytesMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-max="10"></textarea>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="textCharMinLength" data-bv-stringlength data-bv-stringlength-min="5" />',
- '</div>',
- '<div class="form-group">',
- '<textarea name="textareaCharMinLength" data-bv-stringlength data-bv-stringlength-min="5"></textarea>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="textUTF8BytesMinLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" />',
- '</div>',
- '<div class="form-group">',
- '<textarea name="textareaUTF8BytesMinLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5"></textarea>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="textCharMinMaxLength" data-bv-stringlength data-bv-stringlength-min="5" data-bv-stringlength-max="10" />',
- '</div>',
- '<div class="form-group">',
- '<textarea name="textareaCharMinMaxLength" data-bv-stringlength data-bv-stringlength-min="5" data-bv-stringlength-max="10"></textarea>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="textUTF8BytesMinMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" data-bv-stringlength-max="10" />',
- '</div>',
- '<div class="form-group">',
- '<textarea name="textareaUTF8BytesMinMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" data-bv-stringlength-max="10"></textarea>',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#stringLengthForm').bootstrapValidator();
- this.bv = $('#stringLengthForm').data('bootstrapValidator');
- this.$textCharMaxLength = this.bv.getFieldElements('textCharMaxLength');
- this.$textareaCharMaxLength = this.bv.getFieldElements('textareaCharMaxLength');
- this.$textUTF8BytesMaxLength = this.bv.getFieldElements('textUTF8BytesMaxLength');
- this.$textareaUTF8BytesMaxLength = this.bv.getFieldElements('textareaUTF8BytesMaxLength');
- this.$textCharMinLength = this.bv.getFieldElements('textCharMinLength');
- this.$textareaCharMinLength = this.bv.getFieldElements('textareaCharMinLength');
- this.$textUTF8BytesMinLength = this.bv.getFieldElements('textUTF8BytesMinLength');
- this.$textareaUTF8BytesMinLength = this.bv.getFieldElements('textareaUTF8BytesMinLength');
- this.$textCharMinMaxLength = this.bv.getFieldElements('textCharMinMaxLength');
- this.$textareaCharMinMaxLength = this.bv.getFieldElements('textareaCharMinMaxLength');
- this.$textUTF8BytesMinMaxLength = this.bv.getFieldElements('textUTF8BytesMinMaxLength');
- this.$textareaUTF8BytesMinMaxLength = this.bv.getFieldElements('textareaUTF8BytesMinMaxLength');
- });
- afterEach(function() {
- $('#stringLengthForm').bootstrapValidator('destroy').remove();
- });
- it('Valid max lengths', function() {
- this.$textCharMaxLength.val('123456789♥');
- this.$textareaCharMaxLength.val('123456789♥');
- this.$textUTF8BytesMaxLength.val('1234567♥');
- this.$textareaUTF8BytesMaxLength.val('1234567♥');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid min lengths', function() {
- this.$textCharMinLength.val('1234♥');
- this.$textareaCharMinLength.val('1234♥');
- this.$textUTF8BytesMinLength.val('12♥');
- this.$textareaUTF8BytesMinLength.val('12♥');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Valid min and max lengths', function() {
- this.$textCharMinMaxLength.val('1234♥');
- this.$textareaCharMinMaxLength.val('1234♥');
- this.$textUTF8BytesMinMaxLength.val('12♥');
- this.$textareaUTF8BytesMinMaxLength.val('12♥');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$textCharMinMaxLength.val('123456789♥');
- this.$textareaCharMinMaxLength.val('123456789♥');
- this.$textUTF8BytesMinMaxLength.val('1234567♥');
- this.$textareaUTF8BytesMinMaxLength.val('1234567♥');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('Invalid max lengths', function() {
- this.$textCharMaxLength.val('1234567890♥'); // 11 chars when max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaCharMaxLength.val('1234567890♥'); // 11 chars when max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Invalid min lengths', function() {
- this.$textCharMinLength.val('123♥'); // 4 chars when min is 5
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaCharMinLength.val('123♥'); // 4 chars when min is 5
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Invalid min and max lengths', function() {
- this.$textCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textareaUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('trim option', function() {
- this.bv.updateOption('textCharMaxLength', 'stringLength', 'trim', false);
- this.$textCharMaxLength.val('');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(true);
- this.bv.resetForm();
- this.$textCharMaxLength.val(' ');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$textCharMaxLength.val('1234567890 ');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.updateOption('textCharMaxLength', 'stringLength', 'trim', true);
- this.bv.resetForm();
- this.$textCharMaxLength.val(' ');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(true);
- this.bv.resetForm();
- this.$textCharMaxLength.val(' ');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(true);
- this.bv.resetForm();
- this.$textCharMaxLength.val(' 0123456789 ');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(true);
- this.bv.resetForm();
- this.$textCharMaxLength.val(' 01234567890 ');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- });
- describe('uri', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="uriForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="uri" data-bv-uri />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#uriForm').bootstrapValidator();
- this.bv = $('#uriForm').data('bootstrapValidator');
- this.$uri = this.bv.getFieldElements('uri');
- });
- afterEach(function() {
- $('#uriForm').bootstrapValidator('destroy').remove();
- });
- var validGlobalURIs = [
- 'http://foo.com/blah_blah',
- 'http://foo.com/blah_blah',
- 'http://foo.com/blah_blah/',
- 'http://foo.com/blah_blah_(wikipedia)',
- 'http://foo.com/blah_blah_(wikipedia)_(again)',
- 'http://www.example.com/wpstyle/?p=364',
- 'https://www.example.com/foo/?bar=baz&inga=42&quux',
- 'http://✪df.ws/123',
- 'http://userid:password@example.com:8080',
- 'http://userid:password@example.com:8080/',
- 'http://userid@example.com',
- 'http://userid@example.com/',
- 'http://userid@example.com:8080',
- 'http://userid@example.com:8080/',
- 'http://userid:password@example.com',
- 'http://userid:password@example.com/',
- 'http://142.42.1.1/',
- 'http://142.42.1.1:8080/',
- 'http://➡.ws/䨹',
- 'http://⌘.ws',
- 'http://⌘.ws/',
- 'http://foo.com/blah_(wikipedia)#cite-1',
- 'http://foo.com/blah_(wikipedia)_blah#cite-1',
- 'http://foo.com/unicode_(✪)_in_parens',
- 'http://foo.com/(something)?after=parens',
- 'http://☺.damowmow.com/',
- 'http://code.google.com/events/#&product=browser',
- 'http://j.mp',
- 'ftp://foo.bar/baz',
- 'http://foo.bar/?q=Test%20URL-encoded%20stuff',
- 'http://مثال.إختبار',
- 'http://例子.测试',
- 'http://उदाहरण.परीक्षा',
- "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
- 'http://1337.net',
- 'http://a.b-c.de',
- 'http://223.255.255.254'
- ];
- var invalidGlobalURIs = [
- 'http://',
- 'http://.',
- 'http://..',
- 'http://../',
- 'http://?',
- 'http://??',
- 'http://??/',
- 'http://#',
- 'http://##',
- 'http://##/',
- 'http://foo.bar?q=Spaces should be encoded',
- '//',
- '//a',
- '///a',
- '///',
- 'http:///a',
- 'foo.com',
- 'rdar://1234',
- 'h://test',
- 'http:// shouldfail.com',
- ':// should fail',
- 'http://foo.bar/foo(bar)baz quux',
- 'ftps://foo.bar/',
- 'http://-error-.invalid/',
- 'http://a.b--c.de/',
- 'http://-a.b.co',
- 'http://a.b-.co',
- 'http://.www.foo.bar/',
- 'http://www.foo.bar./',
- 'http://.www.foo.bar./'
- ];
- var localURIs = [
- 'http://intranetsite',
- 'http://intranetsite/test',
- 'http://intranetsite:80',
- 'http://intranetsite:80/test',
- 'http://user:pass@intranetsite',
- 'http://user:pass@intranetsite/test',
- 'http://user:pass@intranetsite:80',
- 'http://user:pass@intranetsite:80/test',
- 'http://10.1.1.0',
- 'http://10.1.1.255',
- 'http://10.1.1.1',
- 'http://10.1.1.254',
- 'http://127.0.0.1',
- 'http://192.168.0.1',
- 'http://0.0.0.0',
- 'http://224.1.1.1',
- 'http://1.1.1.1.1',
- 'http://123.123.123',
- 'http://3628126748'
- ];
- it('Valid URIs (allowLocal=false)', function() {
- var me = this;
- $.each(validGlobalURIs, function(index, uri) {
- me.bv.resetForm();
- me.$uri.val(uri);
- me.bv.validate();
- expect(me.bv.isValid()).toBeTruthy();
- });
- });
- it('Invalid URIs (allowLocal=false)', function() {
- var me = this;
- $.each(invalidGlobalURIs.concat(localURIs), function(index, uri) {
- me.bv.resetForm();
- me.$uri.val(uri);
- me.bv.validate();
- expect(me.bv.isValid()).toEqual(false);
- });
- });
- it('Valid URIs (allowLocal=true)', function() {
- var me = this;
- me.bv.updateOption('uri', 'uri', 'allowLocal', true);
- $.each(validGlobalURIs.concat(localURIs), function(index, uri) {
- me.bv.resetForm();
- me.$uri.val(uri);
- me.bv.validate();
- expect(me.bv.isValid()).toBeTruthy();
- });
- });
- it('Invalid URIs (allowLocal=true)', function() {
- var me = this;
- me.bv.updateOption('uri', 'uri', 'allowLocal', true);
- $.each(invalidGlobalURIs, function(index, uri) {
- me.bv.resetForm();
- me.$uri.val(uri);
- me.bv.validate();
- expect(me.bv.isValid()).toEqual(false);
- });
- });
- });
- describe('vat', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="vatForm">',
- '<div class="form-group">',
- '<select class="form-control" name="country">',
- '<option value="AT">Austria</option>',
- '<option value="BE">Belgium</option>',
- '<option value="BG">Bulgaria</option>',
- '<option value="HR">Croatia</option>',
- '<option value="CY">Cyprus</option>',
- '<option value="CZ">Czech Republic</option>',
- '<option value="DK">Denmark</option>',
- '<option value="EE">Estonia</option>',
- '<option value="FI">Finland</option>',
- '<option value="FR">France</option>',
- '<option value="DE">Germany</option>',
- '<option value="GR">Greece</option>',
- '<option value="HU">Hungary</option>',
- '<option value="IE">Ireland</option>',
- '<option value="IS">Iceland</option>',
- '<option value="IT">Italy</option>',
- '<option value="LV">Latvia</option>',
- '<option value="LT">Lithuania</option>',
- '<option value="LU">Luxembourg</option>',
- '<option value="MT">Malta</option>',
- '<option value="NL">Netherlands</option>',
- '<option value="NO">Norway</option>',
- '<option value="PL">Poland</option>',
- '<option value="PT">Portugal</option>',
- '<option value="RO">Romania</option>',
- '<option value="RU">Russia</option>',
- '<option value="RS">Serbia</option>',
- '<option value="SK">Slovakia</option>',
- '<option value="SI">Slovenia</option>',
- '<option value="ES">Spain</option>',
- '<option value="SE">Sweden</option>',
- '<option value="CH">Switzerland</option>',
- '<option value="GB">United Kingdom</option>',
- '<option value="VE">Venezuela</option>',
- '<option value="ZA">South Africa</option>',
- '</select>',
- '</div>',
- '<div class="form-group">',
- '<input type="text" name="vat" data-bv-vat />',
- '</div>',
- '</form>',
- ].join('\n')).appendTo('body');
- $('#vatForm').bootstrapValidator();
- /**
- * @type {BootstrapValidator}
- */
- this.bv = $('#vatForm').data('bootstrapValidator');
- this.$country = this.bv.getFieldElements('country');
- this.$vat = this.bv.getFieldElements('vat');
- });
- afterEach(function() {
- $('#vatForm').bootstrapValidator('destroy').remove();
- });
- it('dynamic country', function() {
- this.$vat.attr('data-bv-vat-country', 'country');
- this.bv.destroy();
- this.bv = $('#vatForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('AT');
- this.$vat.val('ATU13585627');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$country.val('BG');
- this.$vat.val('BE0428759497');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$country.val('BE');
- this.$vat.val('BE431150351');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Austrian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'AT');
- // Valid samples
- var validSamples = ['ATU13585627', 'U13585627'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['ATU13585626', 'U13585626'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Belgian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'BE');
- // Valid samples
- var validSamples = ['BE0428759497', '0428759497'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['BE431150351', '431150351'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Bulgarian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'BG');
- // Valid samples
- var validSamples = ['BG175074752', 'BG7523169263', 'BG8032056031', 'BG7542011030', 'BG7111042925', '175074752', '7523169263', '8032056031'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['BG175074753', 'BG7552A10004', 'BG7111042922', '175074753', '7552A10004'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Cypriot VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'CY');
- // Valid samples
- var validSamples = ['CY10259033P', '10259033P'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['CY10259033Z', '10259033Z'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Czech Republic VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'CZ');
- // Valid samples
- var validSamples = ['CZ25123891', 'CZ7103192745', 'CZ991231123', 'CZ640903926', '25123891', '7103192745'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['CZ25123890', 'CZ1103492745', 'CZ590312123', '25123890', '1103492745'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('German VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'DE');
- // Valid samples
- var validSamples = ['DE136695976', '136695976'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['DE136695978', '136695978'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Danish VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'DK');
- // Valid samples
- var validSamples = ['DK13585628', '13585628'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['DK13585627', '13585627'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Estonian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'EE');
- // Valid samples
- var validSamples = ['EE100931558', 'EE100594102', '100931558', '100594102'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['EE100594103', '100594103'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Spanish VAT number (NIF)', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'ES');
- // Valid samples
- var validSamples = ['ES54362315K', 'ESX2482300W', 'ESX5253868R', 'ESM1234567L', 'ESJ99216582', 'ESB58378431', 'ESB64717838', '54362315K', 'X2482300W', 'X5253868R', 'M1234567L', 'J99216582'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['ES54362315Z', 'ESX2482300A', 'ESJ99216583', '54362315Z', 'X2482300A'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Finnish VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'FI');
- // Valid samples
- var validSamples = ['FI20774740', '20774740'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['FI20774741', '20774741'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('French VAT number (TVA)', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'FR');
- // Valid samples
- var validSamples = ['FR40303265045', 'FR23334175221', 'FRK7399859412', 'FR4Z123456782', '40303265045', '23334175221', 'K7399859412'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['FR84323140391', '84323140391'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('United Kingdom VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'GB');
- // Valid samples
- var validSamples = ['GB980780684', '980780684'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['GB802311781', '802311781'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Greek VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'GR');
- // Valid samples
- var validSamples = ['GR023456780', 'EL094259216', '023456780', '094259216'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['GR123456781', '123456781'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Hungarian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'HU');
- // Valid samples
- var validSamples = ['HU12892312', '12892312'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['HU12892313', '12892313'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Croatian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'HR');
- // Valid samples
- var validSamples = ['HR33392005961', '33392005961'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['HR33392005962', '33392005962'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Irish VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'IE');
- // Valid samples
- var validSamples = ['IE6433435F', 'IE6433435OA', 'IE8D79739I', '6433435F', '6433435OA', '8D79739I'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['IE8D79738J', '8D79738J'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Iceland VAT (VSK) number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'IS');
- // Valid samples
- var validSamples = ['IS11111', 'IS111111', '11111', '111111'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['IS1234567', 'IS123456ABC', '1234567', '123456ABC'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Italian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'IT');
- // Valid samples
- var validSamples = ['IT00743110157', '00743110157'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['IT00743110158', '00743110158'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Lithuanian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'LT');
- // Valid samples
- var validSamples = ['LT119511515', 'LT100001919017', 'LT100004801610', '119511515', '100001919017', '100004801610'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['LT100001919018', '100001919018'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Luxembourg VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'LU');
- // Valid samples
- var validSamples = ['LU15027442', '15027442'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['LU15027443', '15027443'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Latvian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'LV');
- // Valid samples
- var validSamples = ['LV40003521600', 'LV16117519997', '40003521600', '16117519997'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['LV40003521601', 'LV16137519997', '40003521601', '16137519997'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Maltese VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'MT');
- // Valid samples
- var validSamples = ['MT11679112', '11679112'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['MT11679113', '11679113'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Dutch VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'NL');
- // Valid samples
- var validSamples = ['NL004495445B01', '004495445B01'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['NL123456789B90', '123456789B90'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Polish VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'PL');
- // Valid samples
- var validSamples = ['PL8567346215', '8567346215'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['PL8567346216', '8567346216'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Portuguese VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'PT');
- // Valid samples
- var validSamples = ['PT501964843', '501964843'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['PT501964842', '501964842'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Romanian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'RO');
- // Valid samples
- var validSamples = ['RO18547290', '18547290'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['RO18547291', '18547291'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Russian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'RU');
- // Valid samples
- var validSamples = ['RU7805145876', 'RU781300557475', '7805145876', '781300557475'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['RU7805145877', 'RU781300557474', '7805145877', '781300557474'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Swedish VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'SE');
- // Valid samples
- var validSamples = ['SE123456789701', '123456789701'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['SE123456789101', '123456789101'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Slovenian VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'SI');
- // Valid samples
- var validSamples = ['SI50223054', '50223054'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['SI50223055', '50223055'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Slovak VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'SK');
- // Valid samples
- var validSamples = ['SK2022749619', '2022749619'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['SK2022749618', '2022749618'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('South African VAT number', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'ZA');
- // Valid samples
- var validSamples = ['ZA4012345678', '4012345678'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['ZA40123456789', 'ZA0123456789', '40123456789', '0123456789'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Venezuelan VAT number (RIF)', function() {
- this.bv.updateOption('vat', 'vat', 'country', 'VE');
- // Valid samples
- var validSamples = ['VEJ309272292', 'VEV242818101', 'VEJ000126518', 'VEJ000458324', 'J309272292', 'V242818101', 'J000126518', 'J000458324'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$vat.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['VEJ309272293', 'VEV242818100', 'J000126519', 'J000458323'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$vat.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- });
- function getCountryCode(value, validator, $field) {
- $('#msg').html('getCountryCode() called');
- return validator.getFieldElements('country').val();
- };
- TestSuite = $.extend({}, TestSuite, {
- ZipCode: {
- getCountryCode: function(value, validator, $field) {
- $('#msg').html('TestSuite.ZipCode.getCountryCode() called');
- return validator.getFieldElements('country').val();
- }
- }
- });
- describe('zipCode', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="zipCodeForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<label class="col-md-3 control-label">Country:</label>',
- '<div class="col-md-2">',
- '<select class="form-control" name="country">',
- '<option value="">Select a country</option>',
- '<option value="CA">Canada</option>',
- '<option value="CZ">Czech Republic</option>',
- '<option value="DK">Denmark</option>',
- '<option value="FR">France</option>',
- '<option value="GB">United Kingdom</option>',
- '<option value="IE">Ireland</option>',
- '<option value="IT">Italy</option>',
- '<option value="NL">Netherlands</option>',
- '<option value="PT">Portugal</option>',
- '<option value="SE">Sweden</option>',
- '<option value="SK">Slovakia</option>',
- '<option value="US">United States</option>',
- '</select>',
- '</div>',
- '</div>',
- '<div class="form-group">',
- '<label class="col-md-3 control-label">Zipcode</label>',
- '<div class="col-md-2">',
- '<input type="text" class="form-control" name="zc" data-bv-zipcode data-bv-zipcode-country="US" />',
- '</div>',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#zipCodeForm').bootstrapValidator();
- /**
- * @type {BootstrapValidator}
- */
- this.bv = $('#zipCodeForm').data('bootstrapValidator');
- this.$country = this.bv.getFieldElements('country');
- this.$zipCode = this.bv.getFieldElements('zc');
- });
- afterEach(function() {
- $('#zipCodeForm').bootstrapValidator('destroy').remove();
- });
- it('country code updateOption()', function() {
- // Check IT postal code
- this.bv.updateOption('zc', 'zipCode', 'country', 'IT');
- this.$zipCode.val('1234');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$zipCode.val('IT-12345');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- // Check United Kingdom postal code
- this.bv.updateOption('zc', 'zipCode', 'country', 'GB');
- var validUkSamples = ['EC1A 1BB', 'W1A 1HQ', 'M1 1AA', 'B33 8TH', 'CR2 6XH', 'DN55 1PT', 'AI-2640', 'ASCN 1ZZ', 'GIR 0AA'];
- for (var i in validUkSamples) {
- this.bv.resetForm();
- this.$zipCode.val(validUkSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- });
- it('country code other field declarative', function() {
- this.$zipCode.attr('data-bv-zipcode-country', 'country');
- // Need to destroy the plugin instance ...
- $('#zipCodeForm').bootstrapValidator('destroy');
- // ... and re-create it
- this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('IT');
- this.bv.resetForm();
- this.$zipCode.val('1234');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$zipCode.val('I-12345');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('country code callback declarative function', function() {
- this.$zipCode.attr('data-bv-zipcode-country', 'getCountryCode');
- $('#zipCodeForm').bootstrapValidator('destroy');
- this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('NL');
- this.$zipCode.val('0123');
- this.bv.validate();
- expect($('#msg').html()).toEqual('getCountryCode() called');
- expect(this.bv.isValid()).toEqual(false);
- });
- it('country code callback declarative function()', function() {
- this.$zipCode.attr('data-bv-zipcode-country', 'getCountryCode()');
- $('#zipCodeForm').bootstrapValidator('destroy');
- this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('NL');
- this.$zipCode.val('1234 ab');
- this.bv.validate();
- expect($('#msg').html()).toEqual('getCountryCode() called');
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('country code callback declarative A.B.C', function() {
- this.$zipCode.attr('data-bv-zipcode-country', 'TestSuite.ZipCode.getCountryCode');
- $('#zipCodeForm').bootstrapValidator('destroy');
- this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('DK');
- this.$zipCode.val('DK 123');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.ZipCode.getCountryCode() called');
- expect(this.bv.isValid()).toEqual(false);
- });
- it('country code callback declarative A.B.C()', function() {
- this.$zipCode.attr('data-bv-zipcode-country', 'TestSuite.ZipCode.getCountryCode()');
- $('#zipCodeForm').bootstrapValidator('destroy');
- this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
- this.$country.val('DK');
- this.$zipCode.val('DK-1234');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.ZipCode.getCountryCode() called');
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('country code callback programmatically', function() {
- this.$zipCode.removeAttr('data-bv-zipcode-country');
- $('#zipCodeForm').bootstrapValidator('destroy');
- this.bv = $('#zipCodeForm')
- .bootstrapValidator({
- fields: {
- zc: {
- validators: {
- zipCode: {
- country: function(value, validator, $field) {
- return getCountryCode(value, validator, $field);
- }
- }
- }
- }
- }
- })
- .data('bootstrapValidator');
- this.$country.val('SE');
- this.bv.resetForm();
- this.$zipCode.val('S-567 8');
- this.bv.validate();
- expect($('#msg').html()).toEqual('getCountryCode() called');
- expect(this.bv.isValid()).toEqual(false);
- this.bv.resetForm();
- this.$zipCode.val('S-12345');
- this.bv.validate();
- expect($('#msg').html()).toEqual('getCountryCode() called');
- expect(this.bv.isValid()).toBeTruthy();
- });
- it('not supported country code', function() {
- this.$zipCode.attr('data-bv-zipcode-country', 'NOT_SUPPORTED');
- $('#zipCodeForm').bootstrapValidator('destroy');
- this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
- this.bv.resetForm();
- this.$zipCode.val('1234');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- expect(this.bv.getMessages(this.$zipCode, 'zipCode')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, 'NOT_SUPPORTED'));
- });
- it('US zipcode', function() {
- this.$zipCode.val('12345');
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- this.bv.resetForm();
- this.$zipCode.val('123');
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- });
- it('Czech Republic postal code', function() {
- this.bv.updateOption('zc', 'zipCode', 'country', 'CZ');
- // Valid samples
- var validSamples = ['12345', '123 45'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$zipCode.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['12 345', '123456', '1 2345', '1234 5', '12 3 45'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$zipCode.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('Slovakia postal code', function() {
- this.bv.updateOption('zc', 'zipCode', 'country', 'SK');
- // Valid samples
- var validSamples = ['12345', '123 45'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$zipCode.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['12 345', '123456', '1 2345', '1234 5', '12 3 45'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$zipCode.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- it('France postal code', function() {
- this.bv.updateOption('zc', 'zipCode', 'country', 'FR');
- // Valid samples
- var validSamples = ['12340', '01230', '75116'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$zipCode.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['123 45', '12 345', '123456', '1 2345', '1234 5', '12 3 45', '1234A'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$zipCode.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
-
- it('Eircode (Ireland postal code)', function() {
- this.bv.updateOption('zc', 'zipCode', 'country', 'IE');
- // Valid samples
- var validSamples = ['A65 F4E2', 'D6W FNT4', 'T37 F8HK'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$zipCode.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['a65 f4e2', 'D6W FNTO', 'T37F8HK'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$zipCode.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
-
- it('Portugal postal code', function() {
- this.bv.updateOption('zc', 'zipCode', 'country', 'PT');
- // Valid samples
- var validSamples = ['2435-459', '1000-000', '1234-456'];
- for (var i in validSamples) {
- this.bv.resetForm();
- this.$zipCode.val(validSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toBeTruthy();
- }
- // Invalid samples
- var invalidSamples = ['0123-456', '1234456', '1234-ABC', '1234 456'];
- for (i in invalidSamples) {
- this.bv.resetForm();
- this.$zipCode.val(invalidSamples[i]);
- this.bv.validate();
- expect(this.bv.isValid()).toEqual(false);
- }
- });
- });
|