spec.js 282 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892
  1. describe('api', function() {
  2. // Override the options
  3. $.extend($.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  4. feedbackIcons: {
  5. valid: 'glyphicon glyphicon-ok',
  6. invalid: 'glyphicon glyphicon-remove',
  7. validating: 'glyphicon glyphicon-refresh'
  8. }
  9. });
  10. beforeEach(function() {
  11. $([
  12. '<form class="form-horizontal" id="apiForm">',
  13. '<div class="form-group">',
  14. '<input type="text" name="username" data-bv-notempty data-bv-stringlength data-bv-stringlength-min="8" />',
  15. '</div>',
  16. '<div class="form-group">',
  17. '<input type="text" name="email" data-bv-notempty data-bv-emailaddress />',
  18. '</div>',
  19. '</form>'
  20. ].join('\n')).appendTo('body');
  21. $('#apiForm').bootstrapValidator();
  22. this.bv = $('#apiForm').data('bootstrapValidator');
  23. this.$email = this.bv.getFieldElements('email');
  24. });
  25. afterEach(function() {
  26. $('#apiForm').bootstrapValidator('destroy').remove();
  27. });
  28. it('revalidateField()', function() {
  29. this.$email.val('email@domain.com');
  30. this.bv.validate();
  31. expect(this.bv.isValidField('email')).toBeTruthy();
  32. this.$email.val('invalid#email.address');
  33. this.bv.revalidateField('email');
  34. expect(this.bv.isValidField(this.$email)).toEqual(false);
  35. });
  36. it('destroy()', function() {
  37. this.bv.destroy();
  38. expect($('#apiForm').data('bootstrapValidator')).toBeUndefined();
  39. expect($('#apiForm').find('i[data-bv-icon-for]').length).toEqual(0);
  40. expect($('#apiForm').find('.help-block[data-bv-for]').length).toEqual(0);
  41. expect($('#apiForm').find('.has-feedback').length).toEqual(0);
  42. expect($('#apiForm').find('.has-success').length).toEqual(0);
  43. expect($('#apiForm').find('.has-error').length).toEqual(0);
  44. expect($('#apiForm').find('[data-bv-field]').length).toEqual(0);
  45. });
  46. it('getOptions()', function() {
  47. // Form options
  48. expect(this.bv.getOptions().feedbackIcons.valid).toEqual('glyphicon glyphicon-ok');
  49. // Field options
  50. expect(this.bv.getOptions('username', 'stringlength')).toBeNull();
  51. expect(this.bv.getOptions('username', 'stringlength', 'min')).toBeNull();
  52. expect(this.bv.getOptions('username', 'stringLength')).toBeDefined();
  53. expect(this.bv.getOptions('username', 'stringLength', 'min')).toEqual('8');
  54. expect(this.bv.getOptions('username', 'stringlength', 'max')).toBeNull();
  55. });
  56. });
  57. describe('container form option', function() {
  58. beforeEach(function() {
  59. $([
  60. '<form id="containerForm" class="form-horizontal">',
  61. '<div class="form-group">',
  62. '<label class="col-lg-3 control-label">Full name</label>',
  63. '<div class="col-lg-4">',
  64. '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" />',
  65. '</div>',
  66. '<div class="col-lg-4">',
  67. '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
  68. '</div>',
  69. '</div>',
  70. '<div id="errors"></div>',
  71. '</form>'
  72. ].join('')).appendTo('body');
  73. });
  74. afterEach(function() {
  75. $('#containerForm').bootstrapValidator('destroy').remove();
  76. });
  77. it('form container declarative', function() {
  78. $('#containerForm')
  79. .attr('data-bv-container', '#errors')
  80. .bootstrapValidator();
  81. this.bv = $('#containerForm').data('bootstrapValidator');
  82. this.$firstName = this.bv.getFieldElements('firstName');
  83. this.$lastName = this.bv.getFieldElements('lastName');
  84. expect($('#errors').find('.help-block').length).toBeGreaterThan(0);
  85. this.$firstName.val('First');
  86. this.$lastName.val('');
  87. this.bv.validate();
  88. expect($('#errors').find('.help-block:visible[data-bv-for="firstName"]').length).toEqual(0);
  89. expect($('#errors').find('.help-block:visible[data-bv-for="lastName"]').length).toBeGreaterThan(0);
  90. });
  91. it('form container programmatically', function() {
  92. $('#containerForm').bootstrapValidator({
  93. container: '#errors'
  94. });
  95. this.bv = $('#containerForm').data('bootstrapValidator');
  96. this.$firstName = this.bv.getFieldElements('firstName');
  97. this.$lastName = this.bv.getFieldElements('lastName');
  98. expect($('#errors').find('.help-block').length).toBeGreaterThan(0);
  99. this.$firstName.val('');
  100. this.$lastName.val('Last');
  101. this.bv.validate();
  102. expect($('#errors').find('.help-block:visible[data-bv-for="firstName"]').length).toBeGreaterThan(0);
  103. expect($('#errors').find('.help-block:visible[data-bv-for="lastName"]').length).toEqual(0);
  104. this.bv.resetForm();
  105. this.$firstName.val('First');
  106. this.$lastName.val('Last');
  107. this.bv.validate();
  108. expect($('#errors').find('.help-block:visible').length).toEqual(0);
  109. });
  110. });
  111. describe('container field option', function() {
  112. beforeEach(function() {
  113. $([
  114. '<form id="containerForm" class="form-horizontal">',
  115. '<div class="form-group">',
  116. '<label class="col-lg-3 control-label">Full name</label>',
  117. '<div class="col-lg-4">',
  118. '<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" />',
  119. '<span class="help-block" id="firstNameMessage" />',
  120. '</div>',
  121. '<div class="col-lg-4">',
  122. '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
  123. '<span class="help-block lastNameMessage" />',
  124. '</div>',
  125. '</div>',
  126. '</form>'
  127. ].join('')).appendTo('body');
  128. $('#containerForm').bootstrapValidator({
  129. feedbackIcons: {
  130. valid: 'glyphicon glyphicon-ok',
  131. invalid: 'glyphicon glyphicon-remove',
  132. validating: 'glyphicon glyphicon-refresh'
  133. },
  134. fields: {
  135. lastName: {
  136. container: '.lastNameMessage'
  137. }
  138. }
  139. });
  140. this.bv = $('#containerForm').data('bootstrapValidator');
  141. this.$firstName = this.bv.getFieldElements('firstName');
  142. this.$lastName = this.bv.getFieldElements('lastName');
  143. });
  144. afterEach(function() {
  145. $('#containerForm').bootstrapValidator('destroy').remove();
  146. });
  147. it('field container declarative', function() {
  148. expect($.trim($('#firstNameMessage').text())).toEqual('The first name is required');
  149. expect($.trim($('.lastNameMessage').text())).toEqual('The last name is required');
  150. });
  151. it('field container programmatically', function() {
  152. this.$firstName.val('First');
  153. this.$lastName.val('');
  154. this.bv.validate();
  155. expect($('#firstNameMessage').find('.help-block:visible').length).toEqual(0);
  156. expect($('.lastNameMessage').find('.help-block:visible').length).toBeGreaterThan(0);
  157. this.bv.resetForm();
  158. this.$firstName.val('');
  159. this.$lastName.val('Last');
  160. this.bv.validate();
  161. expect($('#firstNameMessage').find('.help-block:visible').length).toBeGreaterThan(0);
  162. expect($('.lastNameMessage').find('.help-block:visible').length).toEqual(0);
  163. });
  164. });
  165. describe('container tooltip/popover', function() {
  166. beforeEach(function() {
  167. $([
  168. '<form id="containerForm" class="form-horizontal">',
  169. '<div class="form-group">',
  170. '<label class="col-lg-3 control-label">Full name</label>',
  171. '<div class="col-lg-4">',
  172. '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" />',
  173. '</div>',
  174. '<div class="col-lg-4">',
  175. '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
  176. '</div>',
  177. '</div>',
  178. '<div id="errors"></div>',
  179. '</form>'
  180. ].join('')).appendTo('body');
  181. });
  182. afterEach(function() {
  183. $('#containerForm').bootstrapValidator('destroy').remove();
  184. });
  185. it('container declarative', function() {
  186. $('#containerForm')
  187. .attr('data-bv-container', 'tooltip')
  188. .find('[name="lastName"]')
  189. .attr('data-bv-container', 'popover')
  190. .end()
  191. .bootstrapValidator();
  192. this.bv = $('#containerForm').data('bootstrapValidator');
  193. this.$firstName = this.bv.getFieldElements('firstName');
  194. this.$lastName = this.bv.getFieldElements('lastName');
  195. this.bv.validate();
  196. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  197. expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
  198. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
  199. expect(this.$lastName.parent().find('i').data('bs.popover').type).toEqual('popover');
  200. this.bv.resetForm();
  201. this.$firstName.val('First');
  202. this.$lastName.val('Last');
  203. this.bv.validate();
  204. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
  205. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
  206. });
  207. it('container programmatically', function() {
  208. $('#containerForm').bootstrapValidator({
  209. container: 'tooltip',
  210. fields: {
  211. lastName: {
  212. container: 'popover'
  213. }
  214. }
  215. });
  216. this.bv = $('#containerForm').data('bootstrapValidator');
  217. this.$firstName = this.bv.getFieldElements('firstName');
  218. this.$lastName = this.bv.getFieldElements('lastName');
  219. this.bv.validate();
  220. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  221. expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
  222. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
  223. expect(this.$lastName.parent().find('i').data('bs.popover').type).toEqual('popover');
  224. this.bv.resetForm();
  225. this.$firstName.val('First');
  226. this.$lastName.val('Last');
  227. this.bv.validate();
  228. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
  229. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
  230. });
  231. // #991: Validate once when setting trigger: blur, container: tooltip
  232. it('trigger: blur, container: tooltip', function() {
  233. $('#containerForm').bootstrapValidator({
  234. container: 'tooltip',
  235. trigger: 'blur',
  236. fields: {
  237. firstName: {
  238. validators: {
  239. stringLength: {
  240. min: 5,
  241. message: 'The first name must be more than 5 characters'
  242. },
  243. notEmpty: {
  244. message: 'The first name is required'
  245. },
  246. regexp: {
  247. regexp: /^[a-z]+$/i,
  248. message: 'The first name must consist of a-z, A-Z characters only'
  249. }
  250. }
  251. },
  252. lastName: {
  253. validators: {
  254. stringLength: {
  255. min: 5,
  256. message: 'The last name must be more than 5 characters'
  257. },
  258. notEmpty: {
  259. message: 'The last name is required'
  260. },
  261. regexp: {
  262. regexp: /^[a-z]+$/i,
  263. message: 'The last name must consist of a-z, A-Z characters only'
  264. }
  265. }
  266. }
  267. }
  268. });
  269. this.bv = $('#containerForm').data('bootstrapValidator');
  270. this.$firstName = this.bv.getFieldElements('firstName');
  271. this.$lastName = this.bv.getFieldElements('lastName');
  272. this.$firstName.val('').trigger('blur');
  273. this.bv.validate();
  274. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  275. expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
  276. expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name is required');
  277. this.bv.resetForm();
  278. this.$firstName.val('@not#valid');
  279. this.$lastName.val('').focus();
  280. this.bv.validate();
  281. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  282. expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
  283. expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must consist of a-z, A-Z characters only');
  284. this.bv.resetForm();
  285. this.$firstName.val('Phuo');
  286. this.$lastName.val('').focus();
  287. this.bv.validate();
  288. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  289. expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
  290. expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must be more than 5 characters');
  291. this.bv.resetForm();
  292. this.$firstName.val('Phuoc');
  293. this.$lastName.val('').focus();
  294. this.bv.validate();
  295. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
  296. });
  297. });
  298. describe('dynamic fields', function() {
  299. beforeEach(function() {
  300. $([
  301. '<form class="form-horizontal" id="dynamicForm">',
  302. '<div class="form-group">',
  303. '<input type="text" name="fullName" class="form-control" />',
  304. '</div>',
  305. '</form>'
  306. ].join('\n')).appendTo('body');
  307. $('#dynamicForm').bootstrapValidator({
  308. fields: {
  309. fullName: {
  310. validators: {
  311. notEmpty: {
  312. message: 'The full name is required and cannot be empty'
  313. },
  314. stringLength: {
  315. min: 8,
  316. max: 40,
  317. message: 'The full name must be more than %s and less than %s characters long'
  318. },
  319. regexp: {
  320. enabled: false,
  321. regexp: /^[a-zA-Z\s]+$/,
  322. message: 'The full name can only consist of alphabetical, number, and space'
  323. }
  324. }
  325. },
  326. // #725: Note that the email field isn't available in the form yet
  327. email: {
  328. validators: {
  329. emailAddress: {
  330. message: 'The email address is not valid'
  331. }
  332. }
  333. }
  334. }
  335. });
  336. this.bv = $('#dynamicForm').data('bootstrapValidator');
  337. this.$fullName = this.bv.getFieldElements('fullName');
  338. });
  339. afterEach(function() {
  340. $('#dynamicForm').bootstrapValidator('destroy').remove();
  341. });
  342. // https://github.com/nghuuphuoc/bootstrapvalidator/pull/725
  343. it('adding field [does not exist but is already set in "fields" option]', function() {
  344. var $div = $('<div/>').addClass('form-group').appendTo($('#dynamicForm'));
  345. $email = $('<input/>')
  346. .attr('type', 'text')
  347. .addClass('form-control')
  348. .attr('name', 'email')
  349. .appendTo($div);
  350. this.bv.addField('email');
  351. this.$fullName.val('Phuoc Nguyen');
  352. $email.val('not valid@email');
  353. this.bv.validate();
  354. expect(this.bv.isValidField('email')).toBeFalsy();
  355. expect(this.bv.isValid()).toBeFalsy();
  356. this.bv.resetForm();
  357. $email.val('valid@email.com');
  358. this.bv.validate();
  359. expect(this.bv.isValidField('email')).toBeTruthy();
  360. expect(this.bv.isValid()).toBeTruthy();
  361. });
  362. });
  363. describe('enable validators', function() {
  364. beforeEach(function() {
  365. $([
  366. '<form class="form-horizontal" id="enableForm">',
  367. '<div class="form-group">',
  368. '<input type="text" name="fullName" class="form-control" />',
  369. '</div>',
  370. '</form>'
  371. ].join('\n')).appendTo('body');
  372. $('#enableForm').bootstrapValidator({
  373. fields: {
  374. fullName: {
  375. validators: {
  376. notEmpty: {
  377. message: 'The full name is required and cannot be empty'
  378. },
  379. stringLength: {
  380. min: 8,
  381. max: 40,
  382. message: 'The full name must be more than %s and less than %s characters long'
  383. },
  384. regexp: {
  385. enabled: false,
  386. regexp: /^[a-zA-Z\s]+$/,
  387. message: 'The full name can only consist of alphabetical, number, and space'
  388. }
  389. }
  390. }
  391. }
  392. });
  393. this.bv = $('#enableForm').data('bootstrapValidator');
  394. this.$fullName = this.bv.getFieldElements('fullName');
  395. });
  396. afterEach(function() {
  397. $('#enableForm').bootstrapValidator('destroy').remove();
  398. });
  399. it('enable all validators', function() {
  400. this.$fullName.val('@ $full N@m3');
  401. this.bv.validate();
  402. expect(this.bv.isValid()).toBeTruthy();
  403. this.bv.resetForm();
  404. this.$fullName.val('Contain#$@');
  405. this.bv.enableFieldValidators('fullName', true);
  406. this.bv.validate();
  407. expect(this.bv.isValidField('fullName')).toEqual(false);
  408. expect(this.bv.isValid()).toEqual(false);
  409. });
  410. it('disable all validators', function() {
  411. this.bv.resetForm();
  412. this.bv.enableFieldValidators('fullName', false);
  413. this.bv.validate();
  414. expect(this.bv.isValid()).toBeTruthy();
  415. });
  416. it('enabled option particular validator', function() {
  417. this.$fullName.val('Contain@#$');
  418. this.bv.validate();
  419. expect(this.bv.isValid()).toBeTruthy();
  420. var messages = this.bv.getMessages('fullName');
  421. expect(messages.length).toEqual(0);
  422. });
  423. it('enable particular validators', function() {
  424. // Enable stringLength validator
  425. this.bv.resetForm();
  426. this.bv.enableFieldValidators('fullName', true, 'stringLength');
  427. this.bv.enableFieldValidators('fullName', true, 'regexp');
  428. this.$fullName.val('Full@');
  429. this.bv.validate();
  430. expect(this.bv.isValid()).toEqual(false);
  431. var messages = this.bv.getMessages('fullName');
  432. expect($.inArray('The full name must be more than 8 and less than 40 characters long', messages)).toBeGreaterThan(-1);
  433. expect($.inArray('The full name can only consist of alphabetical, number, and space', messages)).toBeGreaterThan(-1);
  434. });
  435. it('disable particular validators', function() {
  436. // Disable stringLength validator
  437. this.bv.enableFieldValidators('fullName', false, 'stringLength');
  438. this.$fullName.val('Full');
  439. this.bv.validate();
  440. expect(this.bv.isValid()).toBeTruthy();
  441. var messages = this.bv.getMessages('fullName');
  442. expect($.inArray('The full name must be more than 8 and less than 40 characters long', messages)).toEqual(-1);
  443. // Disable regexp validator
  444. this.bv.enableFieldValidators('fullName', false, 'regexp');
  445. this.$fullName.val('Special@#$');
  446. this.bv.validate();
  447. expect(this.bv.isValid()).toBeTruthy();
  448. var messages = this.bv.getMessages('fullName');
  449. expect($.inArray('The full name can only consist of alphabetical, number, and space', messages)).toEqual(-1);
  450. });
  451. });
  452. TestSuite = $.extend({}, TestSuite, {
  453. Event: {
  454. onEmailValid: function(e, data) {
  455. $('#msg').html('TestSuite.Event.onEmailValid() called, ' + data.field + ' is valid');
  456. },
  457. onEmailInvalid: function(e, data) {
  458. $('#msg').html('TestSuite.Event.onEmailInvalid() called, ' + data.field + ' is invalid');
  459. },
  460. onEmailStatus: function(e, data) {
  461. $('#status').html('TestSuite.Event.onEmailStatus() called; status = ' + data.status);
  462. },
  463. onFormValid: function(e) {
  464. $('#msg').html('TestSuite.Event.onFormValid() called, form ' + $(e.target).attr('id') + ' is valid');
  465. },
  466. onFormInvalid: function(e) {
  467. $('#msg').html('TestSuite.Event.onFormInvalid() called, form ' + $(e.target).attr('id') + ' is invalid');
  468. }
  469. }
  470. });
  471. // ---
  472. // Form events
  473. // ---
  474. function onFormValid(e) {
  475. $('#msg').html('form ' + $(e.target).attr('id') + ' is valid');
  476. };
  477. function onFormInvalid(e) {
  478. $('#msg').html('form ' + $(e.target).attr('id') + ' is invalid');
  479. };
  480. describe('event form attribute callback global', function() {
  481. beforeEach(function() {
  482. $([
  483. '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="onFormValid" data-bv-onerror="onFormInvalid" >',
  484. '<div id="msg"></div>',
  485. '<div class="form-group">',
  486. '<input type="text" name="email" required data-bv-emailaddress />',
  487. '</div>',
  488. '</form>'
  489. ].join('\n')).appendTo('body');
  490. $('#eventForm').bootstrapValidator();
  491. this.bv = $('#eventForm').data('bootstrapValidator');
  492. this.$email = this.bv.getFieldElements('email');
  493. });
  494. afterEach(function() {
  495. $('#eventForm').bootstrapValidator('destroy').remove();
  496. });
  497. it('call data-bv-onsuccess', function() {
  498. this.$email.val('email@domain.com');
  499. this.bv.validate();
  500. expect($('#msg').html()).toEqual('form eventForm is valid');
  501. });
  502. it('call data-bv-onerror', function() {
  503. this.$email.val('a@b@c@example.com');
  504. this.bv.validate();
  505. expect($('#msg').html()).toEqual('form eventForm is invalid');
  506. });
  507. });
  508. describe('event form attribute callback namespace', function() {
  509. beforeEach(function() {
  510. $([
  511. '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="TestSuite.Event.onFormValid" data-bv-onerror="TestSuite.Event.onFormInvalid" >',
  512. '<div id="msg"></div>',
  513. '<div class="form-group">',
  514. '<input type="text" name="email" required data-bv-emailaddress />',
  515. '</div>',
  516. '</form>'
  517. ].join('\n')).appendTo('body');
  518. $('#eventForm').bootstrapValidator();
  519. this.bv = $('#eventForm').data('bootstrapValidator');
  520. this.$email = this.bv.getFieldElements('email');
  521. });
  522. afterEach(function() {
  523. $('#eventForm').bootstrapValidator('destroy').remove();
  524. });
  525. it('call data-bv-onsuccess', function() {
  526. this.$email.val('email@domain.com');
  527. this.bv.validate();
  528. expect($('#msg').html()).toEqual('TestSuite.Event.onFormValid() called, form eventForm is valid');
  529. });
  530. it('call data-bv-onerror', function() {
  531. this.$email.val('just"not"right@example.com');
  532. this.bv.validate();
  533. expect($('#msg').html()).toEqual('TestSuite.Event.onFormInvalid() called, form eventForm is invalid');
  534. });
  535. });
  536. describe('event form trigger', function() {
  537. beforeEach(function() {
  538. $([
  539. '<form class="form-horizontal" id="eventForm">',
  540. '<div id="msg"></div>',
  541. '<div class="form-group">',
  542. '<input type="text" name="email" data-bv-emailaddress />',
  543. '</div>',
  544. '</form>'
  545. ].join('\n')).appendTo('body');
  546. $('#eventForm')
  547. .bootstrapValidator()
  548. .on('success.form.bv', function(e) {
  549. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
  550. })
  551. .on('error.form.bv', function(e) {
  552. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
  553. });
  554. this.bv = $('#eventForm').data('bootstrapValidator');
  555. this.$email = this.bv.getFieldElements('email');
  556. });
  557. afterEach(function() {
  558. $('#eventForm').bootstrapValidator('destroy').remove();
  559. });
  560. it('trigger success.form.bv', function() {
  561. this.$email.val('email@domain.com');
  562. this.bv.validate();
  563. expect($('#msg').html()).toEqual('form eventForm triggered success.form.bv event');
  564. });
  565. it('trigger error.form.bv', function() {
  566. this.$email.val('this is"not\\allowed@example.com');
  567. this.bv.validate();
  568. expect($('#msg').html()).toEqual('form eventForm triggered error.form.bv event');
  569. });
  570. });
  571. describe('event form programmatically', function() {
  572. beforeEach(function() {
  573. $([
  574. '<form class="form-horizontal" id="eventForm">',
  575. '<div id="msg"></div>',
  576. '<div class="form-group">',
  577. '<input type="text" name="email" data-bv-emailaddress />',
  578. '</div>',
  579. '</form>'
  580. ].join('\n')).appendTo('body');
  581. $('#eventForm').bootstrapValidator({
  582. onSuccess: function(e) {
  583. $('#msg').html('onSuccess() called');
  584. },
  585. onError: function(e) {
  586. $('#msg').html('onError() called');
  587. }
  588. });
  589. this.bv = $('#eventForm').data('bootstrapValidator');
  590. this.$email = this.bv.getFieldElements('email');
  591. });
  592. afterEach(function() {
  593. $('#eventForm').bootstrapValidator('destroy').remove();
  594. });
  595. it('call onSuccess()', function() {
  596. this.$email.val('email@domain.com');
  597. this.bv.validate();
  598. expect($('#msg').html()).toEqual('onSuccess() called');
  599. });
  600. it('call onError()', function() {
  601. this.$email.val('Abc.example.com');
  602. this.bv.validate();
  603. expect($('#msg').html()).toEqual('onError() called');
  604. });
  605. });
  606. // ---
  607. // Field events
  608. // ---
  609. function onEmailValid(e, data) {
  610. $('#msg').html(data.field + ' is valid');
  611. };
  612. function onEmailInvalid(e, data) {
  613. $('#msg').html(data.field + ' is invalid');
  614. };
  615. function onEmailStatus(e, data) {
  616. $('#status').html(data.status);
  617. };
  618. describe('event field attribute callback global', function() {
  619. beforeEach(function() {
  620. $([
  621. '<form class="form-horizontal" id="eventForm">',
  622. '<div id="msg"></div>',
  623. '<div id="status"></div>',
  624. '<div class="form-group">',
  625. '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="onEmailValid" data-bv-onerror="onEmailInvalid" data-bv-onstatus="onEmailStatus" />',
  626. '</div>',
  627. '</form>'
  628. ].join('\n')).appendTo('body');
  629. $('#eventForm').bootstrapValidator();
  630. this.bv = $('#eventForm').data('bootstrapValidator');
  631. this.$email = this.bv.getFieldElements('email');
  632. });
  633. afterEach(function() {
  634. $('#eventForm').bootstrapValidator('destroy').remove();
  635. });
  636. it('call data-bv-onsuccess', function() {
  637. this.$email.val('email@domain.com');
  638. this.bv.validate();
  639. expect($('#msg').html()).toEqual('email is valid');
  640. expect($('#status').html()).toEqual(this.bv.STATUS_VALID);
  641. });
  642. it('call data-bv-onerror', function() {
  643. this.$email.val('A@b@c@example.com');
  644. this.bv.validate();
  645. expect($('#msg').html()).toEqual('email is invalid');
  646. expect($('#status').html()).toEqual(this.bv.STATUS_INVALID);
  647. });
  648. });
  649. describe('event field attribute callback namespace', function() {
  650. beforeEach(function() {
  651. $([
  652. '<form class="form-horizontal" id="eventForm">',
  653. '<div id="msg"></div>',
  654. '<div id="status"></div>',
  655. '<div class="form-group">',
  656. '<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" />',
  657. '</div>',
  658. '</form>'
  659. ].join('\n')).appendTo('body');
  660. $('#eventForm').bootstrapValidator();
  661. this.bv = $('#eventForm').data('bootstrapValidator');
  662. this.$email = this.bv.getFieldElements('email');
  663. });
  664. afterEach(function() {
  665. $('#eventForm').bootstrapValidator('destroy').remove();
  666. });
  667. it('call data-bv-onsuccess', function() {
  668. this.$email.val('email@domain.com');
  669. this.bv.validate();
  670. expect($('#msg').html()).toEqual('TestSuite.Event.onEmailValid() called, email is valid');
  671. expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_VALID);
  672. });
  673. it('call data-bv-onerror', function() {
  674. this.$email.val('a"b(c)d,e:f;gi[j\\k]l@example.com');
  675. this.bv.validate();
  676. expect($('#msg').html()).toEqual('TestSuite.Event.onEmailInvalid() called, email is invalid');
  677. expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_INVALID);
  678. });
  679. });
  680. describe('event field trigger', function() {
  681. beforeEach(function() {
  682. $([
  683. '<form class="form-horizontal" id="eventForm">',
  684. '<div id="msg"></div>',
  685. '<div class="form-group">',
  686. '<input type="text" name="email" data-bv-emailaddress />',
  687. '</div>',
  688. '</form>'
  689. ].join('\n')).appendTo('body');
  690. $('#eventForm')
  691. .bootstrapValidator()
  692. .on('success.field.bv', '[name="email"]', function(e, data) {
  693. $('#msg').html('triggered success.field.bv on ' + data.field);
  694. })
  695. .on('error.field.bv', '[name="email"]', function(e, data) {
  696. $('#msg').html('triggered error.field.bv on ' + data.field);
  697. });
  698. this.bv = $('#eventForm').data('bootstrapValidator');
  699. this.$email = this.bv.getFieldElements('email');
  700. });
  701. afterEach(function() {
  702. $('#eventForm').bootstrapValidator('destroy').remove();
  703. });
  704. it('trigger success.field.bv', function() {
  705. this.$email.val('email@domain.com');
  706. this.bv.validate();
  707. expect($('#msg').html()).toEqual('triggered success.field.bv on email');
  708. });
  709. it('trigger error.field.bv', function() {
  710. this.$email.val('just"not"right@example.com');
  711. this.bv.validate();
  712. expect($('#msg').html()).toEqual('triggered error.field.bv on email');
  713. });
  714. });
  715. describe('event field programmatically', function() {
  716. beforeEach(function() {
  717. $([
  718. '<form class="form-horizontal" id="eventForm">',
  719. '<div id="msg"></div>',
  720. '<div class="form-group">',
  721. '<input type="text" name="email" data-bv-emailaddress />',
  722. '</div>',
  723. '</form>'
  724. ].join('\n')).appendTo('body');
  725. $('#eventForm').bootstrapValidator({
  726. fields: {
  727. email: {
  728. onSuccess: function(e, data) {
  729. $('#msg').html('onSuccess() called');
  730. },
  731. onError: function(e, data) {
  732. $('#msg').html('onError() called');
  733. }
  734. }
  735. }
  736. });
  737. this.bv = $('#eventForm').data('bootstrapValidator');
  738. this.$email = this.bv.getFieldElements('email');
  739. });
  740. afterEach(function() {
  741. $('#eventForm').bootstrapValidator('destroy').remove();
  742. });
  743. it('call onSuccess()', function() {
  744. this.$email.val('email@domain.com');
  745. this.bv.validate();
  746. expect($('#msg').html()).toEqual('onSuccess() called');
  747. });
  748. it('call onError()', function() {
  749. this.$email.val('this is"not\\allowed@example.com');
  750. this.bv.validate();
  751. expect($('#msg').html()).toEqual('onError() called');
  752. });
  753. });
  754. // ---
  755. // Modifying default events
  756. // ---
  757. describe('event form trigger with default events', function() {
  758. beforeEach(function() {
  759. $([
  760. '<form class="form-horizontal" id="eventForm1">',
  761. '<div id="msg"></div>',
  762. '<div class="form-group">',
  763. '<input type="text" name="email" data-bv-emailaddress />',
  764. '</div>',
  765. '</form>'
  766. ].join('\n')).appendTo('body');
  767. $('#eventForm1')
  768. .bootstrapValidator()
  769. .on('bv.form.success', function(e) {
  770. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
  771. })
  772. .on('success.form.bv', function(e) {
  773. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
  774. })
  775. .on('bv.form.error', function(e) {
  776. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
  777. })
  778. .on('error.form.bv', function(e) {
  779. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
  780. });
  781. this.bv = $('#eventForm1').data('bootstrapValidator');
  782. this.$email = this.bv.getFieldElements('email');
  783. });
  784. afterEach(function() {
  785. $('#eventForm1').bootstrapValidator('destroy').remove();
  786. });
  787. it('does not trigger bv.form.success', function() {
  788. this.$email.val('email@domain.com');
  789. this.bv.validate();
  790. expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.success event');
  791. });
  792. it('triggers success.form.bv', function() {
  793. this.$email.val('email@domain.com');
  794. this.bv.validate();
  795. expect($('#msg').html()).toEqual('form eventForm1 triggered success.form.bv event');
  796. });
  797. it('does not trigger bv.form.error', function() {
  798. this.$email.val('A@b@c@example.com');
  799. this.bv.validate();
  800. expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.error event');
  801. });
  802. it('triggers error.form.bv', function() {
  803. this.$email.val('A@b@c@example.com');
  804. this.bv.validate();
  805. expect($('#msg').html()).toEqual('form eventForm1 triggered error.form.bv event');
  806. });
  807. });
  808. describe('event field trigger with default events', function() {
  809. beforeEach(function() {
  810. $([
  811. '<form class="form-horizontal" id="eventForm3">',
  812. '<div id="msg"></div>',
  813. '<div class="form-group">',
  814. '<input type="text" name="email" data-bv-emailaddress />',
  815. '</div>',
  816. '</form>'
  817. ].join('\n')).appendTo('body');
  818. $('#eventForm3')
  819. .bootstrapValidator()
  820. .on('success.field.bv', '[name="email"]', function(e, data) {
  821. $('#msg').html('triggered success.field.bv on ' + data.field);
  822. })
  823. .on('error.field.bv', '[name="email"]', function(e, data) {
  824. $('#msg').html('triggered error.field.bv on ' + data.field);
  825. })
  826. .on('bv.field.success', '[name="email"]', function(e, data) {
  827. $('#msg').html('triggered bv.field.success on ' + data.field);
  828. })
  829. .on('bv.field.error', '[name="email"]', function(e, data) {
  830. $('#msg').html('triggered bv.field.error on ' + data.field);
  831. });
  832. this.bv = $('#eventForm3').data('bootstrapValidator');
  833. this.$email = this.bv.getFieldElements('email');
  834. });
  835. afterEach(function() {
  836. $('#eventForm3').bootstrapValidator('destroy').remove();
  837. });
  838. it('triggers success.field.bv', function() {
  839. this.$email.val('email@domain.com');
  840. this.bv.validate();
  841. expect($('#msg').html()).toEqual('triggered success.field.bv on email');
  842. });
  843. it('does not trigger bv.field.success', function() {
  844. this.$email.val('email@domain.com');
  845. this.bv.validate();
  846. expect($('#msg').html()).not.toEqual('triggered bv.field.success on email');
  847. });
  848. it('does not trigger error.field.bv', function() {
  849. this.$email.val('just"not"right@example.com');
  850. this.bv.validate();
  851. expect($('#msg').html()).toEqual('triggered error.field.bv on email');
  852. });
  853. it('triggers bv.field.error', function() {
  854. this.$email.val('just"not"right@example.com');
  855. this.bv.validate();
  856. expect($('#msg').html()).not.toEqual('triggered bv.field.error on email');
  857. });
  858. });
  859. describe('event form trigger with events changed', function() {
  860. beforeEach(function() {
  861. $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  862. events: {
  863. formInit: 'init.form.bv',
  864. formError: 'bv.form.error',
  865. formSuccess: 'bv.form.success',
  866. fieldAdded: 'added.field.bv',
  867. fieldRemoved: 'removed.field.bv',
  868. fieldInit: 'init.field.bv',
  869. fieldError: 'bv.field.error',
  870. fieldSuccess: 'bv.field.success',
  871. fieldStatus: 'status.field.bv',
  872. validatorError: 'bv.validator.error',
  873. validatorSuccess: 'success.validator.bv'
  874. }
  875. });
  876. $([
  877. '<form class="form-horizontal" id="eventForm2">',
  878. '<div id="msg"></div>',
  879. '<div class="form-group">',
  880. '<input type="text" name="email" data-bv-emailaddress />',
  881. '</div>',
  882. '</form>'
  883. ].join('\n')).appendTo('body');
  884. $('#eventForm2')
  885. .bootstrapValidator()
  886. .on('bv.form.success', function(e) {
  887. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
  888. })
  889. .on('success.form.bv', function(e) {
  890. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
  891. })
  892. .on('bv.form.error', function(e) {
  893. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
  894. })
  895. .on('error.form.bv', function(e) {
  896. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
  897. });
  898. this.bv = $('#eventForm2').data('bootstrapValidator');
  899. this.$email = this.bv.getFieldElements('email');
  900. });
  901. afterEach(function() {
  902. $('#eventForm2').bootstrapValidator('destroy').remove();
  903. });
  904. it('triggers bv.form.success', function() {
  905. this.$email.val('email@domain.com');
  906. this.bv.validate();
  907. expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.success event');
  908. });
  909. it('does not trigger success.form.bv', function() {
  910. this.$email.val('email@domain.com');
  911. this.bv.validate();
  912. expect($('#msg').html()).not.toEqual('form eventForm2 triggered success.form.bv event');
  913. });
  914. it('triggers bv.form.error', function() {
  915. spyOn(window, 'onerror');
  916. this.$email.val('this is"not\\allowed@example.com');
  917. this.bv.validate();
  918. expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.error event');
  919. expect(window.onerror).not.toHaveBeenCalled();
  920. });
  921. });
  922. describe('event field trigger with events changed', function() {
  923. beforeEach(function () {
  924. $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  925. events: {
  926. formInit: 'init.form.bv',
  927. formError: 'bv.form.error',
  928. formSuccess: 'bv.form.success',
  929. fieldAdded: 'added.field.bv',
  930. fieldRemoved: 'removed.field.bv',
  931. fieldInit: 'init.field.bv',
  932. fieldError: 'bv.field.error',
  933. fieldSuccess: 'bv.field.success',
  934. fieldStatus: 'status.field.bv',
  935. validatorError: 'bv.validator.error',
  936. validatorSuccess: 'success.validator.bv'
  937. }
  938. });
  939. $([
  940. '<form class="form-horizontal" id="eventForm4">',
  941. '<div id="msg"></div>',
  942. '<div class="form-group">',
  943. '<input type="text" name="email" data-bv-emailaddress />',
  944. '</div>',
  945. '</form>'
  946. ].join('\n')).appendTo('body');
  947. $('#eventForm4')
  948. .bootstrapValidator()
  949. .on('success.field.bv', '[name="email"]', function(e, data) {
  950. $('#msg').html('triggered success.field.bv on ' + data.field);
  951. })
  952. .on('error.field.bv', '[name="email"]', function(e, data) {
  953. $('#msg').html('triggered error.field.bv on ' + data.field);
  954. })
  955. .on('bv.field.success', '[name="email"]', function(e, data) {
  956. $('#msg').html('triggered bv.field.success on ' + data.field);
  957. })
  958. .on('bv.field.error', '[name="email"]', function(e, data) {
  959. $('#msg').html('triggered bv.field.error on ' + data.field);
  960. });
  961. this.bv = $('#eventForm4').data('bootstrapValidator');
  962. this.$email = this.bv.getFieldElements('email');
  963. });
  964. afterEach(function() {
  965. $('#eventForm4').bootstrapValidator('destroy').remove();
  966. });
  967. it('triggers success.field.bv', function() {
  968. this.$email.val('email@domain.com');
  969. this.bv.validate();
  970. expect($('#msg').html()).not.toEqual('triggered success.field.bv on email');
  971. });
  972. it('does not trigger bv.field.success', function() {
  973. this.$email.val('email@domain.com');
  974. this.bv.validate();
  975. expect($('#msg').html()).toEqual('triggered bv.field.success on email');
  976. });
  977. it('does not trigger error.field.bv', function() {
  978. this.$email.val('Abc.example.com');
  979. this.bv.validate();
  980. expect($('#msg').html()).not.toEqual('triggered error.field.bv on email');
  981. });
  982. it('triggers bv.field.error', function() {
  983. spyOn(window, 'onerror');
  984. this.$email.val('Abc.example.com');
  985. this.bv.validate();
  986. expect($('#msg').html()).toEqual('triggered bv.field.error on email');
  987. expect(window.onerror).not.toHaveBeenCalled();
  988. });
  989. });
  990. // ---
  991. // Validator events
  992. // ---
  993. function onEmailAddressValidatorSuccess(e, data) {
  994. $('#msg').html(data.validator + ' validator passed');
  995. };
  996. function onEmailAddressValidatorError(e, data) {
  997. $('#msg').html(data.validator + ' validator did not pass');
  998. };
  999. describe('event validator declarative', function() {
  1000. beforeEach(function() {
  1001. $([
  1002. '<form class="form-horizontal" id="eventForm">',
  1003. '<div id="msg"></div>',
  1004. '<div class="form-group">',
  1005. '<input type="text" name="email" data-bv-emailaddress data-bv-emailaddress-onsuccess="onEmailAddressValidatorSuccess" data-bv-emailaddress-onerror="onEmailAddressValidatorError" />',
  1006. '</div>',
  1007. '</form>'
  1008. ].join('\n')).appendTo('body');
  1009. $('#eventForm').bootstrapValidator();
  1010. this.bv = $('#eventForm').data('bootstrapValidator');
  1011. this.$email = this.bv.getFieldElements('email');
  1012. });
  1013. afterEach(function() {
  1014. $('#eventForm').bootstrapValidator('destroy').remove();
  1015. });
  1016. it('trigger data-bv-emailaddress-onsuccess', function() {
  1017. this.$email.val('email@domain.com');
  1018. this.bv.validate();
  1019. expect($('#msg').html()).toEqual('emailAddress validator passed');
  1020. });
  1021. it('trigger data-bv-emailaddress-onerror', function() {
  1022. this.$email.val('A@b@c@example.com');
  1023. this.bv.validate();
  1024. expect($('#msg').html()).toEqual('emailAddress validator did not pass');
  1025. });
  1026. });
  1027. describe('event validator programmatically', function() {
  1028. beforeEach(function() {
  1029. $([
  1030. '<form class="form-horizontal" id="eventForm">',
  1031. '<div id="msg"></div>',
  1032. '<div class="form-group">',
  1033. '<input type="text" name="email" data-bv-emailaddress />',
  1034. '</div>',
  1035. '</form>'
  1036. ].join('\n')).appendTo('body');
  1037. $('#eventForm').bootstrapValidator({
  1038. fields: {
  1039. email: {
  1040. validators: {
  1041. emailAddress: {
  1042. onSuccess: function(e, data) {
  1043. $('#msg').html('emailAddress validator: onSuccess() called');
  1044. },
  1045. onError: function(e, data) {
  1046. $('#msg').html('emailAddress validator: onError() called');
  1047. },
  1048. message: 'The email address is not valid'
  1049. }
  1050. }
  1051. }
  1052. }
  1053. });
  1054. this.bv = $('#eventForm').data('bootstrapValidator');
  1055. this.$email = this.bv.getFieldElements('email');
  1056. });
  1057. afterEach(function() {
  1058. $('#eventForm').bootstrapValidator('destroy').remove();
  1059. });
  1060. it('call onSuccess()', function() {
  1061. this.$email.val('email@domain.com');
  1062. this.bv.validate();
  1063. expect($('#msg').html()).toEqual('emailAddress validator: onSuccess() called');
  1064. });
  1065. it('call onError()', function() {
  1066. this.$email.val('A@b@c@example.com');
  1067. this.bv.validate();
  1068. expect($('#msg').html()).toEqual('emailAddress validator: onError() called');
  1069. });
  1070. });
  1071. describe('excluded', function() {
  1072. beforeEach(function() {
  1073. $([
  1074. '<div class="container">',
  1075. '<form class="form-horizontal" id="excludedForm" data-bv-excluded="[name=\'email\']">',
  1076. '<div class="form-group">',
  1077. '<input type="text" name="username" required />',
  1078. '</div>',
  1079. '<div class="form-group">',
  1080. '<input type="text" name="email" required data-bv-emailaddress />',
  1081. '</div>',
  1082. '</form>',
  1083. '</div>'
  1084. ].join('')).appendTo('body');
  1085. $('#excludedForm').bootstrapValidator();
  1086. this.bv = $('#excludedForm').data('bootstrapValidator');
  1087. this.$username = this.bv.getFieldElements('username');
  1088. this.$email = this.bv.getFieldElements('email');
  1089. });
  1090. afterEach(function() {
  1091. $('#excludedForm').bootstrapValidator('destroy').parent().remove();
  1092. });
  1093. it('excluded form declarative', function() {
  1094. this.bv.validate();
  1095. expect(this.bv.isValid()).toEqual(false);
  1096. this.bv.resetForm();
  1097. this.$username.val('your_user_name');
  1098. this.$email.val('');
  1099. this.bv.validate();
  1100. expect(this.bv.isValid()).toBeTruthy();
  1101. });
  1102. it('excluded form programmatically', function() {
  1103. this.bv.destroy();
  1104. $('#excludedForm').removeAttr('data-bv-excluded');
  1105. $('#excludedForm').bootstrapValidator({
  1106. excluded: '[name="username"]'
  1107. });
  1108. this.bv = $('#excludedForm').data('bootstrapValidator');
  1109. this.$username = this.bv.getFieldElements('username');
  1110. this.$email = this.bv.getFieldElements('email');
  1111. this.$username.val('');
  1112. this.$email.val('invalid#email.com');
  1113. this.bv.validate();
  1114. expect(this.bv.isValid()).toEqual(false);
  1115. this.bv.resetForm();
  1116. this.$email.val('valid@email.com');
  1117. this.bv.validate();
  1118. expect(this.bv.isValid()).toBeTruthy();
  1119. });
  1120. it('excluded field declarative', function() {
  1121. this.bv.destroy();
  1122. $('#excludedForm').removeAttr('data-bv-excluded');
  1123. $('#excludedForm').find('[name="username"]').attr('data-bv-excluded', 'true');
  1124. $('#excludedForm').find('[name="email"]').attr('data-bv-excluded', 'false');
  1125. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  1126. this.$username = this.bv.getFieldElements('username');
  1127. this.$email = this.bv.getFieldElements('email');
  1128. this.$username.val('');
  1129. this.$email.val('');
  1130. this.bv.validate();
  1131. expect(this.bv.isValid()).toEqual(false);
  1132. this.bv.resetForm();
  1133. this.$email.val('invalid#email.com');
  1134. this.bv.validate();
  1135. expect(this.bv.isValid()).toEqual(false);
  1136. this.bv.resetForm();
  1137. this.$email.val('valid@email.com');
  1138. this.bv.validate();
  1139. expect(this.bv.isValid()).toBeTruthy();
  1140. });
  1141. it('excluded field programmatically true/false', function() {
  1142. this.bv.destroy();
  1143. $('#excludedForm').removeAttr('data-bv-excluded');
  1144. $('#excludedForm').bootstrapValidator({
  1145. fields: {
  1146. username: {
  1147. excluded: true
  1148. },
  1149. email: {
  1150. excluded: false
  1151. }
  1152. }
  1153. });
  1154. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  1155. this.$username = this.bv.getFieldElements('username');
  1156. this.$email = this.bv.getFieldElements('email');
  1157. this.$username.val('');
  1158. this.$email.val('');
  1159. this.bv.validate();
  1160. expect(this.bv.isValid()).toEqual(false);
  1161. this.bv.resetForm();
  1162. this.$email.val('invalid#email.com');
  1163. this.bv.validate();
  1164. expect(this.bv.isValid()).toEqual(false);
  1165. this.bv.resetForm();
  1166. this.$email.val('valid@email.com');
  1167. this.bv.validate();
  1168. expect(this.bv.isValid()).toBeTruthy();
  1169. });
  1170. it('excluded field programmatically "true"/"false"', function() {
  1171. this.bv.destroy();
  1172. $('#excludedForm').removeAttr('data-bv-excluded');
  1173. $('#excludedForm').bootstrapValidator({
  1174. fields: {
  1175. username: {
  1176. excluded: 'false'
  1177. },
  1178. email: {
  1179. excluded: 'true'
  1180. }
  1181. }
  1182. });
  1183. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  1184. this.$username = this.bv.getFieldElements('username');
  1185. this.$email = this.bv.getFieldElements('email');
  1186. this.$username.val('');
  1187. this.$email.val('valid@email.com');
  1188. this.bv.validate();
  1189. expect(this.bv.isValid()).toEqual(false);
  1190. this.bv.resetForm();
  1191. this.$username.val('your_user_name');
  1192. this.$email.val('invalid#email.com');
  1193. this.bv.validate();
  1194. expect(this.bv.isValid()).toBeTruthy();
  1195. });
  1196. });
  1197. describe('group option', function() {
  1198. beforeEach(function() {
  1199. $([
  1200. '<form id="groupForm" method="post" class="form-horizontal">',
  1201. '<div class="form-group">',
  1202. '<div class="firstNameGroup">',
  1203. '<label class="col-sm-2 control-label">First name</label>',
  1204. '<div class="col-sm-4">',
  1205. '<input type="text" class="form-control" name="firstName" />',
  1206. '</div>',
  1207. '</div>',
  1208. '<div class="lastNameGroup">',
  1209. '<label class="col-sm-2 control-label">Last name</label>',
  1210. '<div class="col-sm-4">',
  1211. '<input type="text" class="form-control" name="lastName" data-bv-group=".lastNameGroup" />',
  1212. '</div>',
  1213. '</div>',
  1214. '</div>',
  1215. '<div class="form-group">',
  1216. '<label class="col-sm-2 control-label">Username</label>',
  1217. '<div class="col-sm-5">',
  1218. '<input type="text" class="form-control" name="username" />',
  1219. '</div>',
  1220. '</div>',
  1221. '</form>'
  1222. ].join('')).appendTo('body');
  1223. $('#groupForm').bootstrapValidator({
  1224. fields: {
  1225. firstName: {
  1226. group: '.firstNameGroup',
  1227. validators: {
  1228. notEmpty: {
  1229. message: 'The first name is required and cannot be empty'
  1230. }
  1231. }
  1232. },
  1233. lastName: {
  1234. validators: {
  1235. notEmpty: {
  1236. message: 'The last name is required and cannot be empty'
  1237. }
  1238. }
  1239. },
  1240. username: {
  1241. validators: {
  1242. notEmpty: {
  1243. message: 'The username is required and cannot be empty'
  1244. },
  1245. stringLength: {
  1246. min: 6,
  1247. max: 30,
  1248. message: 'The username must be more than 6 and less than 30 characters long'
  1249. },
  1250. regexp: {
  1251. regexp: /^[a-zA-Z0-9_\.]+$/,
  1252. message: 'The username can only consist of alphabetical, number, dot and underscore'
  1253. }
  1254. }
  1255. }
  1256. }
  1257. });
  1258. this.bv = $('#groupForm').data('bootstrapValidator');
  1259. this.$firstName = this.bv.getFieldElements('firstName');
  1260. this.$lastName = this.bv.getFieldElements('lastName');
  1261. this.$username = this.bv.getFieldElements('username');
  1262. });
  1263. afterEach(function() {
  1264. $('#groupForm').bootstrapValidator('destroy').remove();
  1265. });
  1266. it('group default', function() {
  1267. this.$username.val('123@#$');
  1268. this.bv.validate();
  1269. expect(this.$username.parents('.form-group').hasClass('has-error')).toBeTruthy();
  1270. expect(this.$username.parents('.form-group').hasClass('has-success')).toEqual(false);
  1271. this.bv.resetForm();
  1272. this.$username.val('validUser.Name');
  1273. this.bv.validate();
  1274. expect(this.$username.parents('.form-group').hasClass('has-success')).toBeTruthy();
  1275. expect(this.$username.parents('.form-group').hasClass('has-error')).toEqual(false);
  1276. });
  1277. it('group programmatically', function() {
  1278. this.$firstName.val('');
  1279. this.bv.validate();
  1280. expect(this.$firstName.parents('.firstNameGroup').hasClass('has-error')).toBeTruthy();
  1281. expect(this.$firstName.parents('.firstNameGroup').hasClass('has-success')).toEqual(false);
  1282. expect(this.$firstName.parents('.form-group').hasClass('has-error')).toEqual(false);
  1283. });
  1284. it('group declarative', function() {
  1285. this.$firstName.val('First');
  1286. this.$lastName.val('Last');
  1287. this.bv.validate();
  1288. expect(this.$lastName.parents('.lastNameGroup').hasClass('has-success')).toBeTruthy();
  1289. expect(this.$lastName.parents('.lastNameGroup').hasClass('has-error')).toEqual(false);
  1290. expect(this.$lastName.parents('.form-group').hasClass('has-success')).toEqual(false);
  1291. expect(this.$lastName.parents('.form-group').hasClass('has-error')).toEqual(false);
  1292. });
  1293. });
  1294. describe('i18n', function() {
  1295. beforeEach(function() {
  1296. $([
  1297. '<form id="i18nForm" class="form-horizontal">',
  1298. '<div class="form-group">',
  1299. '<label class="col-lg-3 control-label">Full name</label>',
  1300. '<div class="col-lg-5">',
  1301. '<input type="text" class="form-control" name="fullName" />',
  1302. '</div>',
  1303. '</div>',
  1304. '<div class="form-group">',
  1305. '<label class="col-lg-3 control-label">Username</label>',
  1306. '<div class="col-lg-5">',
  1307. '<input type="text" class="form-control" name="username" />',
  1308. '</div>',
  1309. '</div>',
  1310. '<div class="form-group">',
  1311. '<label class="col-lg-3 control-label">Email address</label>',
  1312. '<div class="col-lg-5">',
  1313. '<input type="text" class="form-control" name="email" />',
  1314. '</div>',
  1315. '</div>',
  1316. '<div class="form-group">',
  1317. '<label class="col-lg-3 control-label">Password</label>',
  1318. '<div class="col-lg-5">',
  1319. '<input type="password" class="form-control" name="password" />',
  1320. '</div>',
  1321. '</div>',
  1322. '<div class="form-group">',
  1323. '<label class="col-lg-3 control-label">Retype password</label>',
  1324. '<div class="col-lg-5">',
  1325. '<input type="password" class="form-control" name="confirmPassword" />',
  1326. '</div>',
  1327. '</div>',
  1328. '<div class="form-group">',
  1329. '<label class="col-lg-3 control-label">Gender</label>',
  1330. '<div class="col-lg-5">',
  1331. '<div class="radio">',
  1332. '<label><input type="radio" name="gender" value="male" /> Male</label>',
  1333. '</div>',
  1334. '<div class="radio">',
  1335. '<label><input type="radio" name="gender" value="female" /> Female</label>',
  1336. '</div>',
  1337. '<div class="radio">',
  1338. '<label><input type="radio" name="gender" value="other" /> Other</label>',
  1339. '</div>',
  1340. '</div>',
  1341. '</div>',
  1342. '<div class="form-group">',
  1343. '<label class="col-lg-3 control-label">Age</label>',
  1344. '<div class="col-lg-3">',
  1345. '<input type="text" class="form-control" name="age" />',
  1346. '</div>',
  1347. '</div>',
  1348. '<div class="form-group">',
  1349. '<label class="col-lg-3 control-label">Website</label>',
  1350. '<div class="col-lg-5">',
  1351. '<input type="text" class="form-control" name="website" />',
  1352. '</div>',
  1353. '</div>',
  1354. '<div class="form-group">',
  1355. '<label class="col-lg-3 control-label">Phone number</label>',
  1356. '<div class="col-lg-5">',
  1357. '<input type="text" class="form-control" name="phoneNumber" />',
  1358. '</div>',
  1359. '</div>',
  1360. '<div class="form-group">',
  1361. '<label class="col-lg-3 control-label">Languages</label>',
  1362. '<div class="col-lg-5">',
  1363. '<div class="checkbox">',
  1364. '<label><input type="checkbox" name="languages[]" value="english" /> English</label>',
  1365. '</div>',
  1366. '<div class="checkbox">',
  1367. '<label><input type="checkbox" name="languages[]" value="french" /> French</label>',
  1368. '</div>',
  1369. '<div class="checkbox">',
  1370. '<label><input type="checkbox" name="languages[]" value="german" /> German</label>',
  1371. '</div>',
  1372. '<div class="checkbox">',
  1373. '<label><input type="checkbox" name="languages[]" value="russian" /> Russian</label>',
  1374. '</div>',
  1375. '<div class="checkbox">',
  1376. '<label><input type="checkbox" name="languages[]" value="other" /> Other</label>',
  1377. '</div>',
  1378. '</div>',
  1379. '</div>',
  1380. '<div class="form-group">',
  1381. '<label class="col-lg-3 control-label">Programming Languages</label>',
  1382. '<div class="col-lg-5">',
  1383. '<div class="checkbox">',
  1384. '<label><input type="checkbox" name="programs[]" value="net" /> .Net</label>',
  1385. '</div>',
  1386. '<div class="checkbox">',
  1387. '<label><input type="checkbox" name="programs[]" value="java" /> Java</label>',
  1388. '</div>',
  1389. '<div class="checkbox">',
  1390. '<label><input type="checkbox" name="programs[]" value="c" /> C/C++</label>',
  1391. '</div>',
  1392. '<div class="checkbox">',
  1393. '<label><input type="checkbox" name="programs[]" value="php" /> PHP</label>',
  1394. '</div>',
  1395. '<div class="checkbox">',
  1396. '<label><input type="checkbox" name="programs[]" value="perl" /> Perl</label>',
  1397. '</div>',
  1398. '<div class="checkbox">',
  1399. '<label><input type="checkbox" name="programs[]" value="ruby" /> Ruby</label>',
  1400. '</div>',
  1401. '<div class="checkbox">',
  1402. '<label><input type="checkbox" name="programs[]" value="python" /> Python</label>',
  1403. '</div>',
  1404. '<div class="checkbox">',
  1405. '<label><input type="checkbox" name="programs[]" value="javascript" /> Javascript</label>',
  1406. '</div>',
  1407. '</div>',
  1408. '</div>',
  1409. '</form>'
  1410. ].join('')).appendTo('body');
  1411. $('#i18nForm').bootstrapValidator({
  1412. feedbackIcons: {
  1413. valid: 'glyphicon glyphicon-ok',
  1414. invalid: 'glyphicon glyphicon-remove',
  1415. validating: 'glyphicon glyphicon-refresh'
  1416. },
  1417. fields: {
  1418. fullName: {
  1419. validators: {
  1420. notEmpty: {},
  1421. stringCase: {
  1422. 'case': 'upper'
  1423. }
  1424. }
  1425. },
  1426. username: {
  1427. validators: {
  1428. notEmpty: {},
  1429. stringLength: {
  1430. min: 6,
  1431. max: 20
  1432. },
  1433. regexp: {
  1434. regexp: /^[a-zA-Z0-9_\.]+$/
  1435. },
  1436. different: {
  1437. field: 'password'
  1438. }
  1439. }
  1440. },
  1441. email: {
  1442. validators: {
  1443. emailAddress: {}
  1444. }
  1445. },
  1446. password: {
  1447. validators: {
  1448. notEmpty: {},
  1449. identical: {
  1450. field: 'confirmPassword'
  1451. },
  1452. different: {
  1453. field: 'username'
  1454. }
  1455. }
  1456. },
  1457. confirmPassword: {
  1458. validators: {
  1459. notEmpty: {},
  1460. identical: {
  1461. field: 'password'
  1462. },
  1463. different: {
  1464. field: 'username'
  1465. }
  1466. }
  1467. },
  1468. age: {
  1469. validators: {
  1470. notEmpty: {},
  1471. digits: {},
  1472. greaterThan: {
  1473. value: 18
  1474. },
  1475. lessThan: {
  1476. value: 100
  1477. }
  1478. }
  1479. },
  1480. website: {
  1481. validators: {
  1482. notEmpty: {},
  1483. uri: {}
  1484. }
  1485. },
  1486. phoneNumber: {
  1487. validators: {
  1488. notEmpty: {},
  1489. digits: {},
  1490. phone: {
  1491. country: 'US'
  1492. }
  1493. }
  1494. },
  1495. gender: {
  1496. validators: {
  1497. notEmpty: {}
  1498. }
  1499. },
  1500. 'languages[]': {
  1501. validators: {
  1502. notEmpty: {}
  1503. }
  1504. },
  1505. 'programs[]': {
  1506. validators: {
  1507. choice: {
  1508. min: 2,
  1509. max: 4
  1510. }
  1511. }
  1512. }
  1513. }
  1514. });
  1515. this.bv = $('#i18nForm').data('bootstrapValidator');
  1516. this.$fullName = this.bv.getFieldElements('fullName');
  1517. this.$email = this.bv.getFieldElements('email');
  1518. this.$userName = this.bv.getFieldElements('username');
  1519. this.$password = this.bv.getFieldElements('password');
  1520. this.$confirm = this.bv.getFieldElements('confirmPassword');
  1521. this.$age = this.bv.getFieldElements('age');
  1522. this.$website = this.bv.getFieldElements('website');
  1523. this.$phone = this.bv.getFieldElements('phoneNumber');
  1524. this.$program = this.bv.getFieldElements('programs[]');
  1525. });
  1526. afterEach(function() {
  1527. $('#i18nForm').bootstrapValidator('destroy').remove();
  1528. });
  1529. it('default message', function() {
  1530. var format = $.fn.bootstrapValidator.helpers.format,
  1531. i18n = $.fn.bootstrapValidator.i18n;
  1532. this.bv.validate();
  1533. expect(this.bv.getMessages(this.$fullName, 'notEmpty')[0]).toEqual(i18n.notEmpty['default']);
  1534. this.$fullName.val('lowerName');
  1535. this.bv.revalidateField('fullName');
  1536. expect(this.bv.getMessages('fullName', 'stringCase')[0]).toEqual(i18n.stringCase.upper);
  1537. this.bv.resetForm();
  1538. this.$userName.val('123');
  1539. this.bv.validate();
  1540. expect(this.bv.getMessages('username', 'stringLength')[0]).toEqual(format(i18n.stringLength.between, [6, 20]));
  1541. this.bv.resetForm();
  1542. this.$userName.val('contain@#$');
  1543. this.bv.validate();
  1544. expect(this.bv.getMessages(this.$userName, 'regexp')[0]).toEqual(i18n.regexp['default']);
  1545. this.bv.resetForm();
  1546. this.$userName.val('validUserName');
  1547. this.$password.val('validUserName');
  1548. this.bv.validate();
  1549. expect(this.bv.getMessages('username', 'different')[0]).toEqual(i18n.different['default']);
  1550. this.bv.resetForm();
  1551. this.$email.val('A@b@c@example.com');
  1552. this.bv.validate();
  1553. expect(this.bv.getMessages(this.$email, 'emailAddress')[0]).toEqual(i18n.emailAddress['default']);
  1554. this.bv.resetForm();
  1555. this.$password.val('@S3cur3P@@w0rd');
  1556. this.$confirm.val('notMatch');
  1557. this.bv.validate();
  1558. expect(this.bv.getMessages('password', 'identical')[0]).toEqual(i18n.identical['default']);
  1559. this.bv.resetForm();
  1560. this.$age.val('notDigit');
  1561. this.bv.validate();
  1562. expect(this.bv.getMessages('age', 'digits')[0]).toEqual(i18n.digits['default']);
  1563. this.bv.resetForm();
  1564. this.$age.val(10);
  1565. this.bv.validate();
  1566. expect(this.bv.getMessages(this.$age, 'greaterThan')[0]).toEqual(format(i18n.greaterThan['default'], 18));
  1567. this.bv.resetForm();
  1568. this.$age.val(120);
  1569. this.bv.validate();
  1570. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual(format(i18n.lessThan['default'], 100));
  1571. this.bv.resetForm();
  1572. this.$website.val('http://invalidWebsite');
  1573. this.bv.validate();
  1574. expect(this.bv.getMessages('website', 'uri')[0]).toEqual(i18n.uri['default']);
  1575. this.bv.resetForm();
  1576. this.$phone.val('123456');
  1577. this.bv.validate();
  1578. expect(this.bv.getMessages('phoneNumber', 'phone')[0]).toEqual(format(i18n.phone.country, i18n.phone.countries['US']));
  1579. this.bv.resetForm();
  1580. this.$program.eq(0).prop('checked', 'checked');
  1581. this.bv.validate();
  1582. expect(this.bv.getMessages(this.$program, 'choice')[0]).toEqual(format(i18n.choice.between, [2, 4]));
  1583. this.bv.resetForm();
  1584. this.$program.prop('checked', 'checked');
  1585. this.bv.validate();
  1586. expect(this.bv.getMessages('programs[]', 'choice')[0]).toEqual(format(i18n.choice.between, [2, 4]));
  1587. });
  1588. });
  1589. describe('message', function() {
  1590. beforeEach(function() {
  1591. var html = [
  1592. '<div class="container">',
  1593. '<form class="form-horizontal" id="messageForm">',
  1594. '<div class="form-group">',
  1595. '<input type="password" class="form-control" name="password" placeholder="Enter secure password" />',
  1596. '</div>',
  1597. '</form>',
  1598. '</div>'
  1599. ].join('\n');
  1600. $(html).appendTo('body');
  1601. $('#messageForm').bootstrapValidator({
  1602. fields: {
  1603. password: {
  1604. validators: {
  1605. notEmpty: {
  1606. message: 'The password is required'
  1607. },
  1608. callback: {
  1609. callback: function(value, validator) {
  1610. // Check the password strength
  1611. if (value.length < 6) {
  1612. return {
  1613. valid: false,
  1614. message: 'The password must be more than 6 characters'
  1615. }
  1616. }
  1617. if (value === value.toLowerCase()) {
  1618. return {
  1619. valid: false,
  1620. message: 'The password must contain at least one upper case character'
  1621. }
  1622. }
  1623. if (value === value.toUpperCase()) {
  1624. return {
  1625. valid: false,
  1626. message: 'The password must contain at least one lower case character'
  1627. }
  1628. }
  1629. if (value.search(/[0-9]/) < 0) {
  1630. return {
  1631. valid: false,
  1632. message: 'The password must contain at least one digit'
  1633. }
  1634. }
  1635. return true;
  1636. }
  1637. }
  1638. }
  1639. }
  1640. }
  1641. });
  1642. this.bv = $('#messageForm').data('bootstrapValidator');
  1643. this.$password = this.bv.getFieldElements('password');
  1644. });
  1645. afterEach(function() {
  1646. $('#messageForm').bootstrapValidator('destroy').parent().remove();
  1647. });
  1648. it('update message from callback', function() {
  1649. this.bv.resetForm();
  1650. this.$password.val('123');
  1651. this.bv.validate();
  1652. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must be more than 6 characters');
  1653. this.bv.resetForm();
  1654. this.$password.val('no_upper_case!@#');
  1655. this.bv.validate();
  1656. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one upper case character');
  1657. this.bv.resetForm();
  1658. this.$password.val('NO_LOWER_CASE123');
  1659. this.bv.validate();
  1660. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one lower case character');
  1661. this.bv.resetForm();
  1662. this.$password.val('NoDigits!@#');
  1663. this.bv.validate();
  1664. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one digit');
  1665. });
  1666. it('call updateMessage()', function() {
  1667. this.bv.updateStatus('password', this.bv.STATUS_INVALID, 'callback');
  1668. this.bv.updateMessage('password', 'callback', 'The password is weak');
  1669. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password is weak');
  1670. this.bv.updateMessage(this.$password, 'callback', 'The password is not strong');
  1671. expect(this.bv.getMessages(this.$password, 'callback')[0]).toEqual('The password is not strong');
  1672. });
  1673. });
  1674. describe('verbose option', function() {
  1675. beforeEach(function() {
  1676. $([
  1677. '<form class="form-horizontal" id="verboseForm">',
  1678. '<div class="form-group">',
  1679. '<input type="text" name="fullName" class="form-control" ',
  1680. 'required data-bv-notempty-message="The full name is required and cannot be empty" ',
  1681. '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" ',
  1682. '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" ',
  1683. '/>',
  1684. '</div>',
  1685. '</form>'
  1686. ].join('\n')).appendTo('body');
  1687. // The order of validators are alphabetical:
  1688. // - notEmpty
  1689. // - regexp
  1690. // - stringLength
  1691. });
  1692. afterEach(function() {
  1693. $('#verboseForm').bootstrapValidator('destroy').remove();
  1694. });
  1695. it('set data-bv-verbose="false" for form', function() {
  1696. var bv = $('#verboseForm').attr('data-bv-verbose', 'false').bootstrapValidator().data('bootstrapValidator'),
  1697. $fullName = bv.getFieldElements('fullName'),
  1698. messages;
  1699. $fullName.val('');
  1700. bv.validate();
  1701. messages = bv.getMessages('fullName');
  1702. expect(messages.length).toEqual(1);
  1703. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1704. bv.resetForm();
  1705. $fullName.val('Special@#$');
  1706. bv.validate();
  1707. messages = bv.getMessages('fullName');
  1708. expect(messages.length).toEqual(1);
  1709. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1710. bv.resetForm();
  1711. $fullName.val('Full');
  1712. bv.validate();
  1713. messages = bv.getMessages('fullName');
  1714. expect(messages.length).toEqual(1);
  1715. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1716. });
  1717. it('set data-bv-verbose="false" for field', function() {
  1718. var bv = $('#verboseForm')
  1719. .attr('data-bv-verbose', 'true')
  1720. .find('[name="fullName"]')
  1721. .attr('data-bv-verbose', 'false')
  1722. .end()
  1723. .bootstrapValidator().data('bootstrapValidator'),
  1724. $fullName = bv.getFieldElements('fullName'),
  1725. messages;
  1726. $fullName.val('');
  1727. bv.validate();
  1728. messages = bv.getMessages('fullName');
  1729. expect(messages.length).toEqual(1);
  1730. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1731. bv.resetForm();
  1732. $fullName.val('Special@#$');
  1733. bv.validate();
  1734. messages = bv.getMessages('fullName');
  1735. expect(messages.length).toEqual(1);
  1736. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1737. bv.resetForm();
  1738. $fullName.val('Full');
  1739. bv.validate();
  1740. messages = bv.getMessages('fullName');
  1741. expect(messages.length).toEqual(1);
  1742. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1743. });
  1744. it('set verbose: "false" for form', function() {
  1745. var bv = $('#verboseForm').bootstrapValidator({ verbose: false }).data('bootstrapValidator'),
  1746. $fullName = bv.getFieldElements('fullName'),
  1747. messages;
  1748. $fullName.val('');
  1749. bv.validate();
  1750. messages = bv.getMessages('fullName');
  1751. expect(messages.length).toEqual(1);
  1752. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1753. bv.resetForm();
  1754. $fullName.val('Special@#$');
  1755. bv.validate();
  1756. messages = bv.getMessages('fullName');
  1757. expect(messages.length).toEqual(1);
  1758. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1759. bv.resetForm();
  1760. $fullName.val('Full');
  1761. bv.validate();
  1762. messages = bv.getMessages('fullName');
  1763. expect(messages.length).toEqual(1);
  1764. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1765. });
  1766. it('set verbose: "false" for field', function() {
  1767. var bv = $('#verboseForm')
  1768. .attr('data-bv-verbose', 'true')
  1769. .bootstrapValidator({
  1770. verbose: true,
  1771. fields: {
  1772. fullName: {
  1773. verbose: false
  1774. }
  1775. }
  1776. })
  1777. .data('bootstrapValidator'),
  1778. $fullName = bv.getFieldElements('fullName'),
  1779. messages;
  1780. $fullName.val('');
  1781. bv.validate();
  1782. messages = bv.getMessages('fullName');
  1783. expect(messages.length).toEqual(1);
  1784. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1785. bv.resetForm();
  1786. $fullName.val('Special@#$');
  1787. bv.validate();
  1788. messages = bv.getMessages('fullName');
  1789. expect(messages.length).toEqual(1);
  1790. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1791. bv.resetForm();
  1792. $fullName.val('Full');
  1793. bv.validate();
  1794. messages = bv.getMessages('fullName');
  1795. expect(messages.length).toEqual(1);
  1796. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1797. });
  1798. });
  1799. function betweenCompareMin() {
  1800. var compareTo = $('#betweenForm').find('[name="minAge"]').val();
  1801. $('#msgMin').html('betweenCompareMin() called; compare to ' + compareTo);
  1802. return compareTo;
  1803. };
  1804. function betweenCompareMax() {
  1805. var compareTo = $('#betweenForm').find('[name="maxAge"]').val();
  1806. $('#msgMax').html('betweenCompareMax() called; compare to ' + compareTo);
  1807. return compareTo;
  1808. };
  1809. TestSuite = $.extend({}, TestSuite, {
  1810. between: {
  1811. compareToMin: function(value, validator, $field) {
  1812. var compareTo = $('#betweenForm').find('[name="minAge"]').val();
  1813. $('#msgMin').html('TestSuite.between.compareToMin() called; compare to ' + compareTo);
  1814. return compareTo;
  1815. },
  1816. compareToMax: function(value, validator, $field) {
  1817. var compareTo = $('#betweenForm').find('[name="maxAge"]').val();
  1818. $('#msgMax').html('TestSuite.between.compareToMax() called; compare to ' + compareTo);
  1819. return compareTo;
  1820. }
  1821. }
  1822. });
  1823. describe('between', function() {
  1824. beforeEach(function() {
  1825. $([
  1826. '<form class="form-horizontal" id="betweenForm">',
  1827. '<div id="msgMin"></div>',
  1828. '<div id="msgMax"></div>',
  1829. '<div class="form-group">',
  1830. '<input type="text" name="minAge" />',
  1831. '</div>',
  1832. '<div class="form-group">',
  1833. '<input type="text" name="maxAge" />',
  1834. '</div>',
  1835. '<div class="form-group">',
  1836. '<input type="text" name="age" data-bv-between data-bv-between-min="18" data-bv-between-max="100" />',
  1837. '</div>',
  1838. '</form>'
  1839. ].join('\n')).appendTo('body');
  1840. $('#betweenForm').bootstrapValidator();
  1841. this.bv = $('#betweenForm').data('bootstrapValidator');
  1842. this.$minAge = this.bv.getFieldElements('minAge');
  1843. this.$maxAge = this.bv.getFieldElements('maxAge');
  1844. this.$age = this.bv.getFieldElements('age');
  1845. });
  1846. afterEach(function() {
  1847. $('#betweenForm').bootstrapValidator('destroy').remove();
  1848. });
  1849. it('not a number', function() {
  1850. this.$age.val('50abc');
  1851. this.bv.validate();
  1852. expect(this.bv.isValid()).toEqual(false);
  1853. });
  1854. it('compare to value', function() {
  1855. this.$age.val(10);
  1856. this.bv.validate();
  1857. expect(this.bv.isValid()).toEqual(false);
  1858. this.bv.resetForm();
  1859. this.$age.val(120);
  1860. this.bv.validate();
  1861. expect(this.bv.isValid()).toEqual(false);
  1862. this.bv.resetForm();
  1863. this.$age.val(30);
  1864. this.bv.validate();
  1865. expect(this.bv.isValid()).toBeTruthy();
  1866. });
  1867. it('compare to other field', function() {
  1868. this.$age.attr('data-bv-between-min', 'minAge')
  1869. .attr('data-bv-between-max', 'maxAge');
  1870. this.bv.destroy();
  1871. this.bv = $('#betweenForm').bootstrapValidator().data('bootstrapValidator');
  1872. this.$minAge.val(2);
  1873. this.$maxAge.val(10);
  1874. this.$age.val(5);
  1875. this.bv.validate();
  1876. expect(this.bv.isValid()).toBeTruthy();
  1877. this.bv.resetForm();
  1878. this.$minAge.val(20);
  1879. this.$maxAge.val(40);
  1880. this.$age.val(50);
  1881. this.bv.validate();
  1882. expect(this.bv.isValid()).toEqual(false);
  1883. expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
  1884. });
  1885. it('compare to return value of a function', function() {
  1886. this.$age.attr('data-bv-between-min', 'betweenCompareMin')
  1887. .attr('data-bv-between-max', 'betweenCompareMax');
  1888. this.bv.destroy();
  1889. this.bv = $('#betweenForm').bootstrapValidator().data('bootstrapValidator');
  1890. this.$minAge.val(20);
  1891. this.$maxAge.val(30);
  1892. this.$age.val(18);
  1893. this.bv.validate();
  1894. expect($('#msgMin').html()).toEqual('betweenCompareMin() called; compare to 20');
  1895. expect($('#msgMax').html()).toEqual('betweenCompareMax() called; compare to 30');
  1896. expect(this.bv.isValid()).toEqual(false);
  1897. expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
  1898. this.bv.resetForm();
  1899. this.$minAge.val(2);
  1900. this.$maxAge.val(10);
  1901. this.$age.val(6);
  1902. this.bv.validate();
  1903. expect($('#msgMin').html()).toEqual('betweenCompareMin() called; compare to 2');
  1904. expect($('#msgMax').html()).toEqual('betweenCompareMax() called; compare to 10');
  1905. expect(this.bv.isValid()).toBeTruthy();
  1906. });
  1907. it('compare to return value of a namespace function', function() {
  1908. this.$age.attr('data-bv-between-min', 'TestSuite.between.compareToMin')
  1909. .attr('data-bv-between-max', 'TestSuite.between.compareToMax');
  1910. this.bv.destroy();
  1911. this.bv = $('#betweenForm').bootstrapValidator().data('bootstrapValidator');
  1912. this.$minAge.val(20);
  1913. this.$maxAge.val(30);
  1914. this.$age.val(40);
  1915. this.bv.validate();
  1916. expect($('#msgMin').html()).toEqual('TestSuite.between.compareToMin() called; compare to 20');
  1917. expect($('#msgMax').html()).toEqual('TestSuite.between.compareToMax() called; compare to 30');
  1918. expect(this.bv.isValid()).toEqual(false);
  1919. expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
  1920. this.bv.resetForm();
  1921. this.$minAge.val(2);
  1922. this.$maxAge.val(10);
  1923. this.$age.val(5);
  1924. this.bv.validate();
  1925. expect($('#msgMin').html()).toEqual('TestSuite.between.compareToMin() called; compare to 2');
  1926. expect($('#msgMax').html()).toEqual('TestSuite.between.compareToMax() called; compare to 10');
  1927. expect(this.bv.isValid()).toBeTruthy();
  1928. });
  1929. });
  1930. function validateCaptcha(value, validator, $field) {
  1931. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  1932. return value === sum + '';
  1933. };
  1934. describe('callback', function() {
  1935. beforeEach(function() {
  1936. $([
  1937. '<form class="form-horizontal" id="callbackForm">',
  1938. '<div class="form-group">',
  1939. '<label class="col-md-3 control-label" id="captchaOperation"></label>',
  1940. '<div class="col-md-2">',
  1941. '<input type="text" class="form-control" name="captcha" />',
  1942. '</div>',
  1943. '</div>',
  1944. '<div class="form-group">',
  1945. '<div class="col-md-2 col-md-offset-3">',
  1946. '<input type="text" class="form-control" name="declarativeCaptcha" data-bv-callback data-bv-callback-callback="validateCaptcha" />',
  1947. '</div>',
  1948. '</div>',
  1949. '</form>'
  1950. ].join('\n')).appendTo('body');
  1951. $('#callbackForm').bootstrapValidator({
  1952. fields: {
  1953. captcha: {
  1954. validators: {
  1955. callback: {
  1956. message: 'Wrong answer',
  1957. callback: function(value, validator, $field) {
  1958. return validateCaptcha(value, validator, $field);
  1959. }
  1960. }
  1961. }
  1962. }
  1963. }
  1964. });
  1965. this.bv = $('#callbackForm').data('bootstrapValidator');
  1966. this.$captcha = this.bv.getFieldElements('captcha');
  1967. this.$declarativeCaptcha = this.bv.getFieldElements('declarativeCaptcha');
  1968. });
  1969. afterEach(function() {
  1970. $('#callbackForm').bootstrapValidator('destroy').remove();
  1971. });
  1972. it('execute the callback', function() {
  1973. $('#captchaOperation').html('1 + 2');
  1974. this.$captcha.val('3');
  1975. this.bv.validate();
  1976. expect(this.bv.isValidField('captcha')).toBeTruthy();
  1977. this.bv.resetForm();
  1978. this.$captcha.val('5');
  1979. this.bv.validate();
  1980. expect(this.bv.isValidField('captcha')).toEqual(false);
  1981. });
  1982. it('callback declarative', function() {
  1983. $('#captchaOperation').html('10 + 20');
  1984. this.$declarativeCaptcha.val('40');
  1985. this.bv.validate();
  1986. expect(this.bv.isValidField('declarativeCaptcha')).toEqual(false);
  1987. this.bv.resetForm();
  1988. this.$declarativeCaptcha.val('30');
  1989. this.bv.validate();
  1990. expect(this.bv.isValidField('declarativeCaptcha')).toBeTruthy();
  1991. });
  1992. });
  1993. describe('color', function() {
  1994. beforeEach(function() {
  1995. $([
  1996. '<form class="form-horizontal" id="colorForm">',
  1997. '<div class="form-group">',
  1998. '<input type="text" class="form-control" name="color" />',
  1999. '</div>',
  2000. '<div class="form-group">',
  2001. '<input type="text" class="form-control" name="colorMultiple" />',
  2002. '</div>',
  2003. '<div class="form-group">',
  2004. '<input type="text" class="form-control" name="colorHex" />',
  2005. '</div>',
  2006. '<div class="form-group">',
  2007. '<input type="text" class="form-control" name="colorRgb" />',
  2008. '</div>',
  2009. '<div class="form-group">',
  2010. '<input type="text" class="form-control" name="colorRgba" />',
  2011. '</div>',
  2012. '<div class="form-group">',
  2013. '<input type="text" class="form-control" name="colorHsl" />',
  2014. '</div>',
  2015. '<div class="form-group">',
  2016. '<input type="text" class="form-control" name="colorHsla" />',
  2017. '</div>',
  2018. '<div class="form-group">',
  2019. '<input type="text" class="form-control" name="colorKeyword" />',
  2020. '</div>',
  2021. '</form>'
  2022. ].join('\n')).appendTo('body');
  2023. $('#colorForm').bootstrapValidator({
  2024. fields: {
  2025. color: {
  2026. validators: {
  2027. color: { }
  2028. }
  2029. },
  2030. colorMultiple: {
  2031. validators: {
  2032. color: {
  2033. type: [
  2034. 'hex',
  2035. 'rgb'
  2036. ]
  2037. }
  2038. }
  2039. },
  2040. colorHex: {
  2041. validators: {
  2042. color: {
  2043. type: ['hex']
  2044. }
  2045. }
  2046. },
  2047. colorRgb: {
  2048. validators: {
  2049. color: {
  2050. type: ['rgb']
  2051. }
  2052. }
  2053. },
  2054. colorRgba: {
  2055. validators: {
  2056. color: {
  2057. type: ['rgba']
  2058. }
  2059. }
  2060. },
  2061. colorHsl: {
  2062. validators: {
  2063. color: {
  2064. type: ['hsl']
  2065. }
  2066. }
  2067. },
  2068. colorHsla: {
  2069. validators: {
  2070. color: {
  2071. type: ['hsla']
  2072. }
  2073. }
  2074. },
  2075. colorKeyword: {
  2076. validators: {
  2077. color: {
  2078. type: ['keyword']
  2079. }
  2080. }
  2081. }
  2082. }
  2083. });
  2084. this.bv = $('#colorForm').data('bootstrapValidator');
  2085. this.$color = this.bv.getFieldElements('color');
  2086. this.$colorMultiple = this.bv.getFieldElements('colorMultiple');
  2087. this.$colorHex = this.bv.getFieldElements('colorHex');
  2088. this.$colorRgb = this.bv.getFieldElements('colorRgb');
  2089. this.$colorRgba = this.bv.getFieldElements('colorRgba');
  2090. this.$colorHsl = this.bv.getFieldElements('colorHsl');
  2091. this.$colorHsla = this.bv.getFieldElements('colorHsla');
  2092. this.$colorKeyword = this.bv.getFieldElements('colorKeyword');
  2093. });
  2094. afterEach(function() {
  2095. $('#colorForm').bootstrapValidator('destroy').remove();
  2096. });
  2097. // Start hsla() tests
  2098. it('Run hsla() test suite on hsla only field', function() {
  2099. this.$colorHsla.val('hsla(120,50%,50%,1)');
  2100. this.bv.validate();
  2101. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2102. this.bv.resetForm();
  2103. this.$colorHsla.val('hsla( 120 , 50% , 50%, 1 )');
  2104. this.bv.validate();
  2105. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2106. this.bv.resetForm();
  2107. this.$colorHsla.val('hsla( 120, 50%, 50% , 1 )');
  2108. this.bv.validate();
  2109. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2110. this.bv.resetForm();
  2111. this.$colorHsla.val('hsla(-120,50%,50%,1)');
  2112. this.bv.validate();
  2113. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2114. this.bv.resetForm();
  2115. this.$colorHsla.val('hsla(480,50%,50%,1)');
  2116. this.bv.validate();
  2117. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2118. this.bv.resetForm();
  2119. this.$colorHsla.val('hsla(120,50%,100%,0)');
  2120. this.bv.validate();
  2121. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2122. this.bv.resetForm();
  2123. this.$colorHsla.val('hsla(120,50%,100%,1)');
  2124. this.bv.validate();
  2125. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2126. this.bv.resetForm();
  2127. this.$colorHsla.val('hsla(120,50%,100%,0.5)');
  2128. this.bv.validate();
  2129. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2130. this.bv.resetForm();
  2131. this.$colorHsla.val('hsla(120,50%,100%,.5)');
  2132. this.bv.validate();
  2133. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2134. this.bv.resetForm();
  2135. this.$colorHsla.val('hsla(120,50%,100%,.524141)');
  2136. this.bv.validate();
  2137. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2138. this.bv.resetForm();
  2139. this.$colorHsla.val('hsla(120,50%,100%,50%)');
  2140. this.bv.validate();
  2141. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2142. this.bv.resetForm();
  2143. this.$colorHsla.val('hsla(120,50%,100%,2)');
  2144. this.bv.validate();
  2145. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2146. this.bv.resetForm();
  2147. this.$colorHsla.val('hsla(120,50%,100%,-1)');
  2148. this.bv.validate();
  2149. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2150. this.bv.resetForm();
  2151. this.$colorHsla.val('hsla(120,50%,100%,1.000000000001)');
  2152. this.bv.validate();
  2153. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2154. this.bv.resetForm();
  2155. this.$colorHsla.val('hsla(120,50%,100%,-0.5)');
  2156. this.bv.validate();
  2157. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2158. this.bv.resetForm();
  2159. this.$colorHsla.val('hsla(120,50%,100%,2.3)');
  2160. this.bv.validate();
  2161. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2162. this.bv.resetForm();
  2163. this.$colorHsla.val('hsla(10,-50%,50%,1)');
  2164. this.bv.validate();
  2165. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2166. this.bv.resetForm();
  2167. this.$colorHsla.val('hsla(10,50%,-50%,1)');
  2168. this.bv.validate();
  2169. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2170. this.bv.resetForm();
  2171. this.$colorHsla.val('120,50%,50%,1');
  2172. this.bv.validate();
  2173. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2174. this.bv.resetForm();
  2175. this.$colorHsla.val('hsla(120,100%,101%,1)');
  2176. this.bv.validate();
  2177. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2178. this.bv.resetForm();
  2179. this.$colorHsla.val('hsla (120,50%,50%,1)');
  2180. this.bv.validate();
  2181. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2182. this.bv.resetForm();
  2183. this.$colorHsla.val(' hsla(120,50%,50%,1)');
  2184. this.bv.validate();
  2185. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2186. this.bv.resetForm();
  2187. this.$colorHsla.val('hsla(120,50%,50%,1) ');
  2188. this.bv.validate();
  2189. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2190. this.bv.resetForm();
  2191. this.$colorHsla.val('hsla(50%, 50%, 100%,1)');
  2192. this.bv.validate();
  2193. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2194. this.bv.resetForm();
  2195. this.$colorHsla.val('hsla(120, 50, 100%,1)');
  2196. this.bv.validate();
  2197. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2198. this.bv.resetForm();
  2199. this.$colorHsla.val('hsla(120, 50%, 100,1)');
  2200. this.bv.validate();
  2201. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2202. });
  2203. // Start hsl() tests
  2204. it('Run hsl() test suite on hsl only field', function() {
  2205. this.$colorHsl.val('hsl(120,50%,50%)');
  2206. this.bv.validate();
  2207. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2208. this.bv.resetForm();
  2209. this.$colorHsl.val('hsl( 120 , 50% , 50% )');
  2210. this.bv.validate();
  2211. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2212. this.bv.resetForm();
  2213. this.$colorHsl.val('hsl( 120, 50%, 50% )');
  2214. this.bv.validate();
  2215. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2216. this.bv.resetForm();
  2217. this.$colorHsl.val('hsl(-120,50%,50%)');
  2218. this.bv.validate();
  2219. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2220. this.bv.resetForm();
  2221. this.$colorHsl.val('hsl(480,50%,50%)');
  2222. this.bv.validate();
  2223. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2224. this.bv.resetForm();
  2225. this.$colorHsl.val('hsl(10,-50%,50%)');
  2226. this.bv.validate();
  2227. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2228. this.bv.resetForm();
  2229. this.$colorHsl.val('hsl(10,50%,-50%)');
  2230. this.bv.validate();
  2231. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2232. this.bv.resetForm();
  2233. this.$colorHsl.val('120,50%,50%');
  2234. this.bv.validate();
  2235. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2236. this.bv.resetForm();
  2237. this.$colorHsl.val('hsl(120,100%,101%)');
  2238. this.bv.validate();
  2239. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2240. this.bv.resetForm();
  2241. this.$colorHsl.val('hsl (120,50%,50%)');
  2242. this.bv.validate();
  2243. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2244. this.bv.resetForm();
  2245. this.$colorHsl.val(' hsl(120,50%,50%)');
  2246. this.bv.validate();
  2247. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2248. this.bv.resetForm();
  2249. this.$colorHsl.val('hsl(120,50%,50%) ');
  2250. this.bv.validate();
  2251. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2252. this.bv.resetForm();
  2253. this.$colorHsl.val('hsl(50%, 50%, 100%)');
  2254. this.bv.validate();
  2255. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2256. this.bv.resetForm();
  2257. this.$colorHsl.val('hsl(120, 50, 100%)');
  2258. this.bv.validate();
  2259. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2260. this.bv.resetForm();
  2261. this.$colorHsl.val('hsl(120, 50%, 100)');
  2262. this.bv.validate();
  2263. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2264. });
  2265. // Start keyword test
  2266. it('Run keyword test suite on keyword only field', function() {
  2267. this.$colorKeyword.val('transparent');
  2268. this.bv.validate();
  2269. expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
  2270. this.bv.resetForm();
  2271. this.$colorKeyword.val('transparent');
  2272. this.bv.validate();
  2273. expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
  2274. this.bv.resetForm();
  2275. this.$colorKeyword.val('blueviolet red');
  2276. this.bv.validate();
  2277. expect(this.bv.isValidField('colorKeyword')).toEqual(false);
  2278. this.bv.resetForm();
  2279. this.$colorKeyword.val('shady');
  2280. this.bv.validate();
  2281. expect(this.bv.isValidField('colorKeyword')).toEqual(false);
  2282. this.bv.resetForm();
  2283. this.$colorKeyword.val('blueish');
  2284. this.bv.validate();
  2285. expect(this.bv.isValidField('colorKeyword')).toEqual(false);
  2286. });
  2287. // Start rgba() test
  2288. it('Run rgba() test suite on rgba only field', function() {
  2289. this.$colorRgba.val('rgba(255,255,255,1)');
  2290. this.bv.validate();
  2291. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2292. this.bv.resetForm();
  2293. this.$colorRgba.val('rgba( 255 , 255 , 255 , 1 )');
  2294. this.bv.validate();
  2295. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2296. this.bv.resetForm();
  2297. this.$colorRgba.val('rgba( 255 , 255 , 255 , 1 )');
  2298. this.bv.validate();
  2299. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2300. this.bv.resetForm();
  2301. this.$colorRgba.val('rgba(255,255,255,1)');
  2302. this.bv.validate();
  2303. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2304. this.bv.resetForm();
  2305. this.$colorRgba.val('rgba(100%,100%,100%,1)');
  2306. this.bv.validate();
  2307. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2308. this.bv.resetForm();
  2309. this.$colorRgba.val('rgba(255,255,255,0)');
  2310. this.bv.validate();
  2311. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2312. this.bv.resetForm();
  2313. this.$colorRgba.val('rgba(255,255,255,1)');
  2314. this.bv.validate();
  2315. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2316. this.bv.resetForm();
  2317. this.$colorRgba.val('rgba(255,255,255,0.5)');
  2318. this.bv.validate();
  2319. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2320. this.bv.resetForm();
  2321. this.$colorRgba.val('rgba(255,255,255,.5)');
  2322. this.bv.validate();
  2323. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2324. this.bv.resetForm();
  2325. this.$colorRgba.val('rgba(255,255,255,.524141)');
  2326. this.bv.validate();
  2327. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2328. this.bv.resetForm();
  2329. this.$colorRgba.val('rgba(100%,100%,100%,0)');
  2330. this.bv.validate();
  2331. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2332. this.bv.resetForm();
  2333. this.$colorRgba.val('rgba(100%,100%,100%,1)');
  2334. this.bv.validate();
  2335. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2336. this.bv.resetForm();
  2337. this.$colorRgba.val('rgba(100%,100%,100%,0.5)');
  2338. this.bv.validate();
  2339. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2340. this.bv.resetForm();
  2341. this.$colorRgba.val('rgba(100%,100%,100%,.5)');
  2342. this.bv.validate();
  2343. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2344. this.bv.resetForm();
  2345. this.$colorRgba.val('rgba(100%,100%,100%,.524141)');
  2346. this.bv.validate();
  2347. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2348. this.bv.resetForm();
  2349. this.$colorRgba.val('rgba(100%,100%,100%,50%)');
  2350. this.bv.validate();
  2351. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2352. this.bv.resetForm();
  2353. this.$colorRgba.val('rgba(255,255,255,2)');
  2354. this.bv.validate();
  2355. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2356. this.bv.resetForm();
  2357. this.$colorRgba.val('rgba(255,255,255,-1)');
  2358. this.bv.validate();
  2359. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2360. this.bv.resetForm();
  2361. this.$colorRgba.val('rgba(255,255,255,1.000000000001)');
  2362. this.bv.validate();
  2363. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2364. this.bv.resetForm();
  2365. this.$colorRgba.val('rgba(255,255,255,-0.5)');
  2366. this.bv.validate();
  2367. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2368. this.bv.resetForm();
  2369. this.$colorRgba.val('rgba(255,255,255,2.3)');
  2370. this.bv.validate();
  2371. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2372. this.bv.resetForm();
  2373. this.$colorRgba.val('rgba(255,255,100%,1)');
  2374. this.bv.validate();
  2375. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2376. this.bv.resetForm();
  2377. this.$colorRgba.val('rgba(-10,255,255,1)');
  2378. this.bv.validate();
  2379. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2380. this.bv.resetForm();
  2381. this.$colorRgba.val('rgba(-10%,100%,100%,1)');
  2382. this.bv.validate();
  2383. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2384. this.bv.resetForm();
  2385. this.$colorRgba.val('255,255,255,1');
  2386. this.bv.validate();
  2387. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2388. this.bv.resetForm();
  2389. this.$colorRgba.val('rgba(255,255,256),1');
  2390. this.bv.validate();
  2391. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2392. this.bv.resetForm();
  2393. this.$colorRgba.val('rgba(100%,100%,101%,1)');
  2394. this.bv.validate();
  2395. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2396. this.bv.resetForm();
  2397. this.$colorRgba.val('rgba (255,255,255,1)');
  2398. this.bv.validate();
  2399. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2400. this.bv.resetForm();
  2401. this.$colorRgba.val(' rgba(255,255,255,1)');
  2402. this.bv.validate();
  2403. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2404. this.bv.resetForm();
  2405. this.$colorRgba.val('rgba(255,255,255,1) ');
  2406. this.bv.validate();
  2407. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2408. });
  2409. // Start rgb() test
  2410. it('Run rgb() test suite on rgb only field', function() {
  2411. this.$colorRgb.val('rgb(255,255,255)');
  2412. this.bv.validate();
  2413. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2414. this.bv.resetForm();
  2415. this.$colorRgb.val('rgb( 255 , 255 , 255 )');
  2416. this.bv.validate();
  2417. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2418. this.bv.resetForm();
  2419. this.$colorRgb.val('rgb( 255, 255, 255 )');
  2420. this.bv.validate();
  2421. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2422. this.bv.resetForm();
  2423. this.$colorRgb.val('rgb(255,255,255)');
  2424. this.bv.validate();
  2425. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2426. this.bv.resetForm();
  2427. this.$colorRgb.val('rgb(100%,100%,100%)');
  2428. this.bv.validate();
  2429. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2430. this.bv.resetForm();
  2431. this.$colorRgb.val('rgb(255,255,100%)');
  2432. this.bv.validate();
  2433. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2434. this.bv.resetForm();
  2435. this.$colorRgb.val('rgb(-10,255,255)');
  2436. this.bv.validate();
  2437. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2438. this.bv.resetForm();
  2439. this.$colorRgb.val('rgb(-10%,100%,100%)');
  2440. this.bv.validate();
  2441. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2442. this.bv.resetForm();
  2443. this.$colorRgb.val('255,255,255');
  2444. this.bv.validate();
  2445. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2446. this.bv.resetForm();
  2447. this.$colorRgb.val('rgb(255,255,256)');
  2448. this.bv.validate();
  2449. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2450. this.bv.resetForm();
  2451. this.$colorRgb.val('rgb(100%,100%,101%)');
  2452. this.bv.validate();
  2453. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2454. this.bv.resetForm();
  2455. this.$colorRgb.val('rgb (255,255,255)');
  2456. this.bv.validate();
  2457. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2458. this.bv.resetForm();
  2459. this.$colorRgb.val(' rgb(255,255,255)');
  2460. this.bv.validate();
  2461. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2462. this.bv.resetForm();
  2463. this.$colorRgb.val('rgb(255,255,255) ');
  2464. this.bv.validate();
  2465. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2466. });
  2467. /* Run individual tests */
  2468. it('Individual field keyword: accept keyword', function() {
  2469. this.$colorKeyword.val('blue');
  2470. this.bv.validate();
  2471. expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
  2472. });
  2473. it('Individual field keyword: reject rgb', function() {
  2474. this.$colorKeyword.val('rgb(255,255,255)');
  2475. this.bv.validate();
  2476. expect(this.bv.isValidField('colorKeyword')).toEqual(false);
  2477. });
  2478. it('Individual field hex: accept 6 char hex', function() {
  2479. this.$colorHex.val('#0000FF');
  2480. this.bv.validate();
  2481. expect(this.bv.isValidField('colorHex')).toBeTruthy();
  2482. });
  2483. it('Individual field hex: accept 3 char hex', function() {
  2484. this.$colorHex.val('#00F');
  2485. this.bv.validate();
  2486. expect(this.bv.isValidField('colorHex')).toBeTruthy();
  2487. });
  2488. it('Individual field hex: reject keyword', function() {
  2489. this.$colorHex.val('blue');
  2490. this.bv.validate();
  2491. expect(this.bv.isValidField('colorHex')).toEqual(false);
  2492. });
  2493. it('Individual field rgb(): accept rgb()', function() {
  2494. this.$colorRgb.val('rgb(255,255,255)');
  2495. this.bv.validate();
  2496. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2497. });
  2498. it('Individual field rgb(): reject hex', function() {
  2499. this.$colorRgb.val('#0000FF');
  2500. this.bv.validate();
  2501. expect(this.bv.isValidField('colorRgb')).toEqual(false);
  2502. });
  2503. it('Individual field rgba(): accept rgba()', function() {
  2504. this.$colorRgba.val('rgba(255,255,255,1)');
  2505. this.bv.validate();
  2506. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2507. });
  2508. it('Individual field rgba(): reject rgb()', function() {
  2509. this.$colorRgba.val('rgb(255,255,255)');
  2510. this.bv.validate();
  2511. expect(this.bv.isValidField('colorRgba')).toEqual(false);
  2512. });
  2513. it('Individual field hsl(): accept hsl()', function() {
  2514. this.$colorHsl.val('hsl(120,50%,50%)');
  2515. this.bv.validate();
  2516. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2517. });
  2518. it('Individual field hsl(): reject rgba()', function() {
  2519. this.$colorHsl.val('rgba(255,255,255,1)');
  2520. this.bv.validate();
  2521. expect(this.bv.isValidField('colorHsl')).toEqual(false);
  2522. });
  2523. it('Individual field hsla(): accept hsla()', function() {
  2524. this.$colorHsla.val('hsla(120,50%,50%,1)');
  2525. this.bv.validate();
  2526. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2527. });
  2528. it('Individual field hsla(): reject hsl()', function() {
  2529. this.$colorHsla.val('hsl(120,50%,50%)');
  2530. this.bv.validate();
  2531. expect(this.bv.isValidField('colorHsla')).toEqual(false);
  2532. });
  2533. /* Run validation message tests */
  2534. it('Validation message tests', function() {
  2535. this.$color.val('notacolor');
  2536. this.bv.validate();
  2537. expect(this.bv.isValidField('color')).toEqual(false);
  2538. expect(this.bv.getMessages(this.$color, 'color')[0]).toEqual($.fn.bootstrapValidator.i18n.color.default);
  2539. });
  2540. });
  2541. describe('creditCard', function() {
  2542. // Get the fake credit card number at http://www.getcreditcardnumbers.com/
  2543. beforeEach(function() {
  2544. var html = [
  2545. '<div class="container">',
  2546. '<form class="form-horizontal" id="ccForm">',
  2547. '<div class="form-group">',
  2548. '<input type="text" name="cc" data-bv-creditcard />',
  2549. '</div>',
  2550. '</form>',
  2551. '</div>'
  2552. ].join('\n');
  2553. $(html).appendTo('body');
  2554. $('#ccForm').bootstrapValidator();
  2555. this.bv = $('#ccForm').data('bootstrapValidator');
  2556. this.$creditCard = this.bv.getFieldElements('cc');
  2557. });
  2558. afterEach(function() {
  2559. $('#ccForm').bootstrapValidator('destroy').parent().remove();
  2560. });
  2561. it('accept spaces', function() {
  2562. this.$creditCard.val('5267 9789 9451 9654');
  2563. this.bv.validate();
  2564. expect(this.bv.isValidField('cc')).toBeTruthy();
  2565. });
  2566. it('accept dashes', function() {
  2567. this.$creditCard.val('6011-2649-6840-4521');
  2568. this.bv.validate();
  2569. expect(this.bv.isValidField('cc')).toBeTruthy();
  2570. });
  2571. it('invalid format', function() {
  2572. this.$creditCard.val('4539.1870.2954.3862');
  2573. this.bv.validate();
  2574. expect(this.bv.isValidField('cc')).toEqual(false);
  2575. });
  2576. it('American Express', function() {
  2577. this.$creditCard.val('340653705597107');
  2578. this.bv.validate();
  2579. expect(this.bv.isValidField('cc')).toBeTruthy();
  2580. });
  2581. it('American Express invalid length', function() {
  2582. this.$creditCard.val('3744148309166730');
  2583. this.bv.validate();
  2584. expect(this.bv.isValidField('cc')).toEqual(false);
  2585. });
  2586. it('American Express invalid prefix', function() {
  2587. this.$creditCard.val('356120148436654');
  2588. this.bv.validate();
  2589. expect(this.bv.isValidField('cc')).toEqual(false);
  2590. });
  2591. it('Diners Club', function() {
  2592. this.$creditCard.val('30130708434187');
  2593. this.bv.validate();
  2594. expect(this.bv.isValidField('cc')).toBeTruthy();
  2595. });
  2596. it('Diners Club (US)', function() {
  2597. this.$creditCard.val('5517479515603901');
  2598. this.bv.validate();
  2599. expect(this.bv.isValidField('cc')).toBeTruthy();
  2600. });
  2601. it('Discover', function() {
  2602. this.$creditCard.val('6011734674929094');
  2603. this.bv.validate();
  2604. expect(this.bv.isValidField('cc')).toBeTruthy();
  2605. });
  2606. it('JCB', function() {
  2607. this.$creditCard.val('3566002020360505');
  2608. this.bv.validate();
  2609. expect(this.bv.isValidField('cc')).toBeTruthy();
  2610. });
  2611. it('Laser', function() {
  2612. this.$creditCard.val('6304 9000 1774 0292 441');
  2613. this.bv.validate();
  2614. expect(this.bv.isValidField('cc')).toBeTruthy();
  2615. });
  2616. it('Maestro', function() {
  2617. this.$creditCard.val('6762835098779303');
  2618. this.bv.validate();
  2619. expect(this.bv.isValidField('cc')).toBeTruthy();
  2620. });
  2621. it('Mastercard', function() {
  2622. this.$creditCard.val('5303765013600904');
  2623. this.bv.validate();
  2624. expect(this.bv.isValidField('cc')).toBeTruthy();
  2625. });
  2626. it('Solo', function() {
  2627. this.$creditCard.val('6334580500000000');
  2628. this.bv.validate();
  2629. expect(this.bv.isValidField('cc')).toBeTruthy();
  2630. });
  2631. it('Visa', function() {
  2632. this.$creditCard.val('4929248980295542');
  2633. this.bv.validate();
  2634. expect(this.bv.isValidField('cc')).toBeTruthy();
  2635. });
  2636. it('Visa invalid check digit', function() {
  2637. this.$creditCard.val('4532599916257826');
  2638. this.bv.validate();
  2639. expect(this.bv.isValidField('cc')).toEqual(false);
  2640. });
  2641. });
  2642. function getDate(value, validator, $field) {
  2643. return validator.getFieldElements('date').val();
  2644. };
  2645. TestSuite = $.extend({}, TestSuite, {
  2646. Date: {
  2647. getDate: function(value, validator, $field) {
  2648. return validator.getFieldElements('date').val();
  2649. }
  2650. }
  2651. });
  2652. describe('date', function() {
  2653. beforeEach(function() {
  2654. $([
  2655. '<form class="form-horizontal" id="dateForm">',
  2656. '<div id="msg"></div>',
  2657. '<div class="form-group">',
  2658. '<input type="text" name="date" data-bv-date />',
  2659. '</div>',
  2660. '<div class="form-group">',
  2661. '<input type="text" name="minDate" data-bv-date data-bv-date-min="" />',
  2662. '</div>',
  2663. '<div class="form-group">',
  2664. '<input type="text" name="maxDate" data-bv-date data-bv-date-max="" />',
  2665. '</div>',
  2666. '<div class="form-group">',
  2667. '<input type="text" name="range" data-bv-date data-bv-date-min="" data-bv-date-max="" />',
  2668. '</div>',
  2669. '</form>'
  2670. ].join('\n')).appendTo('body');
  2671. $('#dateForm').bootstrapValidator();
  2672. this.bv = $('#dateForm').data('bootstrapValidator');
  2673. this.$date = this.bv.getFieldElements('date');
  2674. this.$minDate = this.bv.getFieldElements('minDate');
  2675. this.$maxDate = this.bv.getFieldElements('maxDate');
  2676. this.$range = this.bv.getFieldElements('range');
  2677. });
  2678. afterEach(function() {
  2679. $('#dateForm').bootstrapValidator('destroy').remove();
  2680. });
  2681. it('YYYY/MM/DD', function() {
  2682. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
  2683. this.$date.val('2000/01/30');
  2684. this.bv.validate();
  2685. expect(this.bv.isValid()).toBeTruthy();
  2686. // Invalid year
  2687. this.bv.resetForm();
  2688. this.$date.val('100/10/20');
  2689. this.bv.validate();
  2690. expect(this.bv.isValid()).toEqual(false);
  2691. // Invalid month
  2692. this.bv.resetForm();
  2693. this.$date.val('2000/00/10');
  2694. this.bv.validate();
  2695. expect(this.bv.isValid()).toEqual(false);
  2696. this.bv.resetForm();
  2697. this.$date.val('2000/15/10');
  2698. this.bv.validate();
  2699. expect(this.bv.isValid()).toEqual(false);
  2700. // Invalid day
  2701. this.bv.resetForm();
  2702. this.$date.val('2000/03/00');
  2703. this.bv.validate();
  2704. expect(this.bv.isValid()).toEqual(false);
  2705. this.bv.resetForm();
  2706. this.$date.val('2000/10/32');
  2707. this.bv.validate();
  2708. expect(this.bv.isValid()).toEqual(false);
  2709. // Negative number
  2710. this.bv.resetForm();
  2711. this.$date.val('-2000/10/20');
  2712. this.bv.validate();
  2713. expect(this.bv.isValid()).toEqual(false);
  2714. this.bv.resetForm();
  2715. this.$date.val('2000/-10/20');
  2716. this.bv.validate();
  2717. expect(this.bv.isValid()).toEqual(false);
  2718. this.bv.resetForm();
  2719. this.$date.val('2000/10/-20');
  2720. this.bv.validate();
  2721. expect(this.bv.isValid()).toEqual(false);
  2722. // Consist invalid characters
  2723. // Issue #310
  2724. this.bv.resetForm();
  2725. this.$date.val('aaaa/');
  2726. this.bv.validate();
  2727. expect(this.bv.isValid()).toEqual(false);
  2728. this.bv.resetForm();
  2729. this.$date.val('2004df/1dd1/5ffg');
  2730. this.bv.validate();
  2731. expect(this.bv.isValid()).toEqual(false);
  2732. // Issue #475
  2733. this.bv.resetForm();
  2734. this.$date.val('2014/09');
  2735. this.bv.validate();
  2736. expect(this.bv.isValid()).toEqual(false);
  2737. this.bv.resetForm();
  2738. this.$date.val('2014/09/');
  2739. this.bv.validate();
  2740. expect(this.bv.isValid()).toEqual(false);
  2741. this.bv.resetForm();
  2742. this.$date.val('2014//15');
  2743. this.bv.validate();
  2744. expect(this.bv.isValid()).toEqual(false);
  2745. this.bv.resetForm();
  2746. this.$date.val('/09/15');
  2747. this.bv.validate();
  2748. expect(this.bv.isValid()).toEqual(false);
  2749. });
  2750. it('MM/DD/YYYY', function() {
  2751. this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
  2752. this.$date.val('09/15/2020');
  2753. this.bv.validate();
  2754. expect(this.bv.isValid()).toBeTruthy();
  2755. this.bv.resetForm();
  2756. this.$date.val('09/15');
  2757. this.bv.validate();
  2758. expect(this.bv.isValid()).toEqual(false);
  2759. this.bv.resetForm();
  2760. this.$date.val('09/15/');
  2761. this.bv.validate();
  2762. expect(this.bv.isValid()).toEqual(false);
  2763. });
  2764. it('number of days in February', function() {
  2765. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
  2766. this.$date.val('2000/02/28');
  2767. this.bv.validate();
  2768. expect(this.bv.isValid()).toBeTruthy();
  2769. this.bv.resetForm();
  2770. this.$date.val('2000/02/29');
  2771. this.bv.validate();
  2772. expect(this.bv.isValid()).toBeTruthy();
  2773. this.bv.resetForm();
  2774. this.$date.val('2001/02/29');
  2775. this.bv.validate();
  2776. expect(this.bv.isValid()).toEqual(false);
  2777. });
  2778. // Issue #681
  2779. it('date, month, year are prefixed by zero', function() {
  2780. this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
  2781. this.$date.val('0012/08/2014');
  2782. this.bv.validate();
  2783. expect(this.bv.isValid()).toEqual(false);
  2784. this.bv.resetForm();
  2785. this.$date.val('12/0008/2014');
  2786. this.bv.validate();
  2787. expect(this.bv.isValid()).toEqual(false);
  2788. this.bv.resetForm();
  2789. this.$date.val('12/08/002014');
  2790. this.bv.validate();
  2791. expect(this.bv.isValid()).toEqual(false);
  2792. this.bv.resetForm();
  2793. this.$date.val('12/08/2014');
  2794. this.bv.validate();
  2795. expect(this.bv.isValid()).toBeTruthy();
  2796. });
  2797. it('hours, minutes, seconds are prefixed by zero', function() {
  2798. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD h:m:s');
  2799. this.$date.val('2014/08/17 0007:30:00');
  2800. this.bv.validate();
  2801. expect(this.bv.isValid()).toEqual(false);
  2802. this.bv.resetForm();
  2803. this.$date.val('2014/08/17 07:030:00');
  2804. this.bv.validate();
  2805. expect(this.bv.isValid()).toEqual(false);
  2806. this.bv.resetForm();
  2807. this.$date.val('2014/08/17 07:30:0000');
  2808. this.bv.validate();
  2809. expect(this.bv.isValid()).toEqual(false);
  2810. this.bv.resetForm();
  2811. this.$date.val('2014/08/17 07:30:00');
  2812. this.bv.validate();
  2813. expect(this.bv.isValid()).toBeTruthy();
  2814. });
  2815. // min test suite
  2816. it('min date format YYYY/MM/DD', function() {
  2817. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  2818. this.bv.updateOption('minDate', 'date', 'min', '2010/01/01');
  2819. this.$minDate.val('2010/01/02');
  2820. this.bv.validate();
  2821. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2822. this.bv.resetForm();
  2823. this.$minDate.val('2010/01/002'); // day prefexid by 0 not allowed
  2824. this.bv.validate();
  2825. expect(this.bv.isValidField('minDate')).toEqual(false);
  2826. this.bv.resetForm();
  2827. this.$minDate.val('2014/08/17');
  2828. this.bv.validate();
  2829. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2830. this.bv.resetForm();
  2831. this.$minDate.val('2009/12/31');
  2832. this.bv.validate();
  2833. expect(this.bv.isValidField('minDate')).toEqual(false);
  2834. this.bv.resetForm();
  2835. this.$minDate.val('2000/01/01');
  2836. this.bv.validate();
  2837. expect(this.bv.isValidField('minDate')).toEqual(false);
  2838. });
  2839. it('min date format YYYY-MM-DD', function() {
  2840. this.bv.updateOption('minDate', 'date', 'format', 'YYYY-MM-DD');
  2841. this.bv.updateOption('minDate', 'date', 'min', '2010-01-01');
  2842. this.$minDate.val('2010-01-02');
  2843. this.bv.validate();
  2844. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2845. this.bv.resetForm();
  2846. this.$minDate.val('2010-001-02'); // month prefexid by 0 not allowed
  2847. this.bv.validate();
  2848. expect(this.bv.isValidField('minDate')).toEqual(false);
  2849. this.bv.resetForm();
  2850. this.$minDate.val('2014-08-17');
  2851. this.bv.validate();
  2852. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2853. this.bv.resetForm();
  2854. this.$minDate.val('2009-12-31');
  2855. this.bv.validate();
  2856. expect(this.bv.isValidField('minDate')).toEqual(false);
  2857. this.bv.resetForm();
  2858. this.$minDate.val('2000-01-01');
  2859. this.bv.validate();
  2860. expect(this.bv.isValidField('minDate')).toEqual(false);
  2861. });
  2862. it('min date format DD/MM/YYYY', function() {
  2863. this.bv.updateOption('minDate', 'date', 'format', 'DD/MM/YYYY');
  2864. this.bv.updateOption('minDate', 'date', 'min', '01/01/2010');
  2865. this.$minDate.val('02/01/2010');
  2866. this.bv.validate();
  2867. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2868. this.bv.resetForm();
  2869. this.$minDate.val('17/08/2014');
  2870. this.bv.validate();
  2871. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2872. this.bv.resetForm();
  2873. this.$minDate.val('02/01/02010'); // year prefixed by 0 not allowed
  2874. this.bv.validate();
  2875. expect(this.bv.isValidField('minDate')).toEqual(false);
  2876. this.bv.resetForm();
  2877. this.$minDate.val('31/12/2009');
  2878. this.bv.validate();
  2879. expect(this.bv.isValidField('minDate')).toEqual(false);
  2880. this.bv.resetForm();
  2881. this.$minDate.val('01/01/2000');
  2882. this.bv.validate();
  2883. expect(this.bv.isValidField('minDate')).toEqual(false);
  2884. });
  2885. it('min date format YYYY-MM-DD h:m:s', function() {
  2886. this.bv.updateOption('minDate', 'date', 'format', 'YYYY-MM-DD h:m:s');
  2887. this.bv.updateOption('minDate', 'date', 'min', '2010-01-01 01:00:00');
  2888. this.bv.resetForm();
  2889. this.$minDate.val('2010-01-01 01:00:01');
  2890. this.bv.validate();
  2891. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2892. this.$minDate.val('2010-01-02 01:00:01');
  2893. this.bv.validate();
  2894. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2895. this.bv.resetForm();
  2896. this.$minDate.val('2014-08-17 12:00:00');
  2897. this.bv.validate();
  2898. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2899. this.bv.resetForm();
  2900. this.$minDate.val('2009-12-31 00:00:00');
  2901. this.bv.validate();
  2902. expect(this.bv.isValidField('minDate')).toEqual(false);
  2903. this.bv.resetForm();
  2904. this.$minDate.val('2009-12-31 010:00:00'); // hours prefixed by 0 not allowed
  2905. this.bv.validate();
  2906. expect(this.bv.isValidField('minDate')).toEqual(false);
  2907. this.bv.resetForm();
  2908. this.$minDate.val('2009-12-31 10:001:00'); // minutes prefixed by 0 not allowed
  2909. this.bv.validate();
  2910. expect(this.bv.isValidField('minDate')).toEqual(false);
  2911. this.bv.resetForm();
  2912. this.$minDate.val('2009-12-31 10:01:012'); // seconds prefixed by 0 not allowed
  2913. this.bv.validate();
  2914. expect(this.bv.isValidField('minDate')).toEqual(false);
  2915. this.bv.resetForm();
  2916. this.$minDate.val('2009-12-31 00:00:00');
  2917. this.bv.validate();
  2918. expect(this.bv.isValidField('minDate')).toEqual(false);
  2919. this.bv.resetForm();
  2920. this.$minDate.val('2000-01-01 23:00:12');
  2921. this.bv.validate();
  2922. expect(this.bv.isValidField('minDate')).toEqual(false);
  2923. });
  2924. // max test suite
  2925. it('max date format YYYY/MM/DD', function() {
  2926. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  2927. this.bv.updateOption('maxDate', 'date', 'max', '2014/09/10');
  2928. this.$maxDate.val('2014/09/09');
  2929. this.bv.validate();
  2930. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2931. this.bv.resetForm();
  2932. this.$maxDate.val('2014/08/17');
  2933. this.bv.validate();
  2934. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2935. this.bv.resetForm();
  2936. this.$maxDate.val('02014/012/031'); // year, month or day prefixed by 0 not allowed
  2937. this.bv.validate();
  2938. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2939. this.bv.resetForm();
  2940. this.$maxDate.val('2014/12/31');
  2941. this.bv.validate();
  2942. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2943. this.bv.resetForm();
  2944. this.$maxDate.val('2015/01/01');
  2945. this.bv.validate();
  2946. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2947. });
  2948. it('max date format YYYY-MM-DD', function() {
  2949. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY-MM-DD');
  2950. this.bv.updateOption('maxDate', 'date', 'max', '2014-09-10');
  2951. this.$maxDate.val('2014-09-09');
  2952. this.bv.validate();
  2953. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2954. this.bv.resetForm();
  2955. this.$maxDate.val('2014-08-17');
  2956. this.bv.validate();
  2957. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2958. this.bv.resetForm();
  2959. this.$maxDate.val('02014-012-031'); // year, month or day prefixed by 0 not allowed
  2960. this.bv.validate();
  2961. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2962. this.bv.resetForm();
  2963. this.$maxDate.val('2014-12-31');
  2964. this.bv.validate();
  2965. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2966. this.bv.resetForm();
  2967. this.$maxDate.val('2015-01-01');
  2968. this.bv.validate();
  2969. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2970. });
  2971. it('max date format DD/MM/YYYY', function() {
  2972. this.bv.updateOption('maxDate', 'date', 'format', 'DD/MM/YYYY');
  2973. this.bv.updateOption('maxDate', 'date', 'max', '10/09/2014');
  2974. this.$maxDate.val('09/09/2014');
  2975. this.bv.validate();
  2976. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2977. this.bv.resetForm();
  2978. this.$maxDate.val('17/08/2014');
  2979. this.bv.validate();
  2980. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2981. this.bv.resetForm();
  2982. this.$maxDate.val('031/012/02014'); // year, month or day prefixed by 0 not allowed
  2983. this.bv.validate();
  2984. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2985. this.bv.resetForm();
  2986. this.$maxDate.val('31/12/2014');
  2987. this.bv.validate();
  2988. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2989. this.bv.resetForm();
  2990. this.$maxDate.val('01/01/2015');
  2991. this.bv.validate();
  2992. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2993. });
  2994. it('max date format YYYY-MM-DD h:m:s', function() {
  2995. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY-MM-DD h:m:s');
  2996. this.bv.updateOption('maxDate', 'date', 'max', '2014-09-10 01:00:00');
  2997. this.$maxDate.val('2014-09-09 01:00:01');
  2998. this.bv.validate();
  2999. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3000. this.bv.resetForm();
  3001. this.$maxDate.val('2014-08-17 12:00:00');
  3002. this.bv.validate();
  3003. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3004. this.bv.resetForm();
  3005. this.$maxDate.val('2014-09-09 001:001:001'); // hours, minutes or seconds prefixed by 0 not allowed
  3006. this.bv.validate();
  3007. expect(this.bv.isValidField('maxDate')).toEqual(false);
  3008. this.bv.resetForm();
  3009. this.$maxDate.val('2014-12-31 00:00:00');
  3010. this.bv.validate();
  3011. expect(this.bv.isValidField('maxDate')).toEqual(false);
  3012. this.bv.resetForm();
  3013. this.$maxDate.val('2015-01-01 23:00:12');
  3014. this.bv.validate();
  3015. expect(this.bv.isValidField('maxDate')).toEqual(false);
  3016. });
  3017. // range test suite
  3018. it('range format YYYY/MM/DD', function() {
  3019. this.bv.updateOption('range', 'date', 'format', 'YYYY/MM/DD');
  3020. this.bv.updateOption('range', 'date', 'min', '2010/09/10');
  3021. this.bv.updateOption('range', 'date', 'max', '2014/09/10');
  3022. this.$range.val('2011/01/01');
  3023. this.bv.validate();
  3024. expect(this.bv.isValidField('range')).toBeTruthy();
  3025. this.bv.resetForm();
  3026. this.$range.val('2014/09/09');
  3027. this.bv.validate();
  3028. expect(this.bv.isValidField('range')).toBeTruthy();
  3029. this.bv.resetForm();
  3030. this.$range.val('02014/001/031'); // year, month or day prefixed by 0 not allowed
  3031. this.bv.validate();
  3032. expect(this.bv.isValidField('range')).toEqual(false);
  3033. this.bv.resetForm();
  3034. this.$range.val('2010/09/09');
  3035. this.bv.validate();
  3036. expect(this.bv.isValidField('range')).toEqual(false);
  3037. this.bv.resetForm();
  3038. this.$range.val('2014/09/11');
  3039. this.bv.validate();
  3040. expect(this.bv.isValidField('range')).toEqual(false);
  3041. });
  3042. it('range format YYYY-MM-DD', function() {
  3043. this.bv.updateOption('range', 'date', 'format', 'YYYY-MM-DD');
  3044. this.bv.updateOption('range', 'date', 'min', '2010-09-10');
  3045. this.bv.updateOption('range', 'date', 'max', '2014-09-10');
  3046. this.$range.val('2012-01-12');
  3047. this.bv.validate();
  3048. expect(this.bv.isValidField('range')).toBeTruthy();
  3049. this.bv.resetForm();
  3050. this.$range.val('2014-09-09');
  3051. this.bv.validate();
  3052. expect(this.bv.isValidField('range')).toBeTruthy();
  3053. this.bv.resetForm();
  3054. this.$range.val('02014-003-031'); // year, month or day prefixed by 0 not allowed
  3055. this.bv.validate();
  3056. expect(this.bv.isValidField('range')).toEqual(false);
  3057. this.bv.resetForm();
  3058. this.$range.val('2009-12-31');
  3059. this.bv.validate();
  3060. expect(this.bv.isValidField('range')).toEqual(false);
  3061. this.bv.resetForm();
  3062. this.$range.val('2015-01-01');
  3063. this.bv.validate();
  3064. expect(this.bv.isValidField('range')).toEqual(false);
  3065. });
  3066. it('range format DD/MM/YYYY', function() {
  3067. this.bv.updateOption('range', 'date', 'format', 'DD/MM/YYYY');
  3068. this.bv.updateOption('range', 'date', 'min', '10/09/2010');
  3069. this.bv.updateOption('range', 'date', 'max', '10/09/2014');
  3070. this.$range.val('11/11/2011');
  3071. this.bv.validate();
  3072. expect(this.bv.isValidField('range')).toBeTruthy();
  3073. this.bv.resetForm();
  3074. this.$range.val('17/08/2014');
  3075. this.bv.validate();
  3076. expect(this.bv.isValidField('range')).toBeTruthy();
  3077. this.bv.resetForm();
  3078. this.$range.val('031/012/02013'); // year, month or day prefixed by 0 not allowed
  3079. this.bv.validate();
  3080. expect(this.bv.isValidField('range')).toEqual(false);
  3081. this.bv.resetForm();
  3082. this.$range.val('31/01/2010');
  3083. this.bv.validate();
  3084. expect(this.bv.isValidField('range')).toEqual(false);
  3085. this.bv.resetForm();
  3086. this.$range.val('25/03/2015');
  3087. this.bv.validate();
  3088. expect(this.bv.isValidField('range')).toEqual(false);
  3089. });
  3090. it('range format YYYY-MM-DD h:m:s', function() {
  3091. this.bv.updateOption('range', 'date', 'format', 'YYYY-MM-DD h:m:s');
  3092. this.bv.updateOption('range', 'date', 'min', '2010-05-15 22:00:00');
  3093. this.bv.updateOption('range', 'date', 'max', '2015-05-15 22:00:00');
  3094. this.$range.val('2012-07-17 01:00:01');
  3095. this.bv.validate();
  3096. expect(this.bv.isValidField('range')).toBeTruthy();
  3097. this.bv.resetForm();
  3098. this.$range.val('2013-08-17 12:00:00');
  3099. this.bv.validate();
  3100. expect(this.bv.isValidField('range')).toBeTruthy();
  3101. this.bv.resetForm();
  3102. this.$range.val('2011-06-19 001:001:001'); // hours, minutes or seconds prefixed by 0 not allowed
  3103. this.bv.validate();
  3104. expect(this.bv.isValidField('range')).toEqual(false);
  3105. this.bv.resetForm();
  3106. this.$range.val('2008-11-27 23:15:00');
  3107. this.bv.validate();
  3108. expect(this.bv.isValidField('range')).toEqual(false);
  3109. this.bv.resetForm();
  3110. this.$range.val('2015-05-15 22:00:01');
  3111. this.bv.validate();
  3112. expect(this.bv.isValidField('range')).toEqual(false);
  3113. });
  3114. // dynamic min option
  3115. it('dynamic min: name of field', function() {
  3116. this.$minDate.attr('data-bv-date-min', 'date');
  3117. this.bv.destroy();
  3118. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3119. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3120. this.$date.val('2014/09/08');
  3121. this.$minDate.val('2014/09/09');
  3122. this.bv.validate();
  3123. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3124. this.bv.resetForm();
  3125. this.$date.val('2014/09/08');
  3126. this.$minDate.val('2014/08/17');
  3127. this.bv.validate();
  3128. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3129. });
  3130. it('dynamic min: callback declarative function', function() {
  3131. this.$minDate.attr('data-bv-date-min', 'getDate');
  3132. this.bv.destroy();
  3133. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3134. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3135. this.$date.val('2014/09/08');
  3136. this.$minDate.val('2014/09/09');
  3137. this.bv.validate();
  3138. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3139. this.bv.resetForm();
  3140. this.$date.val('2014/10/01');
  3141. this.$minDate.val('2014/08/17');
  3142. this.bv.validate();
  3143. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3144. });
  3145. it('dynamic min: callback declarative function()', function() {
  3146. this.$minDate.attr('data-bv-date-min', 'getDate()');
  3147. this.bv.destroy();
  3148. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3149. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3150. this.$date.val('2014/09/08');
  3151. this.$minDate.val('2014/09/09');
  3152. this.bv.validate();
  3153. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3154. this.bv.resetForm();
  3155. this.$date.val('2014/10/01');
  3156. this.$minDate.val('2014/08/17');
  3157. this.bv.validate();
  3158. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3159. });
  3160. it('dynamic min: callback declarative A.B.C', function() {
  3161. this.$minDate.attr('data-bv-date-min', 'TestSuite.Date.getDate');
  3162. this.bv.destroy();
  3163. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3164. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3165. this.$date.val('2014/09/08');
  3166. this.$minDate.val('2014/09/09');
  3167. this.bv.validate();
  3168. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3169. this.bv.resetForm();
  3170. this.$date.val('2014/10/01');
  3171. this.$minDate.val('2014/08/17');
  3172. this.bv.validate();
  3173. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3174. });
  3175. it('dynamic min: callback declarative A.B.C()', function() {
  3176. this.$minDate.attr('data-bv-date-min', 'TestSuite.Date.getDate()');
  3177. this.bv.destroy();
  3178. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3179. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3180. this.$date.val('2014/09/08');
  3181. this.$minDate.val('2014/09/09');
  3182. this.bv.validate();
  3183. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3184. this.bv.resetForm();
  3185. this.$date.val('2014/10/01');
  3186. this.$minDate.val('2014/08/17');
  3187. this.bv.validate();
  3188. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3189. });
  3190. it('dynamic min: callback programmatically', function() {
  3191. this.$minDate.removeAttr('data-bv-date-min');
  3192. this.bv.destroy();
  3193. this.bv = $('#dateForm')
  3194. .bootstrapValidator({
  3195. fields: {
  3196. minDate: {
  3197. validators: {
  3198. date: {
  3199. min: function(value, validator, $field) {
  3200. return getDate(value, validator, $field);
  3201. }
  3202. }
  3203. }
  3204. }
  3205. }
  3206. })
  3207. .data('bootstrapValidator');
  3208. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3209. this.$date.val('2014/09/08');
  3210. this.$minDate.val('2014/09/09');
  3211. this.bv.validate();
  3212. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3213. this.bv.resetForm();
  3214. this.$date.val('2014/10/01');
  3215. this.$minDate.val('2014/08/17');
  3216. this.bv.validate();
  3217. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3218. });
  3219. // dynamic max option
  3220. it('dynamic max: name of field', function() {
  3221. this.$maxDate.attr('data-bv-date-max', 'date');
  3222. this.bv.destroy();
  3223. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3224. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3225. this.$date.val('2015/01/01');
  3226. this.$maxDate.val('2014/09/09');
  3227. this.bv.validate();
  3228. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3229. this.bv.resetForm();
  3230. this.$date.val('2014/01/01');
  3231. this.$maxDate.val('2014/08/17');
  3232. this.bv.validate();
  3233. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3234. });
  3235. it('dynamic max: callback declarative function', function() {
  3236. this.$maxDate.attr('data-bv-date-max', 'getDate');
  3237. this.bv.destroy();
  3238. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3239. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3240. this.$date.val('2015/01/01');
  3241. this.$maxDate.val('2014/09/09');
  3242. this.bv.validate();
  3243. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3244. this.bv.resetForm();
  3245. this.$date.val('2014/01/01');
  3246. this.$maxDate.val('2014/08/17');
  3247. this.bv.validate();
  3248. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3249. });
  3250. it('dynamic max: callback declarative function()', function() {
  3251. this.$maxDate.attr('data-bv-date-max', 'getDate()');
  3252. this.bv.destroy();
  3253. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3254. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3255. this.$date.val('2015/01/01');
  3256. this.$maxDate.val('2014/09/09');
  3257. this.bv.validate();
  3258. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3259. this.bv.resetForm();
  3260. this.$date.val('2014/01/01');
  3261. this.$maxDate.val('2014/08/17');
  3262. this.bv.validate();
  3263. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3264. });
  3265. it('dynamic max: callback declarative A.B.C', function() {
  3266. this.$maxDate.attr('data-bv-date-max', 'TestSuite.Date.getDate');
  3267. this.bv.destroy();
  3268. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3269. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3270. this.$date.val('2015/01/01');
  3271. this.$maxDate.val('2014/09/09');
  3272. this.bv.validate();
  3273. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3274. this.bv.resetForm();
  3275. this.$date.val('2014/01/01');
  3276. this.$maxDate.val('2014/08/17');
  3277. this.bv.validate();
  3278. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3279. });
  3280. it('dynamic max: callback declarative A.B.C()', function() {
  3281. this.$maxDate.attr('data-bv-date-max', 'TestSuite.Date.getDate()');
  3282. this.bv.destroy();
  3283. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3284. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3285. this.$date.val('2015/01/01');
  3286. this.$maxDate.val('2014/09/09');
  3287. this.bv.validate();
  3288. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3289. this.bv.resetForm();
  3290. this.$date.val('2014/01/01');
  3291. this.$maxDate.val('2014/08/17');
  3292. this.bv.validate();
  3293. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3294. });
  3295. it('dynamic max: callback programmatically', function() {
  3296. this.$maxDate.removeAttr('data-bv-date-max');
  3297. this.bv.destroy();
  3298. this.bv = $('#dateForm')
  3299. .bootstrapValidator({
  3300. fields: {
  3301. maxDate: {
  3302. validators: {
  3303. date: {
  3304. max: function(value, validator, $field) {
  3305. return getDate(value, validator, $field);
  3306. }
  3307. }
  3308. }
  3309. }
  3310. }
  3311. })
  3312. .data('bootstrapValidator');
  3313. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3314. this.$date.val('2015/01/01');
  3315. this.$maxDate.val('2014/09/09');
  3316. this.bv.validate();
  3317. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3318. this.bv.resetForm();
  3319. this.$date.val('2014/01/01');
  3320. this.$maxDate.val('2014/08/17');
  3321. this.bv.validate();
  3322. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3323. });
  3324. });
  3325. describe('ean', function() {
  3326. beforeEach(function() {
  3327. var html = [
  3328. '<div class="container">',
  3329. '<form class="form-horizontal" id="eanForm">',
  3330. '<div class="form-group">',
  3331. '<input type="text" name="ean" data-bv-ean />',
  3332. '</div>',
  3333. '</form>',
  3334. '</div>'
  3335. ].join('\n');
  3336. $(html).appendTo('body');
  3337. $('#eanForm').bootstrapValidator();
  3338. this.bv = $('#eanForm').data('bootstrapValidator');
  3339. this.$ean = this.bv.getFieldElements('ean');
  3340. });
  3341. afterEach(function() {
  3342. $('#eanForm').bootstrapValidator('destroy').parent().remove();
  3343. });
  3344. it('valid', function() {
  3345. var samples = ['73513537', '9780471117094', '4006381333931'];
  3346. for (var i in samples) {
  3347. this.$ean.val(samples[i]);
  3348. this.bv.validate();
  3349. expect(this.bv.isValidField('ean')).toBeTruthy();
  3350. }
  3351. });
  3352. it('contains only digits', function() {
  3353. this.$ean.val('123abcDEF!@#');
  3354. this.bv.validate();
  3355. expect(this.bv.isValidField('ean')).toEqual(false);
  3356. });
  3357. it('invalid length', function() {
  3358. this.$ean.val('1234567');
  3359. this.bv.validate();
  3360. expect(this.bv.isValidField('ean')).toEqual(false);
  3361. });
  3362. it('invalid check digit', function() {
  3363. this.$ean.val('73513536');
  3364. this.bv.validate();
  3365. expect(this.bv.isValidField('ean')).toEqual(false);
  3366. });
  3367. });
  3368. describe('emailAddress', function() {
  3369. beforeEach(function() {
  3370. $([
  3371. '<form class="form-horizontal" id="emailAddressForm">',
  3372. '<div id="msg"></div>',
  3373. '<div class="form-group">',
  3374. '<input type="text" name="email-address-or-addresses" data-bv-emailaddress />',
  3375. '</div>',
  3376. '</form>'
  3377. ].join('\n')).appendTo('body');
  3378. $('#emailAddressForm').bootstrapValidator();
  3379. this.bv = $('#emailAddressForm').data('bootstrapValidator');
  3380. this.$emailAddressOrAddresses = this.bv.getFieldElements('email-address-or-addresses');
  3381. });
  3382. afterEach(function() {
  3383. $('#emailAddressForm').bootstrapValidator('destroy').remove();
  3384. });
  3385. var validEmailAddresses = [
  3386. 'admin@mailserver1',
  3387. 'niceandsimple@example.com',
  3388. 'very.common@example.com',
  3389. 'a.little.lengthy.but.fine@dept.example.com',
  3390. 'disposable.style.email.with+symbol@example.com',
  3391. 'other.email-with-dash@example.com',
  3392. '"much.more unusual"@example.com',
  3393. '"very.unusual.@.unusual.com"@example.com',
  3394. '"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
  3395. '" "@example.org',
  3396. 'üñîçøðé@example.com'
  3397. ];
  3398. var invalidEmailAddresses = [
  3399. // "!#$%&'*+-/=?^_`{}|~@example.org", // This is actually passing validation; see https://github.com/nghuuphuoc/bootstrapvalidator/issues/673
  3400. 'üñîçøðé@üñîçøðé.com',
  3401. 'Abc.example.com',
  3402. 'A@b@c@example.com',
  3403. 'a"b(c)d,e:f;gi[j\k]l@example.com',
  3404. 'just"not"right@example.com',
  3405. 'this is"not\allowed@example.com',
  3406. 'this\ still\"not\\allowed@example.com'
  3407. ];
  3408. var validMultipleEmailAddressesForDefaultSeparators = [
  3409. 'niceandsimple@example.com,very.common@example.com',
  3410. 'niceandsimple@example.com;very.common@example.com',
  3411. 'niceandsimple@example.com;very.common@example.com,a.little.lengthy.but.fine@dept.example.com'
  3412. ];
  3413. var invalidMultipleEmailAddressesForDefaultSeparators = [
  3414. 'niceandsimple@example.com+very.common@example.com',
  3415. 'niceandsimple@example.com|very.common@example.com'
  3416. ];
  3417. var validMultipleEmailAddressesForCommaOrDollarSignSeparators = [
  3418. 'niceandsimple@example.com,very.common@example.com',
  3419. 'niceandsimple@example.com$very.common@example.com',
  3420. 'niceandsimple@example.com,very.common@example.com$a.little.lengthy.but.fine@dept.example.com'
  3421. ];
  3422. var invalidMultipleEmailAddressesForCommaOrDollarSignSeparators = [
  3423. 'niceandsimple@example.com;very.common@example.com',
  3424. 'niceandsimple@example.com;very.common@example.com,a.little.lengthy.but.fine@dept.example.com'
  3425. ];
  3426. it('Valid email addresses (multiple=false)', function() {
  3427. var that = this;
  3428. $.each(validEmailAddresses, function(index, emailAddress) {
  3429. that.bv.resetForm();
  3430. that.$emailAddressOrAddresses.val(emailAddress);
  3431. that.bv.validate();
  3432. expect(that.bv.isValid()).toBeTruthy();
  3433. });
  3434. });
  3435. it('Invalid email addresses (multiple=false)', function() {
  3436. var that = this;
  3437. var addresses = invalidEmailAddresses
  3438. .concat(validMultipleEmailAddressesForDefaultSeparators)
  3439. .concat(invalidMultipleEmailAddressesForDefaultSeparators)
  3440. .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators)
  3441. .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3442. $.each(addresses, function(index, emailAddress) {
  3443. that.bv.resetForm();
  3444. that.$emailAddressOrAddresses.val(emailAddress);
  3445. that.bv.validate();
  3446. expect(that.bv.isValid()).toEqual(false);
  3447. });
  3448. });
  3449. it('Invalid email addresses (multiple=false,separator=/[,\$]/)', function() {
  3450. var that = this;
  3451. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,;]/);
  3452. var addresses = invalidEmailAddresses
  3453. .concat(validMultipleEmailAddressesForDefaultSeparators)
  3454. .concat(invalidMultipleEmailAddressesForDefaultSeparators)
  3455. .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators)
  3456. .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3457. $.each(addresses, function(index, emailAddress) {
  3458. that.bv.resetForm();
  3459. that.$emailAddressOrAddresses.val(emailAddress);
  3460. that.bv.validate();
  3461. expect(that.bv.isValid()).toEqual(false);
  3462. });
  3463. });
  3464. it('Valid email addresses (multiple=true)', function() {
  3465. var that = this;
  3466. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3467. var addresses = validEmailAddresses
  3468. .concat(validMultipleEmailAddressesForDefaultSeparators);
  3469. $.each(addresses, function(index, emailAddress) {
  3470. that.bv.resetForm();
  3471. that.$emailAddressOrAddresses.val(emailAddress);
  3472. that.bv.validate();
  3473. expect(that.bv.isValid()).toBeTruthy();
  3474. });
  3475. });
  3476. it('Invalid email addresses (multiple=true)', function() {
  3477. var that = this;
  3478. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3479. var addresses = invalidEmailAddresses
  3480. .concat(invalidMultipleEmailAddressesForDefaultSeparators);
  3481. $.each(addresses, function(index, emailAddress) {
  3482. that.bv.resetForm();
  3483. that.$emailAddressOrAddresses.val(emailAddress);
  3484. that.bv.validate();
  3485. expect(that.bv.isValid()).toEqual(false);
  3486. });
  3487. });
  3488. it('Valid email addresses (multiple=true,separator=/[,\$]/)', function() {
  3489. var that = this;
  3490. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3491. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,\$]/);
  3492. var addresses = validEmailAddresses
  3493. .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3494. $.each(addresses, function(index, emailAddress) {
  3495. that.bv.resetForm();
  3496. that.$emailAddressOrAddresses.val(emailAddress);
  3497. that.bv.validate();
  3498. expect(that.bv.isValid()).toBeTruthy();
  3499. });
  3500. });
  3501. it('Invalid email addresses (multiple=true,separator=/[,\$]/)', function() {
  3502. var that = this;
  3503. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3504. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,\$]/);
  3505. var addresses = invalidEmailAddresses
  3506. .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3507. $.each(addresses, function(index, emailAddress) {
  3508. that.bv.resetForm();
  3509. that.$emailAddressOrAddresses.val(emailAddress);
  3510. that.bv.validate();
  3511. expect(that.bv.isValid()).toEqual(false);
  3512. });
  3513. });
  3514. });
  3515. function greaterThanCompare() {
  3516. var compareTo = $('#greaterThanForm').find('[name="minAge"]').val();
  3517. $('#msg').html('greaterThanCompare() called; compare to ' + compareTo);
  3518. return compareTo;
  3519. };
  3520. TestSuite = $.extend({}, TestSuite, {
  3521. greaterThan: {
  3522. compareTo: function(value, validator, $field) {
  3523. var compareTo = $('#greaterThanForm').find('[name="minAge"]').val();
  3524. $('#msg').html('TestSuite.greaterThan.compareTo() called; compare to ' + compareTo);
  3525. return compareTo;
  3526. }
  3527. }
  3528. });
  3529. describe('greaterThan', function() {
  3530. beforeEach(function() {
  3531. $([
  3532. '<form class="form-horizontal" id="greaterThanForm">',
  3533. '<div id="msg"></div>',
  3534. '<div class="form-group">',
  3535. '<input type="text" name="minAge" />',
  3536. '</div>',
  3537. '<div class="form-group">',
  3538. '<input type="text" name="age" data-bv-greaterthan data-bv-greaterthan-value="18" />',
  3539. '</div>',
  3540. '</form>'
  3541. ].join('\n')).appendTo('body');
  3542. $('#greaterThanForm').bootstrapValidator();
  3543. this.bv = $('#greaterThanForm').data('bootstrapValidator');
  3544. this.$minAge = this.bv.getFieldElements('minAge');
  3545. this.$age = this.bv.getFieldElements('age');
  3546. });
  3547. afterEach(function() {
  3548. $('#greaterThanForm').bootstrapValidator('destroy').remove();
  3549. });
  3550. it('not a number', function() {
  3551. this.$age.val('20abc');
  3552. this.bv.validate();
  3553. expect(this.bv.isValid()).toEqual(false);
  3554. });
  3555. it('compare to value', function() {
  3556. this.$age.val(10);
  3557. this.bv.validate();
  3558. expect(this.bv.isValid()).toEqual(false);
  3559. this.bv.resetForm();
  3560. this.$age.val(20);
  3561. this.bv.validate();
  3562. expect(this.bv.isValid()).toBeTruthy();
  3563. });
  3564. it('value with coma separator', function() {
  3565. this.$age.val('10,4');
  3566. this.bv.validate();
  3567. expect(this.bv.isValid()).toEqual(false);
  3568. this.bv.resetForm();
  3569. this.$age.val('18,678');
  3570. this.bv.validate();
  3571. expect(this.bv.isValid()).toBeTruthy();
  3572. });
  3573. it('compare to other field', function() {
  3574. this.$age.attr('data-bv-greaterthan-value', 'minAge');
  3575. this.bv.destroy();
  3576. this.bv = $('#greaterThanForm').bootstrapValidator().data('bootstrapValidator');
  3577. this.$minAge.val(10);
  3578. this.$age.val(20);
  3579. this.bv.validate();
  3580. expect(this.bv.isValid()).toBeTruthy();
  3581. this.bv.resetForm();
  3582. this.$minAge.val(20);
  3583. this.$age.val(10);
  3584. this.bv.validate();
  3585. expect(this.bv.isValid()).toEqual(false);
  3586. expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
  3587. });
  3588. it('compare to return value of a function', function() {
  3589. this.$age.attr('data-bv-greaterthan-value', 'greaterThanCompare');
  3590. this.bv.destroy();
  3591. this.bv = $('#greaterThanForm').bootstrapValidator().data('bootstrapValidator');
  3592. this.$minAge.val(20);
  3593. this.$age.val(18);
  3594. this.bv.validate();
  3595. expect($('#msg').html()).toEqual('greaterThanCompare() called; compare to 20');
  3596. expect(this.bv.isValid()).toEqual(false);
  3597. expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
  3598. this.bv.resetForm();
  3599. this.$minAge.val(18);
  3600. this.$age.val(20);
  3601. this.bv.validate();
  3602. expect($('#msg').html()).toEqual('greaterThanCompare() called; compare to 18');
  3603. expect(this.bv.isValid()).toBeTruthy();
  3604. });
  3605. it('compare to return value of a namespace function', function() {
  3606. this.$age.attr('data-bv-greaterthan-value', 'TestSuite.greaterThan.compareTo');
  3607. this.bv.destroy();
  3608. this.bv = $('#greaterThanForm').bootstrapValidator().data('bootstrapValidator');
  3609. this.$minAge.val(20);
  3610. this.$age.val(18);
  3611. this.bv.validate();
  3612. expect($('#msg').html()).toEqual('TestSuite.greaterThan.compareTo() called; compare to 20');
  3613. expect(this.bv.isValid()).toEqual(false);
  3614. expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
  3615. this.bv.resetForm();
  3616. this.$minAge.val(18);
  3617. this.$age.val(20);
  3618. this.bv.validate();
  3619. expect($('#msg').html()).toEqual('TestSuite.greaterThan.compareTo() called; compare to 18');
  3620. expect(this.bv.isValid()).toBeTruthy();
  3621. });
  3622. });
  3623. describe('iban', function() {
  3624. beforeEach(function() {
  3625. $([
  3626. '<form class="form-horizontal" id="ibanForm">',
  3627. '<div class="form-group">',
  3628. '<select class="form-control" name="country">',
  3629. '<option value="AD">Andorra</option>',
  3630. '<option value="AE">United Arab Emirates</option>',
  3631. '<option value="AL">Albania</option>',
  3632. '<option value="AO">Angola</option>',
  3633. '<option value="AT">Austria</option>',
  3634. '<option value="AZ">Azerbaijan</option>',
  3635. '<option value="BA">Bosnia and Herzegovina</option>',
  3636. '<option value="BE">Belgium</option>',
  3637. '<option value="BF">Burkina Faso</option>',
  3638. '<option value="BG">Bulgaria</option>',
  3639. '<option value="BH">Bahrain</option>',
  3640. '<option value="BI">Burundi</option>',
  3641. '<option value="BJ">Benin</option>',
  3642. '<option value="BR">Brazil</option>',
  3643. '<option value="CH">Switzerland</option>',
  3644. '<option value="CM">Cameroon</option>',
  3645. '<option value="CR">Costa Rica</option>',
  3646. '<option value="CV">Cape Verde</option>',
  3647. '<option value="CY">Cyprus</option>',
  3648. '<option value="CZ">Czech Republic</option>',
  3649. '<option value="DE">Germany</option>',
  3650. '<option value="DK">Denmark</option>',
  3651. '<option value="DO">Dominican Republic</option>',
  3652. '<option value="DZ">Algeria</option>',
  3653. '<option value="EE">Estonia</option>',
  3654. '<option value="ES">Spain</option>',
  3655. '<option value="FI">Finland</option>',
  3656. '<option value="FO">Faroe Islands</option>',
  3657. '<option value="FR">France</option>',
  3658. '<option value="GB">United Kingdom</option>',
  3659. '<option value="GE">Georgia</option>',
  3660. '<option value="GI">Gibraltar</option>',
  3661. '<option value="GL">Greenland</option>',
  3662. '<option value="GR">Greece</option>',
  3663. '<option value="GT">Guatemala</option>',
  3664. '<option value="HR">Croatia</option>',
  3665. '<option value="HU">Hungary</option>',
  3666. '<option value="IE">Ireland</option>',
  3667. '<option value="IL">Israel</option>',
  3668. '<option value="IR">Iran</option>',
  3669. '<option value="IS">Iceland</option>',
  3670. '<option value="IT">Italy</option>',
  3671. '<option value="JO">Jordan</option>',
  3672. '<option value="KW">Kuwait</option>',
  3673. '<option value="KZ">Kazakhstan</option>',
  3674. '<option value="LB">Lebanon</option>',
  3675. '<option value="LI">Liechtenstein</option>',
  3676. '<option value="LT">Lithuania</option>',
  3677. '<option value="LU">Luxembourg</option>',
  3678. '<option value="LV">Latvia</option>',
  3679. '<option value="MC">Monaco</option>',
  3680. '<option value="MD">Moldova</option>',
  3681. '<option value="ME">Montenegro</option>',
  3682. '<option value="MG">Madagascar</option>',
  3683. '<option value="MK">Macedonia</option>',
  3684. '<option value="ML">Mali</option>',
  3685. '<option value="MR">Mauritania</option>',
  3686. '<option value="MT">Malta</option>',
  3687. '<option value="MU">Mauritius</option>',
  3688. '<option value="MZ">Mozambique</option>',
  3689. '<option value="NL">Netherlands</option>',
  3690. '<option value="NO">Norway</option>',
  3691. '<option value="PK">Pakistan</option>',
  3692. '<option value="PL">Poland</option>',
  3693. '<option value="PS">Palestinian</option>',
  3694. '<option value="PT">Portugal</option>',
  3695. '<option value="QA">Qatar</option>',
  3696. '<option value="RO">Romania</option>',
  3697. '<option value="RS">Serbia</option>',
  3698. '<option value="SA">Saudi Arabia</option>',
  3699. '<option value="SE">Sweden</option>',
  3700. '<option value="SE">Slovenia</option>',
  3701. '<option value="SK">Slovakia</option>',
  3702. '<option value="SM">San Marino</option>',
  3703. '<option value="SN">Senegal</option>',
  3704. '<option value="TN">Tunisia</option>',
  3705. '<option value="TR">Turkey</option>',
  3706. '<option value="VG">Virgin Islands, British</option>',
  3707. '</select>',
  3708. '</div>',
  3709. '<div class="form-group">',
  3710. '<input type="text" name="iban" data-bv-iban />',
  3711. '</div>',
  3712. '</form>'
  3713. ].join('\n')).appendTo('body');
  3714. $('#ibanForm').bootstrapValidator();
  3715. this.bv = $('#ibanForm').data('bootstrapValidator');
  3716. this.$country = this.bv.getFieldElements('country');
  3717. this.$iban = this.bv.getFieldElements('iban');
  3718. });
  3719. afterEach(function() {
  3720. $('#ibanForm').bootstrapValidator('destroy').remove();
  3721. });
  3722. it('not supported country', function() {
  3723. this.$iban.val('US123456789');
  3724. this.bv.validate();
  3725. expect(this.bv.isValidField('iban')).toEqual(false);
  3726. });
  3727. it('dynamic country', function() {
  3728. this.$iban.attr('data-bv-iban-country', 'country');
  3729. this.bv.destroy();
  3730. this.bv = $('#ibanForm').bootstrapValidator().data('bootstrapValidator');
  3731. this.$country.val('AT');
  3732. this.$iban.val('AT611904300234573201');
  3733. this.bv.validate();
  3734. expect(this.bv.isValid()).toBeTruthy();
  3735. this.bv.resetForm();
  3736. this.$country.val('BG');
  3737. this.$iban.val('HR1210010051863000160');
  3738. this.bv.validate();
  3739. expect(this.bv.isValid()).toEqual(false);
  3740. });
  3741. it('Albania', function() {
  3742. this.$iban.val('AL47212110090000000235698741');
  3743. this.bv.validate();
  3744. expect(this.bv.isValidField('iban')).toBeTruthy();
  3745. });
  3746. it('Algeria', function() {
  3747. this.$iban.val('DZ4000400174401001050486');
  3748. this.bv.validate();
  3749. expect(this.bv.isValidField('iban')).toBeTruthy();
  3750. });
  3751. it('Andorra', function() {
  3752. this.$iban.val('AD1200012030200359100100');
  3753. this.bv.validate();
  3754. expect(this.bv.isValidField('iban')).toBeTruthy();
  3755. });
  3756. it('Angola', function() {
  3757. this.$iban.val('AO06000600000100037131174');
  3758. this.bv.validate();
  3759. expect(this.bv.isValidField('iban')).toBeTruthy();
  3760. });
  3761. it('Austria', function() {
  3762. this.$iban.val('AT611904300234573201');
  3763. this.bv.validate();
  3764. expect(this.bv.isValidField('iban')).toBeTruthy();
  3765. });
  3766. it('Azerbaijan', function() {
  3767. this.$iban.val('AZ21NABZ00000000137010001944');
  3768. this.bv.validate();
  3769. expect(this.bv.isValidField('iban')).toBeTruthy();
  3770. });
  3771. it('Bahrain', function() {
  3772. this.$iban.val('BH29BMAG1299123456BH00');
  3773. this.bv.validate();
  3774. expect(this.bv.isValidField('iban')).toBeTruthy();
  3775. });
  3776. it('Belgium', function() {
  3777. this.$iban.val('BE68539007547034');
  3778. this.bv.validate();
  3779. expect(this.bv.isValidField('iban')).toBeTruthy();
  3780. });
  3781. it('Benin', function() {
  3782. this.$iban.val('BJ11B00610100400271101192591');
  3783. this.bv.validate();
  3784. expect(this.bv.isValidField('iban')).toBeTruthy();
  3785. });
  3786. it('Brazil', function() {
  3787. this.$iban.val('BR9700360305000010009795493P1');
  3788. this.bv.validate();
  3789. expect(this.bv.isValidField('iban')).toBeTruthy();
  3790. });
  3791. it('Bulgaria', function() {
  3792. this.$iban.val('BG80BNBG96611020345678');
  3793. this.bv.validate();
  3794. expect(this.bv.isValidField('iban')).toBeTruthy();
  3795. });
  3796. it('Burkina Faso', function() {
  3797. this.$iban.val('BF1030134020015400945000643');
  3798. this.bv.validate();
  3799. expect(this.bv.isValidField('iban')).toBeTruthy();
  3800. });
  3801. it('Burundi', function() {
  3802. this.$iban.val('BI43201011067444');
  3803. this.bv.validate();
  3804. expect(this.bv.isValidField('iban')).toBeTruthy();
  3805. });
  3806. it('Cameroon', function() {
  3807. this.$iban.val('CM2110003001000500000605306');
  3808. this.bv.validate();
  3809. expect(this.bv.isValidField('iban')).toBeTruthy();
  3810. });
  3811. it('Cape Verde', function() {
  3812. this.$iban.val('CV64000300004547069110176');
  3813. this.bv.validate();
  3814. expect(this.bv.isValidField('iban')).toBeTruthy();
  3815. });
  3816. it('Costa Rica', function() {
  3817. this.$iban.val('CR0515202001026284066');
  3818. this.bv.validate();
  3819. expect(this.bv.isValidField('iban')).toBeTruthy();
  3820. });
  3821. it('Croatia', function() {
  3822. this.$iban.val('HR1210010051863000160');
  3823. this.bv.validate();
  3824. expect(this.bv.isValidField('iban')).toBeTruthy();
  3825. });
  3826. it('Cyprus', function() {
  3827. this.$iban.val('CY17002001280000001200527600');
  3828. this.bv.validate();
  3829. expect(this.bv.isValidField('iban')).toBeTruthy();
  3830. });
  3831. it('Czech Republic', function() {
  3832. this.$iban.val('CZ6508000000192000145399');
  3833. this.bv.validate();
  3834. expect(this.bv.isValidField('iban')).toBeTruthy();
  3835. });
  3836. it('Denmark', function() {
  3837. this.$iban.val('DK5000400440116243');
  3838. this.bv.validate();
  3839. expect(this.bv.isValidField('iban')).toBeTruthy();
  3840. });
  3841. it('Dominican Republic', function() {
  3842. this.$iban.val('DO28BAGR00000001212453611324');
  3843. this.bv.validate();
  3844. expect(this.bv.isValidField('iban')).toBeTruthy();
  3845. });
  3846. it('Estonia', function() {
  3847. this.$iban.val('EE382200221020145685');
  3848. this.bv.validate();
  3849. expect(this.bv.isValidField('iban')).toBeTruthy();
  3850. });
  3851. it('Faroe Islands', function() {
  3852. this.$iban.val('FO1464600009692713');
  3853. this.bv.validate();
  3854. expect(this.bv.isValidField('iban')).toBeTruthy();
  3855. });
  3856. it('Finland', function() {
  3857. this.$iban.val('FI2112345600000785');
  3858. this.bv.validate();
  3859. expect(this.bv.isValidField('iban')).toBeTruthy();
  3860. });
  3861. it('France', function() {
  3862. this.$iban.val('FR1420041010050500013M02606');
  3863. this.bv.validate();
  3864. expect(this.bv.isValidField('iban')).toBeTruthy();
  3865. });
  3866. it('Guatemala', function() {
  3867. this.$iban.val('GT82TRAJ01020000001210029690');
  3868. this.bv.validate();
  3869. expect(this.bv.isValidField('iban')).toBeTruthy();
  3870. });
  3871. it('Georgia', function() {
  3872. this.$iban.val('GE29NB0000000101904917');
  3873. this.bv.validate();
  3874. expect(this.bv.isValidField('iban')).toBeTruthy();
  3875. });
  3876. it('Germany', function() {
  3877. this.$iban.val('DE89370400440532013000');
  3878. this.bv.validate();
  3879. expect(this.bv.isValidField('iban')).toBeTruthy();
  3880. });
  3881. it('Gibraltar', function() {
  3882. this.$iban.val('GI75NWBK000000007099453');
  3883. this.bv.validate();
  3884. expect(this.bv.isValidField('iban')).toBeTruthy();
  3885. });
  3886. it('Greece', function() {
  3887. this.$iban.val('GR1601101250000000012300695');
  3888. this.bv.validate();
  3889. expect(this.bv.isValidField('iban')).toBeTruthy();
  3890. });
  3891. it('Greenland', function() {
  3892. this.$iban.val('GL8964710001000206');
  3893. this.bv.validate();
  3894. expect(this.bv.isValidField('iban')).toBeTruthy();
  3895. });
  3896. it('Hungary', function() {
  3897. this.$iban.val('HU42117730161111101800000000');
  3898. this.bv.validate();
  3899. expect(this.bv.isValidField('iban')).toBeTruthy();
  3900. });
  3901. it('Iceland', function() {
  3902. this.$iban.val('IS140159260076545510730339');
  3903. this.bv.validate();
  3904. expect(this.bv.isValidField('iban')).toBeTruthy();
  3905. });
  3906. it('Iran', function() {
  3907. this.$iban.val('IR580540105180021273113007');
  3908. this.bv.validate();
  3909. expect(this.bv.isValidField('iban')).toBeTruthy();
  3910. });
  3911. it('Ireland', function() {
  3912. this.$iban.val('IE29AIBK93115212345678');
  3913. this.bv.validate();
  3914. expect(this.bv.isValidField('iban')).toBeTruthy();
  3915. });
  3916. it('Israel', function() {
  3917. this.$iban.val('IL620108000000099999999');
  3918. this.bv.validate();
  3919. expect(this.bv.isValidField('iban')).toBeTruthy();
  3920. });
  3921. it('Italy', function() {
  3922. this.$iban.val('IT60X0542811101000000123456');
  3923. this.bv.validate();
  3924. expect(this.bv.isValidField('iban')).toBeTruthy();
  3925. });
  3926. it('Ivory Coast', function() {
  3927. this.$iban.val('CI05A00060174100178530011852');
  3928. this.bv.validate();
  3929. expect(this.bv.isValidField('iban')).toBeTruthy();
  3930. });
  3931. it('Jordan', function() {
  3932. this.$iban.val('JO94CBJO0010000000000131000302');
  3933. this.bv.validate();
  3934. expect(this.bv.isValidField('iban')).toBeTruthy();
  3935. });
  3936. it('Kazakhstan', function() {
  3937. this.$iban.val('KZ176010251000042993');
  3938. this.bv.validate();
  3939. expect(this.bv.isValidField('iban')).toBeTruthy();
  3940. });
  3941. it('Kuwait', function() {
  3942. this.$iban.val('KW74NBOK0000000000001000372151');
  3943. this.bv.validate();
  3944. expect(this.bv.isValidField('iban')).toBeTruthy();
  3945. });
  3946. it('Latvia', function() {
  3947. this.$iban.val('LV80BANK0000435195001');
  3948. this.bv.validate();
  3949. expect(this.bv.isValidField('iban')).toBeTruthy();
  3950. });
  3951. it('Lebanon', function() {
  3952. this.$iban.val('LB30099900000001001925579115');
  3953. this.bv.validate();
  3954. expect(this.bv.isValidField('iban')).toBeTruthy();
  3955. });
  3956. it('Liechtenstein', function() {
  3957. this.$iban.val('LI21088100002324013AA');
  3958. this.bv.validate();
  3959. expect(this.bv.isValidField('iban')).toBeTruthy();
  3960. });
  3961. it('Lithuania', function() {
  3962. this.$iban.val('LT121000011101001000');
  3963. this.bv.validate();
  3964. expect(this.bv.isValidField('iban')).toBeTruthy();
  3965. });
  3966. it('Luxembourg', function() {
  3967. this.$iban.val('LU280019400644750000');
  3968. this.bv.validate();
  3969. expect(this.bv.isValidField('iban')).toBeTruthy();
  3970. });
  3971. it('Macedonia', function() {
  3972. this.$iban.val('MK07300000000042425');
  3973. this.bv.validate();
  3974. expect(this.bv.isValidField('iban')).toBeTruthy();
  3975. });
  3976. it('Madagascar', function() {
  3977. this.$iban.val('MG4600005030010101914016056');
  3978. this.bv.validate();
  3979. expect(this.bv.isValidField('iban')).toBeTruthy();
  3980. });
  3981. it('Malta', function() {
  3982. this.$iban.val('MT84MALT011000012345MTLCAST001S');
  3983. this.bv.validate();
  3984. expect(this.bv.isValidField('iban')).toBeTruthy();
  3985. });
  3986. it('Mauritania', function() {
  3987. this.$iban.val('MR1300012000010000002037372');
  3988. this.bv.validate();
  3989. expect(this.bv.isValidField('iban')).toBeTruthy();
  3990. });
  3991. it('Mauritius', function() {
  3992. this.$iban.val('MU17BOMM0101101030300200000MUR');
  3993. this.bv.validate();
  3994. expect(this.bv.isValidField('iban')).toBeTruthy();
  3995. });
  3996. it('Mali', function() {
  3997. this.$iban.val('ML03D00890170001002120000447');
  3998. this.bv.validate();
  3999. expect(this.bv.isValidField('iban')).toBeTruthy();
  4000. });
  4001. it('Moldova', function() {
  4002. this.$iban.val('MD24AG000225100013104168');
  4003. this.bv.validate();
  4004. expect(this.bv.isValidField('iban')).toBeTruthy();
  4005. });
  4006. it('Monaco', function() {
  4007. this.$iban.val('MC5813488000010051108001292');
  4008. this.bv.validate();
  4009. expect(this.bv.isValidField('iban')).toBeTruthy();
  4010. });
  4011. it('Montenegro', function() {
  4012. this.$iban.val('ME25505000012345678951');
  4013. this.bv.validate();
  4014. expect(this.bv.isValidField('iban')).toBeTruthy();
  4015. });
  4016. it('Mozambique', function() {
  4017. this.$iban.val('MZ59000100000011834194157');
  4018. this.bv.validate();
  4019. expect(this.bv.isValidField('iban')).toBeTruthy();
  4020. });
  4021. it('Netherlands', function() {
  4022. this.$iban.val('NL91ABNA0417164300');
  4023. this.bv.validate();
  4024. expect(this.bv.isValidField('iban')).toBeTruthy();
  4025. });
  4026. it('Norway', function() {
  4027. this.$iban.val('NO9386011117947');
  4028. this.bv.validate();
  4029. expect(this.bv.isValidField('iban')).toBeTruthy();
  4030. });
  4031. it('Pakistan', function() {
  4032. this.$iban.val('PK24SCBL0000001171495101');
  4033. this.bv.validate();
  4034. expect(this.bv.isValidField('iban')).toBeTruthy();
  4035. });
  4036. it('Palestine', function() {
  4037. this.$iban.val('PS92PALS000000000400123456702');
  4038. this.bv.validate();
  4039. expect(this.bv.isValidField('iban')).toBeTruthy();
  4040. });
  4041. it('Poland', function() {
  4042. this.$iban.val('PL27114020040000300201355387');
  4043. this.bv.validate();
  4044. expect(this.bv.isValidField('iban')).toBeTruthy();
  4045. });
  4046. it('Portugal', function() {
  4047. this.$iban.val('PT50000201231234567890154');
  4048. this.bv.validate();
  4049. expect(this.bv.isValidField('iban')).toBeTruthy();
  4050. });
  4051. it('Qatar', function() {
  4052. this.$iban.val('QA58DOHB00001234567890ABCDEFG');
  4053. this.bv.validate();
  4054. expect(this.bv.isValidField('iban')).toBeTruthy();
  4055. });
  4056. it('Romania', function() {
  4057. this.$iban.val('RO49AAAA1B31007593840000');
  4058. this.bv.validate();
  4059. expect(this.bv.isValidField('iban')).toBeTruthy();
  4060. });
  4061. it('San Marino', function() {
  4062. this.$iban.val('SM86U0322509800000000270100');
  4063. this.bv.validate();
  4064. expect(this.bv.isValidField('iban')).toBeTruthy();
  4065. });
  4066. it('Saudi Arabia', function() {
  4067. this.$iban.val('SA0380000000608010167519');
  4068. this.bv.validate();
  4069. expect(this.bv.isValidField('iban')).toBeTruthy();
  4070. });
  4071. it('Senegal', function() {
  4072. this.$iban.val('SN12K00100152000025690007542');
  4073. this.bv.validate();
  4074. expect(this.bv.isValidField('iban')).toBeTruthy();
  4075. });
  4076. it('Serbia', function() {
  4077. this.$iban.val('RS35260005601001611379');
  4078. this.bv.validate();
  4079. expect(this.bv.isValidField('iban')).toBeTruthy();
  4080. });
  4081. it('Slovakia', function() {
  4082. this.$iban.val('SK3112000000198742637541');
  4083. this.bv.validate();
  4084. expect(this.bv.isValidField('iban')).toBeTruthy();
  4085. });
  4086. it('Slovenia', function() {
  4087. this.$iban.val('SI56191000000123438');
  4088. this.bv.validate();
  4089. expect(this.bv.isValidField('iban')).toBeTruthy();
  4090. });
  4091. it('Spain', function() {
  4092. this.$iban.val('ES9121000418450200051332');
  4093. this.bv.validate();
  4094. expect(this.bv.isValidField('iban')).toBeTruthy();
  4095. });
  4096. it('Sweden', function() {
  4097. this.$iban.val('SE3550000000054910000003');
  4098. this.bv.validate();
  4099. expect(this.bv.isValidField('iban')).toBeTruthy();
  4100. });
  4101. it('Switzerland', function() {
  4102. this.$iban.val('CH9300762011623852957');
  4103. this.bv.validate();
  4104. expect(this.bv.isValidField('iban')).toBeTruthy();
  4105. });
  4106. it('Tunisia', function() {
  4107. this.$iban.val('TN5914207207100707129648');
  4108. this.bv.validate();
  4109. expect(this.bv.isValidField('iban')).toBeTruthy();
  4110. });
  4111. it('Turkey', function() {
  4112. this.$iban.val('TR330006100519786457841326');
  4113. this.bv.validate();
  4114. expect(this.bv.isValidField('iban')).toBeTruthy();
  4115. });
  4116. it('United Arab Emirates', function() {
  4117. this.$iban.val('AE260211000000230064016');
  4118. this.bv.validate();
  4119. expect(this.bv.isValidField('iban')).toBeTruthy();
  4120. });
  4121. it('United Kingdom', function() {
  4122. this.$iban.val('GB29NWBK60161331926819');
  4123. this.bv.validate();
  4124. expect(this.bv.isValidField('iban')).toBeTruthy();
  4125. });
  4126. it('Virgin Islands, British', function() {
  4127. this.$iban.val('VG96VPVG0000012345678901');
  4128. this.bv.validate();
  4129. expect(this.bv.isValidField('iban')).toBeTruthy();
  4130. });
  4131. it('invalid checksum', function() {
  4132. this.$iban.val('TR330006100519786457841325');
  4133. this.bv.validate();
  4134. expect(this.bv.isValidField('iban')).toEqual(false);
  4135. });
  4136. });
  4137. describe('id', function() {
  4138. beforeEach(function() {
  4139. $([
  4140. '<form class="form-horizontal" id="idForm">',
  4141. '<div class="form-group">',
  4142. '<select class="form-control" name="country">',
  4143. '<option value="BA">Bosnia and Herzegovina</option>',
  4144. '<option value="BG">Bulgaria</option>',
  4145. '<option value="BR">Brazil</option>',
  4146. '<option value="CH">Switzerland</option>',
  4147. '<option value="CL">Chile</option>',
  4148. '<option value="CN">China</option>',
  4149. '<option value="CZ">Czech</option>',
  4150. '<option value="DK">Denmark</option>',
  4151. '<option value="EE">Estonia</option>',
  4152. '<option value="ES">Spain</option>',
  4153. '<option value="FI">Finland</option>',
  4154. '<option value="HR">Croatia</option>',
  4155. '<option value="IE">Ireland</option>',
  4156. '<option value="IS">Iceland</option>',
  4157. '<option value="LT">Lithuania</option>',
  4158. '<option value="LV">Latvia</option>',
  4159. '<option value="ME">Montenegro</option>',
  4160. '<option value="MK">Macedonia</option>',
  4161. '<option value="NL">Netherlands</option>',
  4162. '<option value="RO">Romania</option>',
  4163. '<option value="RS">Serbia</option>',
  4164. '<option value="SE">Sweden</option>',
  4165. '<option value="SI">Slovenia</option>',
  4166. '<option value="SK">Slovakia</option>',
  4167. '<option value="SM">San Marino</option>',
  4168. '<option value="TH">Thailand</option>',
  4169. '<option value="ZA">South Africa</option>',
  4170. '</select>',
  4171. '</div>',
  4172. '<div class="form-group">',
  4173. '<input class="form-control" type="text" name="id" data-bv-id />',
  4174. '</div>',
  4175. '</form>'
  4176. ].join('\n')).appendTo('body');
  4177. $('#idForm').bootstrapValidator();
  4178. /**
  4179. * @type {BootstrapValidator}
  4180. */
  4181. this.bv = $('#idForm').data('bootstrapValidator');
  4182. this.$country = this.bv.getFieldElements('country');
  4183. this.$id = this.bv.getFieldElements('id');
  4184. });
  4185. afterEach(function() {
  4186. $('#idForm').bootstrapValidator('destroy').remove();
  4187. });
  4188. it('dynamic country', function() {
  4189. this.$id.attr('data-bv-id-country', 'country');
  4190. this.bv.destroy();
  4191. this.bv = $('#idForm').bootstrapValidator().data('bootstrapValidator');
  4192. this.$country.val('BG');
  4193. this.$id.val('7552010005');
  4194. this.bv.validate();
  4195. expect(this.bv.isValid()).toBeTruthy();
  4196. this.bv.resetForm();
  4197. this.$country.val('BR');
  4198. this.$id.val('231.002.999-00');
  4199. this.bv.validate();
  4200. expect(this.bv.isValid()).toEqual(false);
  4201. });
  4202. it('Bulgarian national identification number (EGN)', function() {
  4203. this.bv.updateOption('id', 'id', 'country', 'BG');
  4204. // Valid samples
  4205. var validSamples = ['7523169263', '8032056031', '803205 603 1', '8001010008', '7501020018', '7552010005', '7542011030'];
  4206. for (var i in validSamples) {
  4207. this.bv.resetForm();
  4208. this.$id.val(validSamples[i]);
  4209. this.bv.validate();
  4210. expect(this.bv.isValid()).toBeTruthy();
  4211. }
  4212. // Invalid samples
  4213. var invalidSamples = ['8019010008'];
  4214. for (i in invalidSamples) {
  4215. this.bv.resetForm();
  4216. this.$id.val(invalidSamples[i]);
  4217. this.bv.validate();
  4218. expect(this.bv.isValid()).toEqual(false);
  4219. }
  4220. });
  4221. it('Brazilian national identification number (CPF)', function() {
  4222. this.bv.updateOption('id', 'id', 'country', 'BR');
  4223. // Valid samples
  4224. var validSamples = ['39053344705', '390.533.447-05', '111.444.777-35'];
  4225. for (var i in validSamples) {
  4226. this.bv.resetForm();
  4227. this.$id.val(validSamples[i]);
  4228. this.bv.validate();
  4229. expect(this.bv.isValid()).toBeTruthy();
  4230. }
  4231. // Invalid samples
  4232. var invalidSamples = ['231.002.999-00'];
  4233. for (i in invalidSamples) {
  4234. this.bv.resetForm();
  4235. this.$id.val(invalidSamples[i]);
  4236. this.bv.validate();
  4237. expect(this.bv.isValid()).toEqual(false);
  4238. }
  4239. });
  4240. it('Swiss Social Security Number (AHV-Nr/No AVS)', function() {
  4241. this.bv.updateOption('id', 'id', 'country', 'CH');
  4242. // Valid samples
  4243. var validSamples = ['756.1234.5678.95', '7561234567895'];
  4244. for (var i in validSamples) {
  4245. this.bv.resetForm();
  4246. this.$id.val(validSamples[i]);
  4247. this.bv.validate();
  4248. expect(this.bv.isValid()).toBeTruthy();
  4249. }
  4250. });
  4251. it('Chilean national identification number (RUN/RUT)', function() {
  4252. this.bv.updateOption('id', 'id', 'country', 'CL');
  4253. // Valid samples
  4254. var validSamples = ['76086428-5', '22060449-7', '12531909-2','12937893-K','12937893-k'];
  4255. for (var i in validSamples) {
  4256. this.bv.resetForm();
  4257. this.$id.val(validSamples[i]);
  4258. this.bv.validate();
  4259. expect(this.bv.isValid()).toBeTruthy();
  4260. }
  4261. });
  4262. // #793
  4263. it('Chinese citizen identification number', function() {
  4264. this.bv.updateOption('id', 'id', 'country', 'CN');
  4265. // Valid samples
  4266. var validSamples = ['450202201409072332', '22011219930407001X', '110108601017023'];
  4267. for (var i in validSamples) {
  4268. this.bv.resetForm();
  4269. this.$id.val(validSamples[i]);
  4270. this.bv.validate();
  4271. expect(this.bv.isValid()).toBeTruthy();
  4272. }
  4273. // Invalid samples
  4274. var invalidSamples = ['999999199304070016', '220112190002290016', '220112199304070019', '999999601017023', '110108999999023'];
  4275. for (i in invalidSamples) {
  4276. this.bv.resetForm();
  4277. this.$id.val(invalidSamples[i]);
  4278. this.bv.validate();
  4279. expect(this.bv.isValid()).toEqual(false);
  4280. }
  4281. });
  4282. it('Czech national identification number (RC)', function() {
  4283. this.bv.updateOption('id', 'id', 'country', 'CZ');
  4284. // Valid samples
  4285. var validSamples = ['7103192745', '991231123'];
  4286. for (var i in validSamples) {
  4287. this.bv.resetForm();
  4288. this.$id.val(validSamples[i]);
  4289. this.bv.validate();
  4290. expect(this.bv.isValid()).toBeTruthy();
  4291. }
  4292. // Invalid samples
  4293. var invalidSamples = ['1103492745', '590312123'];
  4294. for (i in invalidSamples) {
  4295. this.bv.resetForm();
  4296. this.$id.val(invalidSamples[i]);
  4297. this.bv.validate();
  4298. expect(this.bv.isValid()).toEqual(false);
  4299. }
  4300. });
  4301. it('Danish Personal Identification number (CPR)', function() {
  4302. this.bv.updateOption('id', 'id', 'country', 'DK');
  4303. // Valid samples
  4304. var validSamples = ['2110625629', '211062-5629'];
  4305. for (var i in validSamples) {
  4306. this.bv.resetForm();
  4307. this.$id.val(validSamples[i]);
  4308. this.bv.validate();
  4309. expect(this.bv.isValid()).toBeTruthy();
  4310. }
  4311. // Invalid samples
  4312. var invalidSamples = ['511062-5629'];
  4313. for (i in invalidSamples) {
  4314. this.bv.resetForm();
  4315. this.$id.val(invalidSamples[i]);
  4316. this.bv.validate();
  4317. expect(this.bv.isValid()).toEqual(false);
  4318. }
  4319. });
  4320. it('Estonian Personal Identification Code (isikukood)', function() {
  4321. this.bv.updateOption('id', 'id', 'country', 'EE');
  4322. // Valid samples
  4323. var validSamples = ['37605030299'];
  4324. for (var i in validSamples) {
  4325. this.bv.resetForm();
  4326. this.$id.val(validSamples[i]);
  4327. this.bv.validate();
  4328. expect(this.bv.isValid()).toBeTruthy();
  4329. }
  4330. });
  4331. it('Spanish personal identity code (DNI/NIE)', function() {
  4332. this.bv.updateOption('id', 'id', 'country', 'ES');
  4333. // Valid samples
  4334. var validSamples = ['54362315K', '54362315-K', 'X2482300W', 'X-2482300W', 'X-2482300-W'];
  4335. for (var i in validSamples) {
  4336. this.bv.resetForm();
  4337. this.$id.val(validSamples[i]);
  4338. this.bv.validate();
  4339. expect(this.bv.isValid()).toBeTruthy();
  4340. }
  4341. // Invalid samples
  4342. var invalidSamples = ['54362315Z', 'X-2482300A'];
  4343. for (i in invalidSamples) {
  4344. this.bv.resetForm();
  4345. this.$id.val(invalidSamples[i]);
  4346. this.bv.validate();
  4347. expect(this.bv.isValid()).toEqual(false);
  4348. }
  4349. });
  4350. it('Finnish Personal Identity Code (HETU)', function() {
  4351. this.bv.updateOption('id', 'id', 'country', 'FI');
  4352. // Valid samples
  4353. var validSamples = ['311280-888Y', '131052-308T'];
  4354. for (var i in validSamples) {
  4355. this.bv.resetForm();
  4356. this.$id.val(validSamples[i]);
  4357. this.bv.validate();
  4358. expect(this.bv.isValid()).toBeTruthy();
  4359. }
  4360. // Invalid samples
  4361. var invalidSamples = ['131052-308U', '310252-308Y'];
  4362. for (i in invalidSamples) {
  4363. this.bv.resetForm();
  4364. this.$id.val(invalidSamples[i]);
  4365. this.bv.validate();
  4366. expect(this.bv.isValid()).toEqual(false);
  4367. }
  4368. });
  4369. it('Croatian personal identification number (OIB)', function() {
  4370. this.bv.updateOption('id', 'id', 'country', 'HR');
  4371. // Valid samples
  4372. var validSamples = ['33392005961'];
  4373. for (var i in validSamples) {
  4374. this.bv.resetForm();
  4375. this.$id.val(validSamples[i]);
  4376. this.bv.validate();
  4377. expect(this.bv.isValid()).toBeTruthy();
  4378. }
  4379. // Invalid samples
  4380. var invalidSamples = ['33392005962'];
  4381. for (i in invalidSamples) {
  4382. this.bv.resetForm();
  4383. this.$id.val(invalidSamples[i]);
  4384. this.bv.validate();
  4385. expect(this.bv.isValid()).toEqual(false);
  4386. }
  4387. });
  4388. it('Irish Personal Public Service Number (PPS)', function() {
  4389. this.bv.updateOption('id', 'id', 'country', 'IE');
  4390. // Valid samples
  4391. var validSamples = ['6433435F', '6433435FT', '6433435FW', '6433435OA', '6433435IH', '1234567TW', '1234567FA'];
  4392. for (var i in validSamples) {
  4393. this.bv.resetForm();
  4394. this.$id.val(validSamples[i]);
  4395. this.bv.validate();
  4396. expect(this.bv.isValid()).toBeTruthy();
  4397. }
  4398. // Invalid samples
  4399. var invalidSamples = ['6433435E', '6433435VH'];
  4400. for (i in invalidSamples) {
  4401. this.bv.resetForm();
  4402. this.$id.val(invalidSamples[i]);
  4403. this.bv.validate();
  4404. expect(this.bv.isValid()).toEqual(false);
  4405. }
  4406. });
  4407. it('Iceland national identification number (Kennitala)', function() {
  4408. this.bv.updateOption('id', 'id', 'country', 'IS');
  4409. // Valid samples
  4410. var validSamples = ['120174-3399', '1201743399', '0902862349'];
  4411. for (var i in validSamples) {
  4412. this.bv.resetForm();
  4413. this.$id.val(validSamples[i]);
  4414. this.bv.validate();
  4415. expect(this.bv.isValid()).toBeTruthy();
  4416. }
  4417. });
  4418. it('Lithuanian Personal Code (Asmens kodas)', function() {
  4419. this.bv.updateOption('id', 'id', 'country', 'LT');
  4420. // Valid samples
  4421. var validSamples = ['38703181745'];
  4422. for (var i in validSamples) {
  4423. this.bv.resetForm();
  4424. this.$id.val(validSamples[i]);
  4425. this.bv.validate();
  4426. expect(this.bv.isValid()).toBeTruthy();
  4427. }
  4428. // Invalid samples
  4429. var invalidSamples = ['38703181746', '78703181745', '38703421745'];
  4430. for (i in invalidSamples) {
  4431. this.bv.resetForm();
  4432. this.$id.val(invalidSamples[i]);
  4433. this.bv.validate();
  4434. expect(this.bv.isValid()).toEqual(false);
  4435. }
  4436. });
  4437. it('Latvian Personal Code (Personas kods)', function() {
  4438. this.bv.updateOption('id', 'id', 'country', 'LV');
  4439. // Valid samples
  4440. var validSamples = ['161175-19997', '16117519997'];
  4441. for (var i in validSamples) {
  4442. this.bv.resetForm();
  4443. this.$id.val(validSamples[i]);
  4444. this.bv.validate();
  4445. expect(this.bv.isValid()).toBeTruthy();
  4446. }
  4447. // Invalid samples
  4448. var invalidSamples = ['161375-19997'];
  4449. for (i in invalidSamples) {
  4450. this.bv.resetForm();
  4451. this.$id.val(invalidSamples[i]);
  4452. this.bv.validate();
  4453. expect(this.bv.isValid()).toEqual(false);
  4454. }
  4455. });
  4456. it('Dutch national identification number (BSN)', function() {
  4457. this.bv.updateOption('id', 'id', 'country', 'NL');
  4458. // Valid samples
  4459. var validSamples = ['111222333', '941331490', '9413.31.490'];
  4460. for (var i in validSamples) {
  4461. this.bv.resetForm();
  4462. this.$id.val(validSamples[i]);
  4463. this.bv.validate();
  4464. expect(this.bv.isValid()).toBeTruthy();
  4465. }
  4466. // Invalid samples
  4467. var invalidSamples = ['111252333'];
  4468. for (i in invalidSamples) {
  4469. this.bv.resetForm();
  4470. this.$id.val(invalidSamples[i]);
  4471. this.bv.validate();
  4472. expect(this.bv.isValid()).toEqual(false);
  4473. }
  4474. });
  4475. it('Romanian numerical personal code (CNP)', function() {
  4476. this.bv.updateOption('id', 'id', 'country', 'RO');
  4477. // Valid samples
  4478. var validSamples = ['1630615123457', '1800101221144'];
  4479. for (var i in validSamples) {
  4480. this.bv.resetForm();
  4481. this.$id.val(validSamples[i]);
  4482. this.bv.validate();
  4483. expect(this.bv.isValid()).toBeTruthy();
  4484. }
  4485. // Invalid samples
  4486. var invalidSamples = ['8800101221144', '1632215123457', '1630615123458'];
  4487. for (i in invalidSamples) {
  4488. this.bv.resetForm();
  4489. this.$id.val(invalidSamples[i]);
  4490. this.bv.validate();
  4491. expect(this.bv.isValid()).toEqual(false);
  4492. }
  4493. });
  4494. it('Swedish personal identity number (personnummer)', function() {
  4495. this.bv.updateOption('id', 'id', 'country', 'SE');
  4496. // Valid samples
  4497. var validSamples = ['8112289874', '811228-9874', '811228+9874'];
  4498. for (var i in validSamples) {
  4499. this.bv.resetForm();
  4500. this.$id.val(validSamples[i]);
  4501. this.bv.validate();
  4502. expect(this.bv.isValid()).toBeTruthy();
  4503. }
  4504. // Invalid samples
  4505. var invalidSamples = ['811228-9873'];
  4506. for (i in invalidSamples) {
  4507. this.bv.resetForm();
  4508. this.$id.val(invalidSamples[i]);
  4509. this.bv.validate();
  4510. expect(this.bv.isValid()).toEqual(false);
  4511. }
  4512. });
  4513. it('Slovak national identifier number (RC)', function() {
  4514. this.bv.updateOption('id', 'id', 'country', 'SK');
  4515. // Valid samples
  4516. var validSamples = ['7103192745', '991231123'];
  4517. for (var i in validSamples) {
  4518. this.bv.resetForm();
  4519. this.$id.val(validSamples[i]);
  4520. this.bv.validate();
  4521. expect(this.bv.isValid()).toBeTruthy();
  4522. }
  4523. // Invalid samples
  4524. var invalidSamples = ['7103192746', '1103492745'];
  4525. for (i in invalidSamples) {
  4526. this.bv.resetForm();
  4527. this.$id.val(invalidSamples[i]);
  4528. this.bv.validate();
  4529. expect(this.bv.isValid()).toEqual(false);
  4530. }
  4531. });
  4532. it('South African ID', function() {
  4533. this.bv.updateOption('id', 'id', 'country', 'ZA');
  4534. // Valid samples
  4535. var validSamples = ['8001015009087'];
  4536. for (var i in validSamples) {
  4537. this.bv.resetForm();
  4538. this.$id.val(validSamples[i]);
  4539. this.bv.validate();
  4540. expect(this.bv.isValid()).toBeTruthy();
  4541. }
  4542. // Invalid samples
  4543. var invalidSamples = ['8001015009287', '8001015009086'];
  4544. for (i in invalidSamples) {
  4545. this.bv.resetForm();
  4546. this.$id.val(invalidSamples[i]);
  4547. this.bv.validate();
  4548. expect(this.bv.isValid()).toEqual(false);
  4549. }
  4550. });
  4551. it('Thailand citizen number', function() {
  4552. this.bv.updateOption('id', 'id', 'country', 'TH');
  4553. // Valid samples
  4554. var validSamples = ['7145620509547', '3688699975685', '2368719339716'];
  4555. for (var i in validSamples) {
  4556. this.bv.resetForm();
  4557. this.$id.val(validSamples[i]);
  4558. this.bv.validate();
  4559. expect(this.bv.isValid()).toBeTruthy();
  4560. }
  4561. // Invalid samples
  4562. var invalidSamples = ['1100800092310'];
  4563. for (i in invalidSamples) {
  4564. this.bv.resetForm();
  4565. this.$id.val(invalidSamples[i]);
  4566. this.bv.validate();
  4567. expect(this.bv.isValid()).toEqual(false);
  4568. }
  4569. });
  4570. });
  4571. describe('imo', function() {
  4572. beforeEach(function() {
  4573. $([
  4574. '<form class="form-horizontal" id="imoForm">',
  4575. '<div class="form-group">',
  4576. '<input type="text" name="imo" data-bv-imo />',
  4577. '</div>',
  4578. '</form>'
  4579. ].join('\n')).appendTo('body');
  4580. $('#imoForm').bootstrapValidator();
  4581. this.bv = $('#imoForm').data('bootstrapValidator');
  4582. this.$imo = this.bv.getFieldElements('imo');
  4583. });
  4584. afterEach(function() {
  4585. $('#imoForm').bootstrapValidator('destroy').remove();
  4586. });
  4587. it('Valid IMO (upper)', function() {
  4588. this.bv.resetForm();
  4589. this.$imo.val('IMO 9074729');
  4590. this.bv.validate();
  4591. expect(this.bv.isValid()).toBeTruthy();
  4592. });
  4593. it('Valid IMO (lower)', function() {
  4594. this.bv.resetForm();
  4595. this.$imo.val('imo 9074729');
  4596. this.bv.validate();
  4597. expect(this.bv.isValid()).toBeTruthy();
  4598. });
  4599. it('Invalid IMO (bad format)', function() {
  4600. this.bv.resetForm();
  4601. this.$imo.val('9074729');
  4602. this.bv.validate();
  4603. expect(this.bv.isValid()).toBeFalsy();
  4604. });
  4605. it('Invalid IMO (bad check digit)', function() {
  4606. this.bv.resetForm();
  4607. this.$imo.val('IMO 9074728');
  4608. this.bv.validate();
  4609. expect(this.bv.isValid()).toBeFalsy();
  4610. });
  4611. });
  4612. describe('ip', function() {
  4613. beforeEach(function() {
  4614. $([
  4615. '<form class="form-horizontal" id="ipForm">',
  4616. '<div class="form-group">',
  4617. '<input type="text" name="ipv4" data-bv-ip data-bv-ip-ipv6="false" />',
  4618. '</div>',
  4619. '<div class="form-group">',
  4620. '<input type="text" name="ipv6" data-bv-ip data-bv-ip-ipv4="false" />',
  4621. '</div>',
  4622. '<div class="form-group">',
  4623. '<input type="text" name="both" data-bv-ip />',
  4624. '</div>',
  4625. '</form>'
  4626. ].join('\n')).appendTo('body');
  4627. $('#ipForm').bootstrapValidator();
  4628. this.bv = $('#ipForm').data('bootstrapValidator');
  4629. this.$ipv4 = this.bv.getFieldElements('ipv4');
  4630. this.$ipv6 = this.bv.getFieldElements('ipv6');
  4631. this.$both = this.bv.getFieldElements('both');
  4632. });
  4633. afterEach(function() {
  4634. $('#ipForm').bootstrapValidator('destroy').remove();
  4635. });
  4636. it('Valid ipv4', function() {
  4637. this.$ipv4.val('0.0.0.0');
  4638. this.bv.validate();
  4639. expect(this.bv.isValid()).toBeTruthy();
  4640. this.bv.resetForm();
  4641. this.$ipv4.val('192.168.1.1');
  4642. this.bv.validate();
  4643. expect(this.bv.isValid()).toBeTruthy();
  4644. this.bv.resetForm();
  4645. this.$ipv4.val('255.255.255.255');
  4646. this.bv.validate();
  4647. expect(this.bv.isValid()).toBeTruthy();
  4648. });
  4649. it('Invalid ipv4', function() {
  4650. this.$ipv4.val('10.168.0001.100'); // extra 0 not allowed
  4651. this.bv.validate();
  4652. expect(this.bv.isValid()).toEqual(false);
  4653. this.bv.resetForm();
  4654. this.$ipv4.val('0.0.0.256'); // 256 not allowed, max is 255
  4655. this.bv.validate();
  4656. expect(this.bv.isValid()).toEqual(false);
  4657. this.bv.resetForm();
  4658. this.$ipv4.val('256.255.255.255'); // max is 255.255.255.255
  4659. this.bv.validate();
  4660. expect(this.bv.isValid()).toEqual(false);
  4661. this.bv.resetForm();
  4662. this.$ipv4.val('192.168. 224.0'); // internal space
  4663. this.bv.validate();
  4664. expect(this.bv.isValid()).toEqual(false);
  4665. this.bv.resetForm();
  4666. this.$ipv4.val('192.168.224.0 1'); // junk after valid address
  4667. this.bv.validate();
  4668. expect(this.bv.isValid()).toEqual(false);
  4669. });
  4670. it('Valid ipv6', function() {
  4671. this.$ipv6.val('0000:0000:0000:0000:0000:0000:0000:0000');
  4672. this.bv.validate();
  4673. expect(this.bv.isValid()).toBeTruthy();
  4674. this.bv.resetForm();
  4675. this.$ipv6.val('fe00::1');
  4676. this.bv.validate();
  4677. expect(this.bv.isValid()).toBeTruthy();
  4678. this.bv.resetForm();
  4679. this.$ipv6.val('fe80::217:f2ff:fe07:ed62');
  4680. this.bv.validate();
  4681. expect(this.bv.isValid()).toBeTruthy();
  4682. this.bv.resetForm();
  4683. this.$ipv6.val('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff');
  4684. this.bv.validate();
  4685. expect(this.bv.isValid()).toBeTruthy();
  4686. });
  4687. it('Invalid ipv6', function() {
  4688. this.$ipv6.val('02001:0000:1234:0000:0000:C1C0:ABCD:0876'); // extra 0 not allowed
  4689. this.bv.validate();
  4690. expect(this.bv.isValid()).toEqual(false);
  4691. this.bv.resetForm();
  4692. this.$ipv6.val('2001:0000:1234:0000:00001:C1C0:ABCD:0876'); // extra 0 not allowed
  4693. this.bv.validate();
  4694. expect(this.bv.isValid()).toEqual(false);
  4695. this.bv.resetForm();
  4696. this.$ipv6.val('2001:0000:1234: 0000:0000:C1C0:ABCD:0876'); // internal space
  4697. this.bv.validate();
  4698. expect(this.bv.isValid()).toEqual(false);
  4699. this.bv.resetForm();
  4700. this.$ipv6.val('2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'); // junk after valid address
  4701. this.bv.validate();
  4702. expect(this.bv.isValid()).toEqual(false);
  4703. this.bv.resetForm();
  4704. this.$ipv6.val('3ffe:0b00:0000:0001:0000:0000:000a'); // seven segment
  4705. this.bv.validate();
  4706. expect(this.bv.isValid()).toEqual(false);
  4707. this.bv.resetForm();
  4708. this.$ipv6.val('FF02:0000:0000:0000:0000:0000:0000:0000:0001'); // nine segment
  4709. this.bv.validate();
  4710. expect(this.bv.isValid()).toEqual(false);
  4711. this.bv.resetForm();
  4712. this.$ipv6.val('::1111:2222:3333:4444:5555:6666::'); // double "::"
  4713. this.bv.validate();
  4714. expect(this.bv.isValid()).toEqual(false);
  4715. this.bv.resetForm();
  4716. this.$ipv6.val('3ffe:b00::1::a'); // double "::"
  4717. this.bv.validate();
  4718. expect(this.bv.isValid()).toEqual(false);
  4719. });
  4720. it('Both', function() {
  4721. this.$both.val('255.255.255.255'); // valid
  4722. this.bv.validate();
  4723. expect(this.bv.isValid()).toBeTruthy();
  4724. this.bv.resetForm();
  4725. this.$both.val('256.0.0.0'); // 256 not allowed, max is 255
  4726. this.bv.validate();
  4727. expect(this.bv.isValid()).toEqual(false);
  4728. this.bv.resetForm();
  4729. this.$both.val('2001:0db8:0000:85a3:0000:0000:ac1f:8001'); // valid
  4730. this.bv.validate();
  4731. expect(this.bv.isValid()).toBeTruthy();
  4732. this.bv.resetForm();
  4733. this.$both.val('2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'); // junk after valid address
  4734. this.bv.validate();
  4735. expect(this.bv.isValid()).toEqual(false);
  4736. });
  4737. });
  4738. describe('isbn', function() {
  4739. beforeEach(function() {
  4740. var html = [
  4741. '<div class="container">',
  4742. '<form class="form-horizontal" id="isbnForm">',
  4743. '<div class="form-group">',
  4744. '<input type="text" name="isbn" data-bv-isbn />',
  4745. '</div>',
  4746. '</form>',
  4747. '</div>'
  4748. ].join('\n');
  4749. $(html).appendTo('body');
  4750. $('#isbnForm').bootstrapValidator();
  4751. this.bv = $('#isbnForm').data('bootstrapValidator');
  4752. this.$isbn = this.bv.getFieldElements('isbn');
  4753. });
  4754. afterEach(function() {
  4755. $('#isbnForm').bootstrapValidator('destroy').parent().remove();
  4756. });
  4757. it('isbn10 hyphen', function() {
  4758. var samples = ['99921-58-10-7', '9971-5-0210-0', '960-425-059-0', '80-902734-1-6'];
  4759. for (var i in samples) {
  4760. this.$isbn.val(samples[i]);
  4761. this.bv.validate();
  4762. expect(this.bv.isValidField('isbn')).toBeTruthy();
  4763. }
  4764. });
  4765. it('isbn10 space', function() {
  4766. var samples = ['85 359 0277 5', '1 84356 028 3', '0 684 84328 5', '0 85131 041 9', '0 943396 04 2'];
  4767. for (var i in samples) {
  4768. this.$isbn.val(samples[i]);
  4769. this.bv.validate();
  4770. expect(this.bv.isValidField('isbn')).toBeTruthy();
  4771. }
  4772. });
  4773. it('isbn10 hyphen with X', function() {
  4774. var samples = ['0-8044-2957-X', '0-9752298-0-X'];
  4775. for (var i in samples) {
  4776. this.$isbn.val(samples[i]);
  4777. this.bv.validate();
  4778. expect(this.bv.isValidField('isbn')).toBeTruthy();
  4779. }
  4780. });
  4781. it('isbn10 invalid check digit', function() {
  4782. this.$isbn.val('99921-58-10-6');
  4783. this.bv.validate();
  4784. expect(this.bv.isValidField('isbn')).toEqual(false);
  4785. });
  4786. it('isbn13', function() {
  4787. this.$isbn.val('978-0-306-40615-7');
  4788. this.bv.validate();
  4789. expect(this.bv.isValidField('isbn')).toBeTruthy();
  4790. });
  4791. it('isbn13 invalid check digit', function() {
  4792. this.$isbn.val('978-0-306-40615-6');
  4793. this.bv.validate();
  4794. expect(this.bv.isValidField('isbn')).toEqual(false);
  4795. });
  4796. });
  4797. describe('isin', function() {
  4798. beforeEach(function() {
  4799. var html = [
  4800. '<div class="container">',
  4801. '<form class="form-horizontal" id="isinForm">',
  4802. '<div class="form-group">',
  4803. '<input type="text" name="isin" data-bv-isin />',
  4804. '</div>',
  4805. '</form>',
  4806. '</div>'
  4807. ].join('\n');
  4808. $(html).appendTo('body');
  4809. $('#isinForm').bootstrapValidator();
  4810. this.bv = $('#isinForm').data('bootstrapValidator');
  4811. this.$isin = this.bv.getFieldElements('isin');
  4812. });
  4813. afterEach(function() {
  4814. $('#isinForm').bootstrapValidator('destroy').parent().remove();
  4815. });
  4816. it('valid', function() {
  4817. var samples = ['US0378331005', 'AU0000XVGZA3', 'GB0002634946'];
  4818. for (var i in samples) {
  4819. this.$isin.val(samples[i]);
  4820. this.bv.validate();
  4821. expect(this.bv.isValidField('isin')).toBeTruthy();
  4822. }
  4823. });
  4824. it('invalid country code', function() {
  4825. this.$isin.val('AA0000XVGZA3');
  4826. this.bv.validate();
  4827. expect(this.bv.isValidField('isin')).toEqual(false);
  4828. });
  4829. it('contains only digits and alphabet', function() {
  4830. this.$isin.val('US12345ABC@#$');
  4831. this.bv.validate();
  4832. expect(this.bv.isValidField('isin')).toEqual(false);
  4833. });
  4834. it('invalid length', function() {
  4835. this.$isin.val('US1234567');
  4836. this.bv.validate();
  4837. expect(this.bv.isValidField('isin')).toEqual(false);
  4838. });
  4839. it('invalid check digit', function() {
  4840. this.$isin.val('US0378331004');
  4841. this.bv.validate();
  4842. expect(this.bv.isValidField('isin')).toEqual(false);
  4843. });
  4844. });
  4845. describe('ismn', function() {
  4846. beforeEach(function() {
  4847. var html = [
  4848. '<div class="container">',
  4849. '<form class="form-horizontal" id="ismnForm">',
  4850. '<div class="form-group">',
  4851. '<input type="text" name="ismn" data-bv-ismn />',
  4852. '</div>',
  4853. '</form>',
  4854. '</div>'
  4855. ].join('\n');
  4856. $(html).appendTo('body');
  4857. $('#ismnForm').bootstrapValidator();
  4858. this.bv = $('#ismnForm').data('bootstrapValidator');
  4859. this.$ismn = this.bv.getFieldElements('ismn');
  4860. });
  4861. afterEach(function() {
  4862. $('#ismnForm').bootstrapValidator('destroy').parent().remove();
  4863. });
  4864. it('valid start with M', function() {
  4865. this.$ismn.val('M230671187');
  4866. this.bv.validate();
  4867. expect(this.bv.isValidField('ismn')).toBeTruthy();
  4868. });
  4869. it('valid start with 979', function() {
  4870. this.$ismn.val('9790060115615');
  4871. this.bv.validate();
  4872. expect(this.bv.isValidField('ismn')).toBeTruthy();
  4873. });
  4874. it('valid contains spaces', function() {
  4875. this.$ismn.val('979 0 3452 4680 5');
  4876. this.bv.validate();
  4877. expect(this.bv.isValidField('ismn')).toBeTruthy();
  4878. });
  4879. it('valid contains dashes', function() {
  4880. this.$ismn.val('979-0-0601-1561-5');
  4881. this.bv.validate();
  4882. expect(this.bv.isValidField('ismn')).toBeTruthy();
  4883. });
  4884. it('invalid format', function() {
  4885. this.$ismn.val('N123456789');
  4886. this.bv.validate();
  4887. expect(this.bv.isValidField('ismn')).toEqual(false);
  4888. });
  4889. it('invalid check digit', function() {
  4890. this.$ismn.val('9790060115614');
  4891. this.bv.validate();
  4892. expect(this.bv.isValidField('ismn')).toEqual(false);
  4893. });
  4894. });
  4895. describe('issn', function() {
  4896. beforeEach(function() {
  4897. var html = [
  4898. '<div class="container">',
  4899. '<form class="form-horizontal" id="issnForm">',
  4900. '<div class="form-group">',
  4901. '<input type="text" name="issn" data-bv-issn />',
  4902. '</div>',
  4903. '</form>',
  4904. '</div>'
  4905. ].join('\n');
  4906. $(html).appendTo('body');
  4907. $('#issnForm').bootstrapValidator();
  4908. this.bv = $('#issnForm').data('bootstrapValidator');
  4909. this.$issn = this.bv.getFieldElements('issn');
  4910. });
  4911. afterEach(function() {
  4912. $('#issnForm').bootstrapValidator('destroy').parent().remove();
  4913. });
  4914. it('valid', function() {
  4915. var samples = ['0378-5955', '0024-9319', '0032-1478'];
  4916. for (var i in samples) {
  4917. this.$issn.val(samples[i]);
  4918. this.bv.validate();
  4919. expect(this.bv.isValidField('issn')).toBeTruthy();
  4920. }
  4921. });
  4922. it('not contains hyphen', function() {
  4923. this.$issn.val('03785955');
  4924. this.bv.validate();
  4925. expect(this.bv.isValidField('issn')).toEqual(false);
  4926. });
  4927. it('contains only digits, X', function() {
  4928. this.$issn.val('1234-566A');
  4929. this.bv.validate();
  4930. expect(this.bv.isValidField('issn')).toEqual(false);
  4931. });
  4932. it('invalid check sum', function() {
  4933. this.$issn.val('0032-147X');
  4934. this.bv.validate();
  4935. expect(this.bv.isValidField('issn')).toEqual(false);
  4936. });
  4937. });
  4938. function lessThanCompare() {
  4939. var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
  4940. $('#msg').html('lessThanCompare() called; compare to ' + compareTo);
  4941. return compareTo;
  4942. };
  4943. TestSuite = $.extend({}, TestSuite, {
  4944. lessThan: {
  4945. compareTo: function(value, validator, $field) {
  4946. var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
  4947. $('#msg').html('TestSuite.lessThan.compareTo() called; compare to ' + compareTo);
  4948. return compareTo;
  4949. }
  4950. }
  4951. });
  4952. describe('lessThan', function() {
  4953. beforeEach(function() {
  4954. $([
  4955. '<form class="form-horizontal" id="lessThanForm">',
  4956. '<div id="msg"></div>',
  4957. '<div class="form-group">',
  4958. '<input type="text" name="maxAge" />',
  4959. '</div>',
  4960. '<div class="form-group">',
  4961. '<input type="text" name="age" data-bv-lessthan data-bv-lessthan-value="100" />',
  4962. '</div>',
  4963. '</form>'
  4964. ].join('\n')).appendTo('body');
  4965. $('#lessThanForm').bootstrapValidator();
  4966. this.bv = $('#lessThanForm').data('bootstrapValidator');
  4967. this.$maxAge = this.bv.getFieldElements('maxAge');
  4968. this.$age = this.bv.getFieldElements('age');
  4969. });
  4970. afterEach(function() {
  4971. $('#lessThanForm').bootstrapValidator('destroy').remove();
  4972. });
  4973. it('not a number', function() {
  4974. this.$age.val('20abc');
  4975. this.bv.validate();
  4976. expect(this.bv.isValid()).toEqual(false);
  4977. });
  4978. it('value with coma separator', function() {
  4979. this.$age.val('120,2234');
  4980. this.bv.validate();
  4981. expect(this.bv.isValid()).toEqual(false);
  4982. this.bv.resetForm();
  4983. this.$age.val('30,2234');
  4984. this.bv.validate();
  4985. expect(this.bv.isValid()).toBeTruthy();
  4986. });
  4987. it('compare to value', function() {
  4988. this.$age.val(120);
  4989. this.bv.validate();
  4990. expect(this.bv.isValid()).toEqual(false);
  4991. this.bv.resetForm();
  4992. this.$age.val(30);
  4993. this.bv.validate();
  4994. expect(this.bv.isValid()).toBeTruthy();
  4995. });
  4996. it('compare to other field', function() {
  4997. this.$age.attr('data-bv-lessthan-value', 'maxAge');
  4998. this.bv.destroy();
  4999. this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
  5000. this.$maxAge.val(40);
  5001. this.$age.val(20);
  5002. this.bv.validate();
  5003. expect(this.bv.isValid()).toBeTruthy();
  5004. this.bv.resetForm();
  5005. this.$maxAge.val(20);
  5006. this.$age.val(30);
  5007. this.bv.validate();
  5008. expect(this.bv.isValid()).toEqual(false);
  5009. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
  5010. });
  5011. it('compare to return value of a function', function() {
  5012. this.$age.attr('data-bv-lessthan-value', 'lessThanCompare');
  5013. this.bv.destroy();
  5014. this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
  5015. this.$maxAge.val(50);
  5016. this.$age.val(60);
  5017. this.bv.validate();
  5018. expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 50');
  5019. expect(this.bv.isValid()).toEqual(false);
  5020. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
  5021. this.bv.resetForm();
  5022. this.$maxAge.val(60);
  5023. this.$age.val(30);
  5024. this.bv.validate();
  5025. expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 60');
  5026. expect(this.bv.isValid()).toBeTruthy();
  5027. });
  5028. it('compare to return value of a namespace function', function() {
  5029. this.$age.attr('data-bv-lessthan-value', 'TestSuite.lessThan.compareTo');
  5030. this.bv.destroy();
  5031. this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
  5032. this.$maxAge.val(50);
  5033. this.$age.val(60);
  5034. this.bv.validate();
  5035. expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 50');
  5036. expect(this.bv.isValid()).toEqual(false);
  5037. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
  5038. this.bv.resetForm();
  5039. this.$maxAge.val(60);
  5040. this.$age.val(30);
  5041. this.bv.validate();
  5042. expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 60');
  5043. expect(this.bv.isValid()).toBeTruthy();
  5044. });
  5045. });
  5046. describe('meid', function() {
  5047. beforeEach(function() {
  5048. $([
  5049. '<form class="form-horizontal" id="meidForm">',
  5050. '<div class="form-group">',
  5051. '<input type="text" name="meid" data-bv-meid />',
  5052. '</div>',
  5053. '</form>'
  5054. ].join('\n')).appendTo('body');
  5055. $('#meidForm').bootstrapValidator();
  5056. this.bv = $('#meidForm').data('bootstrapValidator');
  5057. this.$meid = this.bv.getFieldElements('meid');
  5058. });
  5059. afterEach(function() {
  5060. $('#meidForm').bootstrapValidator('destroy').remove();
  5061. });
  5062. it('Valid MEID (14 hex, check digit)', function() {
  5063. this.bv.resetForm();
  5064. this.$meid.val('A00000049259B16');
  5065. this.bv.validate();
  5066. expect(this.bv.isValid()).toBeTruthy();
  5067. });
  5068. it('Valid MEID (14 hex, dashes, check digit)', function() {
  5069. this.bv.resetForm();
  5070. this.$meid.val('A0-000004-9259B1-6');
  5071. this.bv.validate();
  5072. expect(this.bv.isValid()).toBeTruthy();
  5073. });
  5074. it('Valid MEID (14 hex, spaces, check digit)', function() {
  5075. this.bv.resetForm();
  5076. this.$meid.val('A0 000004 9259B1 6');
  5077. this.bv.validate();
  5078. expect(this.bv.isValid()).toBeTruthy();
  5079. });
  5080. it('Valid MEID (18 dec, check digit)', function() {
  5081. this.bv.resetForm();
  5082. this.$meid.val('2936087365007037100');
  5083. this.bv.validate();
  5084. expect(this.bv.isValid()).toBeTruthy();
  5085. });
  5086. it('Valid MEID (18 dec, dashes, check digit)', function() {
  5087. this.bv.resetForm();
  5088. this.$meid.val('29360-87365-0070-3710-0');
  5089. this.bv.validate();
  5090. expect(this.bv.isValid()).toBeTruthy();
  5091. });
  5092. it('Valid MEID (18 dec, spaces, check digit)', function() {
  5093. this.bv.resetForm();
  5094. this.$meid.val('29360 87365 0070 3710 0');
  5095. this.bv.validate();
  5096. expect(this.bv.isValid()).toBeTruthy();
  5097. });
  5098. it('Valid MEID (14 hex)', function() {
  5099. this.bv.resetForm();
  5100. this.$meid.val('AF0123450ABCDE');
  5101. this.bv.validate();
  5102. expect(this.bv.isValid()).toBeTruthy();
  5103. });
  5104. it('Valid MEID (14 hex, dashes)', function() {
  5105. this.bv.resetForm();
  5106. this.$meid.val('AF-012345-0ABCDE');
  5107. this.bv.validate();
  5108. expect(this.bv.isValid()).toBeTruthy();
  5109. });
  5110. it('Valid MEID (14 hex, spaces)', function() {
  5111. this.bv.resetForm();
  5112. this.$meid.val('AF 012345 0ABCDE');
  5113. this.bv.validate();
  5114. expect(this.bv.isValid()).toBeTruthy();
  5115. });
  5116. it('Valid MEID (18 dec)', function() {
  5117. this.bv.resetForm();
  5118. this.$meid.val('293608736500703710');
  5119. this.bv.validate();
  5120. expect(this.bv.isValid()).toBeTruthy();
  5121. });
  5122. it('Valid MEID (18 dec, dashes)', function() {
  5123. this.bv.resetForm();
  5124. this.$meid.val('29360-87365-0070-3710');
  5125. this.bv.validate();
  5126. expect(this.bv.isValid()).toBeTruthy();
  5127. });
  5128. it('Valid MEID (18 dec, spaces)', function() {
  5129. this.bv.resetForm();
  5130. this.$meid.val('29360 87365 0070 3710');
  5131. this.bv.validate();
  5132. expect(this.bv.isValid()).toBeTruthy();
  5133. });
  5134. it('Invalid MEID (14 hex, bad check digit)', function() {
  5135. this.bv.resetForm();
  5136. this.$meid.val('A00000049259B15');
  5137. this.bv.validate();
  5138. expect(this.bv.isValid()).toBeFalsy();
  5139. });
  5140. it('Invalid MEID (13 hex)', function() {
  5141. this.bv.resetForm();
  5142. this.$meid.val('A00000049259B');
  5143. this.bv.validate();
  5144. expect(this.bv.isValid()).toBeFalsy();
  5145. });
  5146. it('Invalid MEID (18 dec, bad check digit)', function() {
  5147. this.bv.resetForm();
  5148. this.$meid.val('2936087365007037101');
  5149. this.bv.validate();
  5150. expect(this.bv.isValid()).toBeFalsy();
  5151. });
  5152. it('Invalid MEID (17 dec)', function() {
  5153. this.bv.resetForm();
  5154. this.$meid.val('29360873650070371');
  5155. this.bv.validate();
  5156. expect(this.bv.isValid()).toBeFalsy();
  5157. });
  5158. });
  5159. describe('phone', function() {
  5160. beforeEach(function() {
  5161. $([
  5162. '<form class="form-horizontal" id="phoneForm">',
  5163. '<div class="form-group">',
  5164. '<select class="form-control" name="country">',
  5165. '<option value="BR">Brazil</option>',
  5166. '<option value="CN">China</option>',
  5167. '<option value="CZ">Czech Republic</option>',
  5168. '<option value="DE">Gemany</option>',
  5169. '<option value="DK">Denmark</option>',
  5170. '<option value="ES">Spain</option>',
  5171. '<option value="FR">France</option>',
  5172. '<option value="GB">United Kingdom</option>',
  5173. '<option value="MA">Morocco</option>',
  5174. '<option value="PK">Pakistan</option>',
  5175. '<option value="RO">Romania</option>',
  5176. '<option value="RU">Russia</option>',
  5177. '<option value="SK">Slovakia</option>',
  5178. '<option value="TH">Thailand</option>',
  5179. '<option value="US">USA</option>',
  5180. '<option value="VE">Venezuela</option>',
  5181. '</select>',
  5182. '</div>',
  5183. '<div class="form-group">',
  5184. '<input type="text" name="phone" data-bv-phone />',
  5185. '</div>',
  5186. '</form>',
  5187. ].join('\n')).appendTo('body');
  5188. $('#phoneForm').bootstrapValidator();
  5189. /**
  5190. * @type {BootstrapValidator}
  5191. */
  5192. this.bv = $('#phoneForm').data('bootstrapValidator');
  5193. this.$country = this.bv.getFieldElements('country');
  5194. this.$phone = this.bv.getFieldElements('phone');
  5195. });
  5196. afterEach(function() {
  5197. $('#phoneForm').bootstrapValidator('destroy').remove();
  5198. });
  5199. it('dynamic country', function() {
  5200. this.$phone.attr('data-bv-phone-country', 'country');
  5201. this.bv.destroy();
  5202. this.bv = $('#phoneForm').bootstrapValidator().data('bootstrapValidator');
  5203. this.$country.val('BR');
  5204. this.$phone.val('16920894635');
  5205. this.bv.validate();
  5206. expect(this.bv.isValid()).toBeTruthy();
  5207. this.bv.resetForm();
  5208. this.$country.val('FR');
  5209. this.$phone.val('0644444444');
  5210. this.bv.validate();
  5211. expect(this.bv.isValid()).toBeTruthy();
  5212. this.bv.resetForm();
  5213. this.$country.val('GB');
  5214. this.$phone.val('012345678900');
  5215. this.bv.validate();
  5216. expect(this.bv.isValid()).toBeFalsy();
  5217. });
  5218. it('Brazil phone number', function() {
  5219. this.bv.updateOption('phone', 'phone', 'country', 'BR');
  5220. // Valid samples
  5221. var validSamples = [
  5222. '0800.000.00.00', '0800-000-00-00', '0800 000 00 00', '0800-00-00-00', '0800.00.00.00', '0800 00 00 00',
  5223. '0800-000-0000', '0800 000 0000', '0800.000.0000', '08000000000',
  5224. '1692089-4635', '16920894635', '16992089-4635', '16 99202-4635', '(16)99202-4635', '(16)92089-4635',
  5225. '(16) 92089-4635', '(15) 4343-4343', '+55 15 3702-7523', '(+55) 15 3702-7523', '(+55)1537027523',
  5226. '(+55)(15)3702-7523', '(+55) 15 3702-7523', '(+55) 15 99202-7523', '99202-4635', '(16) 9208-4635'
  5227. ];
  5228. for (var i in validSamples) {
  5229. this.bv.resetForm();
  5230. this.$phone.val(validSamples[i]);
  5231. this.bv.validate();
  5232. expect(this.bv.isValid()).toBeTruthy();
  5233. }
  5234. });
  5235. it('China phone number', function() {
  5236. this.bv.updateOption('phone', 'phone', 'country', 'CN');
  5237. // Valid samples
  5238. var validSamples = [
  5239. '18911111111', '189 1111 1111', '189-1111-1111', '0086-18911111111', '+86-18911111111',
  5240. '86-18911111111', '0086 18911111111', '+86 18911111111', '86 18911111111', '0086 189-1111-1111',
  5241. '+86 189-1111-1111', '86 189-1111-1111', '02011111111', '020-11111111', '020 11111111',
  5242. '020 1111 1111', '020-1111-1111', '0086 020 82803159', '0086-020-82803159', '0086-020-82803159',
  5243. '+86 20 61302222-8866', '+86 20 6130-2222-8866', '+86 10 59081185'
  5244. ];
  5245. for (var i in validSamples) {
  5246. this.bv.resetForm();
  5247. this.$phone.val(validSamples[i]);
  5248. this.bv.validate();
  5249. expect(this.bv.isValid()).toBeTruthy();
  5250. }
  5251. });
  5252. it('Czech Republic phone number', function() {
  5253. this.bv.updateOption('phone', 'phone', 'country', 'CZ');
  5254. // Valid samples
  5255. var validSamples = [
  5256. '00420123456789', '00420 123456789', '00420 123 456 789', '00 420 123 456 789',
  5257. '+420123456789', '+420 123456789', '+420 123 456 789', '123456789', '123 456 789'
  5258. ];
  5259. for (var i in validSamples) {
  5260. this.bv.resetForm();
  5261. this.$phone.val(validSamples[i]);
  5262. this.bv.validate();
  5263. expect(this.bv.isValid()).toBeTruthy();
  5264. }
  5265. // Invalid samples
  5266. var invalidSamples = [
  5267. '420123456789', '420 123456789', '420 123 456 789', '00421123456789', '00421 123456789',
  5268. '00421 123 456 789', '00 421 123 456 789', '+421123456789', '+421 123456789',
  5269. '+421 123 456 789'
  5270. ];
  5271. for (i in invalidSamples) {
  5272. this.bv.resetForm();
  5273. this.$phone.val(invalidSamples[i]);
  5274. this.bv.validate();
  5275. expect(this.bv.isValid()).toEqual(false);
  5276. }
  5277. });
  5278. it('France phone number', function() {
  5279. this.bv.updateOption('phone', 'phone', 'country', 'FR');
  5280. // Valid samples
  5281. var validSamples = [
  5282. // National formats
  5283. '0644444444', '06 44 44 44 44', '06-44-44-44-44', '06.44.44.44.44',
  5284. // International formats
  5285. '+33644444444', '+336.44.44.44.44', '+33 6.44.44.44.44', '0033644444444', '00336.44.44.44.44',
  5286. '0033 6.44.44.44.44',
  5287. // Some times
  5288. '+33(0)644444444', '+33 (0) 644444444'
  5289. ];
  5290. for (var i in validSamples) {
  5291. this.bv.resetForm();
  5292. this.$phone.val(validSamples[i]);
  5293. this.bv.validate();
  5294. expect(this.bv.isValid()).toBeTruthy();
  5295. }
  5296. // Invalid samples
  5297. var invalidSamples = [
  5298. // The separator between pairs of digits is not the same
  5299. '06 44.44-44.44', '06 44 44-44.44', '06 44 44-4444', '06 44 44-4444',
  5300. // Too many digits
  5301. '06444444444444',
  5302. // Missing leading 0
  5303. '6644444444',
  5304. // Too much non-numeric characters
  5305. '06 44.44-44.44', '+33 (0) 644444444',
  5306. // Bad parenthesis
  5307. '(0)644444444',
  5308. // Bad separator after the international prefix
  5309. '+33-(0)-644444444', '+33 (0)-644444444', '+33-(0) 644444444',
  5310. // Trailing separator
  5311. '06.44.44.44.44.'
  5312. ];
  5313. for (i in invalidSamples) {
  5314. this.bv.resetForm();
  5315. this.$phone.val(invalidSamples[i]);
  5316. this.bv.validate();
  5317. expect(this.bv.isValid()).toEqual(false);
  5318. }
  5319. });
  5320. it('Germany phone number', function() {
  5321. this.bv.updateOption('phone', 'phone', 'country', 'DE');
  5322. // Valid samples
  5323. var validSamples = ['+49(89)123456', '089-1234567', '0891234567', '0049-89-123456', '089 123456-78'];
  5324. for (var i in validSamples) {
  5325. this.bv.resetForm();
  5326. this.$phone.val(validSamples[i]);
  5327. this.bv.validate();
  5328. expect(this.bv.isValid()).toBeTruthy();
  5329. }
  5330. });
  5331. it('United Kingdom phone number', function() {
  5332. this.bv.updateOption('phone', 'phone', 'country', 'GB');
  5333. // Valid samples
  5334. var validSamples = [
  5335. // National formats
  5336. '01611234567', '0161 123 4567', '(0161) 123 4567', '0161-123-4567',
  5337. // International formats
  5338. '+44 161 123 4567', '+441611234567', '+44(0)161234567', '00 44 161 1234567', '(011) 44 161 234567', '0161-158-5587',
  5339. // Extensions
  5340. '0161 123 4567 ext. 123', '01611234567x123', '+44161234567x123', '+44 (0) 161 1234567 ext 123'
  5341. ];
  5342. for (var i in validSamples) {
  5343. this.bv.resetForm();
  5344. this.$phone.val(validSamples[i]);
  5345. this.bv.validate();
  5346. expect(this.bv.isValid()).toBeTruthy();
  5347. }
  5348. // Invalid samples
  5349. var invalidSamples = [
  5350. '012345678900', // Too many digits
  5351. '1611234567', // Missing trunk
  5352. '012345678', // Not enough digits
  5353. '123 4567', // Missing area code
  5354. '061 123 4567' // Invalid area code
  5355. ];
  5356. for (i in invalidSamples) {
  5357. this.bv.resetForm();
  5358. this.$phone.val(invalidSamples[i]);
  5359. this.bv.validate();
  5360. expect(this.bv.isValid()).toEqual(false);
  5361. }
  5362. });
  5363. it('Morocco phone number', function() {
  5364. this.bv.updateOption('phone', 'phone', 'country', 'MA');
  5365. // Valid samples
  5366. var validSamples = [
  5367. // National formats
  5368. '0644444444', '0610245896', '0630548564', '06 44 44 44 44', '06-44-44-44-44', '06.44.44.44.44', '06 44.44-44.44',
  5369. '0528254856', '0535484541', '05 28 44 44 44', '05-28-44.44.44', '05.28.44.44.44', '05 28.44-44.44',
  5370. // International formats
  5371. '+212644444444', '+2126.44.44.44.44', '+212 6.44.44.44.44', '00212644444444', '002126.44.44.44.44', '00212 6.44.44.44.44',
  5372. // Some times
  5373. '+212(0)644444444', '+212 (0) 644444444'
  5374. ];
  5375. for (var i in validSamples) {
  5376. this.bv.resetForm();
  5377. this.$phone.val(validSamples[i]);
  5378. this.bv.validate();
  5379. expect(this.bv.isValid()).toBeTruthy();
  5380. }
  5381. // Invalid samples
  5382. var invalidSamples = [
  5383. '0625468961', '0512548632', '0542564896', // Not a valid phone numbers
  5384. '06444444444444', // Too many digits
  5385. '6644444444', // Missing leading 0
  5386. '06 44.44-44.44', '+212 (0) 644444444', // Too much non-numeric characters
  5387. '(0)644444444' // Bad parenthesis
  5388. ];
  5389. for (i in invalidSamples) {
  5390. this.bv.resetForm();
  5391. this.$phone.val(invalidSamples[i]);
  5392. this.bv.validate();
  5393. expect(this.bv.isValid()).toEqual(false);
  5394. }
  5395. });
  5396. it('Pakistan phone number', function() {
  5397. this.bv.updateOption('phone', 'phone', 'country', 'PK');
  5398. // Valid samples
  5399. var validSamples = ['03336527366'];
  5400. for (var i in validSamples) {
  5401. this.bv.resetForm();
  5402. this.$phone.val(validSamples[i]);
  5403. this.bv.validate();
  5404. expect(this.bv.isValid()).toBeTruthy();
  5405. }
  5406. });
  5407. it('Romania phone number', function() {
  5408. this.bv.updateOption('phone', 'phone', 'country', 'RO');
  5409. // Valid samples
  5410. var validSamples = [
  5411. '+40213-564-864', '+40213.564.864', '+40213 564 864', '0213-564-864',
  5412. '0213564864', '0313564864',
  5413. '0720512346', '0730512346', '0740512346', '0750512346', '+40750512346', '+40750.512.346',
  5414. '0760512346', '0770512346', '0780512346'
  5415. ];
  5416. for (var i in validSamples) {
  5417. this.bv.resetForm();
  5418. this.$phone.val(validSamples[i]);
  5419. this.bv.validate();
  5420. expect(this.bv.isValid()).toBeTruthy();
  5421. }
  5422. // Invalid samples
  5423. var invalidSamples = [
  5424. '0213/564/864', // Invalid separator
  5425. '0413564864', // Invalid land line number (The valid one should be +402, +403 or inside country 02 - 03)
  5426. '0790512346' // Invalid mobile phone number (The valid one is 072xxxxxxx - 078xxxxxxx)
  5427. ];
  5428. for (i in invalidSamples) {
  5429. this.bv.resetForm();
  5430. this.$phone.val(invalidSamples[i]);
  5431. this.bv.validate();
  5432. expect(this.bv.isValid()).toEqual(false);
  5433. }
  5434. });
  5435. it('Russia phone number', function() {
  5436. this.bv.updateOption('phone', 'phone', 'country', 'RU');
  5437. // Valid samples
  5438. var validSamples = ['+7(911)976-91-04'];
  5439. for (var i in validSamples) {
  5440. this.bv.resetForm();
  5441. this.$phone.val(validSamples[i]);
  5442. this.bv.validate();
  5443. expect(this.bv.isValid()).toBeTruthy();
  5444. }
  5445. });
  5446. it('Slovakia phone number', function() {
  5447. this.bv.updateOption('phone', 'phone', 'country', 'SK');
  5448. // Valid samples
  5449. var validSamples = [
  5450. '00420123456789', '00420 123456789', '00420 123 456 789', '00 420 123 456 789',
  5451. '+420123456789', '+420 123456789', '+420 123 456 789', '123456789', '123 456 789'
  5452. ];
  5453. for (var i in validSamples) {
  5454. this.bv.resetForm();
  5455. this.$phone.val(validSamples[i]);
  5456. this.bv.validate();
  5457. expect(this.bv.isValid()).toBeTruthy();
  5458. }
  5459. // Invalid samples
  5460. var invalidSamples = [
  5461. '420123456789', '420 123456789', '420 123 456 789', '00421123456789', '00421 123456789',
  5462. '00421 123 456 789', '00 421 123 456 789', '+421123456789', '+421 123456789',
  5463. '+421 123 456 789'
  5464. ];
  5465. for (i in invalidSamples) {
  5466. this.bv.resetForm();
  5467. this.$phone.val(invalidSamples[i]);
  5468. this.bv.validate();
  5469. expect(this.bv.isValid()).toEqual(false);
  5470. }
  5471. });
  5472. });
  5473. describe('stringLength', function() {
  5474. beforeEach(function() {
  5475. $([
  5476. '<form class="form-horizontal" id="stringLengthForm">',
  5477. '<div class="form-group">',
  5478. '<input type="text" name="textCharMaxLength" data-bv-stringlength data-bv-stringlength-max="10" />',
  5479. '</div>',
  5480. '<div class="form-group">',
  5481. '<textarea name="textareaCharMaxLength" data-bv-stringlength data-bv-stringlength-max="10"></textarea>',
  5482. '</div>',
  5483. '<div class="form-group">',
  5484. '<input type="text" name="textUTF8BytesMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-max="10" />',
  5485. '</div>',
  5486. '<div class="form-group">',
  5487. '<textarea name="textareaUTF8BytesMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-max="10"></textarea>',
  5488. '</div>',
  5489. '<div class="form-group">',
  5490. '<input type="text" name="textCharMinLength" data-bv-stringlength data-bv-stringlength-min="5" />',
  5491. '</div>',
  5492. '<div class="form-group">',
  5493. '<textarea name="textareaCharMinLength" data-bv-stringlength data-bv-stringlength-min="5"></textarea>',
  5494. '</div>',
  5495. '<div class="form-group">',
  5496. '<input type="text" name="textUTF8BytesMinLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" />',
  5497. '</div>',
  5498. '<div class="form-group">',
  5499. '<textarea name="textareaUTF8BytesMinLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5"></textarea>',
  5500. '</div>',
  5501. '<div class="form-group">',
  5502. '<input type="text" name="textCharMinMaxLength" data-bv-stringlength data-bv-stringlength-min="5" data-bv-stringlength-max="10" />',
  5503. '</div>',
  5504. '<div class="form-group">',
  5505. '<textarea name="textareaCharMinMaxLength" data-bv-stringlength data-bv-stringlength-min="5" data-bv-stringlength-max="10"></textarea>',
  5506. '</div>',
  5507. '<div class="form-group">',
  5508. '<input type="text" name="textUTF8BytesMinMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" data-bv-stringlength-max="10" />',
  5509. '</div>',
  5510. '<div class="form-group">',
  5511. '<textarea name="textareaUTF8BytesMinMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" data-bv-stringlength-max="10"></textarea>',
  5512. '</div>',
  5513. '</form>'
  5514. ].join('\n')).appendTo('body');
  5515. $('#stringLengthForm').bootstrapValidator();
  5516. this.bv = $('#stringLengthForm').data('bootstrapValidator');
  5517. this.$textCharMaxLength = this.bv.getFieldElements('textCharMaxLength');
  5518. this.$textareaCharMaxLength = this.bv.getFieldElements('textareaCharMaxLength');
  5519. this.$textUTF8BytesMaxLength = this.bv.getFieldElements('textUTF8BytesMaxLength');
  5520. this.$textareaUTF8BytesMaxLength = this.bv.getFieldElements('textareaUTF8BytesMaxLength');
  5521. this.$textCharMinLength = this.bv.getFieldElements('textCharMinLength');
  5522. this.$textareaCharMinLength = this.bv.getFieldElements('textareaCharMinLength');
  5523. this.$textUTF8BytesMinLength = this.bv.getFieldElements('textUTF8BytesMinLength');
  5524. this.$textareaUTF8BytesMinLength = this.bv.getFieldElements('textareaUTF8BytesMinLength');
  5525. this.$textCharMinMaxLength = this.bv.getFieldElements('textCharMinMaxLength');
  5526. this.$textareaCharMinMaxLength = this.bv.getFieldElements('textareaCharMinMaxLength');
  5527. this.$textUTF8BytesMinMaxLength = this.bv.getFieldElements('textUTF8BytesMinMaxLength');
  5528. this.$textareaUTF8BytesMinMaxLength = this.bv.getFieldElements('textareaUTF8BytesMinMaxLength');
  5529. });
  5530. afterEach(function() {
  5531. $('#stringLengthForm').bootstrapValidator('destroy').remove();
  5532. });
  5533. it('Valid max lengths', function() {
  5534. this.$textCharMaxLength.val('123456789♥');
  5535. this.$textareaCharMaxLength.val('123456789♥');
  5536. this.$textUTF8BytesMaxLength.val('1234567♥');
  5537. this.$textareaUTF8BytesMaxLength.val('1234567♥');
  5538. this.bv.validate();
  5539. expect(this.bv.isValid()).toBeTruthy();
  5540. });
  5541. it('Valid min lengths', function() {
  5542. this.$textCharMinLength.val('1234♥');
  5543. this.$textareaCharMinLength.val('1234♥');
  5544. this.$textUTF8BytesMinLength.val('12♥');
  5545. this.$textareaUTF8BytesMinLength.val('12♥');
  5546. this.bv.validate();
  5547. expect(this.bv.isValid()).toBeTruthy();
  5548. });
  5549. it('Valid min and max lengths', function() {
  5550. this.$textCharMinMaxLength.val('1234♥');
  5551. this.$textareaCharMinMaxLength.val('1234♥');
  5552. this.$textUTF8BytesMinMaxLength.val('12♥');
  5553. this.$textareaUTF8BytesMinMaxLength.val('12♥');
  5554. this.bv.validate();
  5555. expect(this.bv.isValid()).toBeTruthy();
  5556. this.bv.resetForm();
  5557. this.$textCharMinMaxLength.val('123456789♥');
  5558. this.$textareaCharMinMaxLength.val('123456789♥');
  5559. this.$textUTF8BytesMinMaxLength.val('1234567♥');
  5560. this.$textareaUTF8BytesMinMaxLength.val('1234567♥');
  5561. this.bv.validate();
  5562. expect(this.bv.isValid()).toBeTruthy();
  5563. });
  5564. it('Invalid max lengths', function() {
  5565. this.$textCharMaxLength.val('1234567890♥'); // 11 chars when max is 10
  5566. this.bv.validate();
  5567. expect(this.bv.isValid()).toEqual(false);
  5568. this.bv.resetForm();
  5569. this.$textareaCharMaxLength.val('1234567890♥'); // 11 chars when max is 10
  5570. this.bv.validate();
  5571. expect(this.bv.isValid()).toEqual(false);
  5572. this.bv.resetForm();
  5573. this.$textUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10
  5574. this.bv.validate();
  5575. expect(this.bv.isValid()).toEqual(false);
  5576. this.bv.resetForm();
  5577. this.$textareaUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10
  5578. this.bv.validate();
  5579. expect(this.bv.isValid()).toEqual(false);
  5580. });
  5581. it('Invalid min lengths', function() {
  5582. this.$textCharMinLength.val('123♥'); // 4 chars when min is 5
  5583. this.bv.validate();
  5584. expect(this.bv.isValid()).toEqual(false);
  5585. this.bv.resetForm();
  5586. this.$textareaCharMinLength.val('123♥'); // 4 chars when min is 5
  5587. this.bv.validate();
  5588. expect(this.bv.isValid()).toEqual(false);
  5589. this.bv.resetForm();
  5590. this.$textUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5
  5591. this.bv.validate();
  5592. expect(this.bv.isValid()).toEqual(false);
  5593. this.bv.resetForm();
  5594. this.$textareaUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5
  5595. this.bv.validate();
  5596. expect(this.bv.isValid()).toEqual(false);
  5597. });
  5598. it('Invalid min and max lengths', function() {
  5599. this.$textCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10
  5600. this.bv.validate();
  5601. expect(this.bv.isValid()).toEqual(false);
  5602. this.bv.resetForm();
  5603. this.$textareaCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10
  5604. this.bv.validate();
  5605. expect(this.bv.isValid()).toEqual(false);
  5606. this.bv.resetForm();
  5607. this.$textUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10
  5608. this.bv.validate();
  5609. expect(this.bv.isValid()).toEqual(false);
  5610. this.bv.resetForm();
  5611. this.$textareaUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10
  5612. this.bv.validate();
  5613. expect(this.bv.isValid()).toEqual(false);
  5614. this.bv.resetForm();
  5615. this.$textCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10
  5616. this.bv.validate();
  5617. expect(this.bv.isValid()).toEqual(false);
  5618. this.bv.resetForm();
  5619. this.$textareaCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10
  5620. this.bv.validate();
  5621. expect(this.bv.isValid()).toEqual(false);
  5622. this.bv.resetForm();
  5623. this.$textUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10
  5624. this.bv.validate();
  5625. expect(this.bv.isValid()).toEqual(false);
  5626. this.bv.resetForm();
  5627. this.$textareaUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10
  5628. this.bv.validate();
  5629. expect(this.bv.isValid()).toEqual(false);
  5630. });
  5631. it('trim option', function() {
  5632. this.bv.updateOption('textCharMaxLength', 'stringLength', 'trim', false);
  5633. this.$textCharMaxLength.val('');
  5634. this.bv.validate();
  5635. expect(this.bv.isValid()).toEqual(true);
  5636. this.bv.resetForm();
  5637. this.$textCharMaxLength.val(' ');
  5638. this.bv.validate();
  5639. expect(this.bv.isValid()).toEqual(false);
  5640. this.bv.resetForm();
  5641. this.$textCharMaxLength.val('1234567890 ');
  5642. this.bv.validate();
  5643. expect(this.bv.isValid()).toEqual(false);
  5644. this.bv.updateOption('textCharMaxLength', 'stringLength', 'trim', true);
  5645. this.bv.resetForm();
  5646. this.$textCharMaxLength.val(' ');
  5647. this.bv.validate();
  5648. expect(this.bv.isValid()).toEqual(true);
  5649. this.bv.resetForm();
  5650. this.$textCharMaxLength.val(' ');
  5651. this.bv.validate();
  5652. expect(this.bv.isValid()).toEqual(true);
  5653. this.bv.resetForm();
  5654. this.$textCharMaxLength.val(' 0123456789 ');
  5655. this.bv.validate();
  5656. expect(this.bv.isValid()).toEqual(true);
  5657. this.bv.resetForm();
  5658. this.$textCharMaxLength.val(' 01234567890 ');
  5659. this.bv.validate();
  5660. expect(this.bv.isValid()).toEqual(false);
  5661. });
  5662. });
  5663. describe('uri', function() {
  5664. beforeEach(function() {
  5665. $([
  5666. '<form class="form-horizontal" id="uriForm">',
  5667. '<div id="msg"></div>',
  5668. '<div class="form-group">',
  5669. '<input type="text" name="uri" data-bv-uri />',
  5670. '</div>',
  5671. '</form>'
  5672. ].join('\n')).appendTo('body');
  5673. $('#uriForm').bootstrapValidator();
  5674. this.bv = $('#uriForm').data('bootstrapValidator');
  5675. this.$uri = this.bv.getFieldElements('uri');
  5676. });
  5677. afterEach(function() {
  5678. $('#uriForm').bootstrapValidator('destroy').remove();
  5679. });
  5680. var validGlobalURIs = [
  5681. 'http://foo.com/blah_blah',
  5682. 'http://foo.com/blah_blah',
  5683. 'http://foo.com/blah_blah/',
  5684. 'http://foo.com/blah_blah_(wikipedia)',
  5685. 'http://foo.com/blah_blah_(wikipedia)_(again)',
  5686. 'http://www.example.com/wpstyle/?p=364',
  5687. 'https://www.example.com/foo/?bar=baz&inga=42&quux',
  5688. 'http://✪df.ws/123',
  5689. 'http://userid:password@example.com:8080',
  5690. 'http://userid:password@example.com:8080/',
  5691. 'http://userid@example.com',
  5692. 'http://userid@example.com/',
  5693. 'http://userid@example.com:8080',
  5694. 'http://userid@example.com:8080/',
  5695. 'http://userid:password@example.com',
  5696. 'http://userid:password@example.com/',
  5697. 'http://142.42.1.1/',
  5698. 'http://142.42.1.1:8080/',
  5699. 'http://➡.ws/䨹',
  5700. 'http://⌘.ws',
  5701. 'http://⌘.ws/',
  5702. 'http://foo.com/blah_(wikipedia)#cite-1',
  5703. 'http://foo.com/blah_(wikipedia)_blah#cite-1',
  5704. 'http://foo.com/unicode_(✪)_in_parens',
  5705. 'http://foo.com/(something)?after=parens',
  5706. 'http://☺.damowmow.com/',
  5707. 'http://code.google.com/events/#&product=browser',
  5708. 'http://j.mp',
  5709. 'ftp://foo.bar/baz',
  5710. 'http://foo.bar/?q=Test%20URL-encoded%20stuff',
  5711. 'http://مثال.إختبار',
  5712. 'http://例子.测试',
  5713. 'http://उदाहरण.परीक्षा',
  5714. "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
  5715. 'http://1337.net',
  5716. 'http://a.b-c.de',
  5717. 'http://223.255.255.254'
  5718. ];
  5719. var invalidGlobalURIs = [
  5720. 'http://',
  5721. 'http://.',
  5722. 'http://..',
  5723. 'http://../',
  5724. 'http://?',
  5725. 'http://??',
  5726. 'http://??/',
  5727. 'http://#',
  5728. 'http://##',
  5729. 'http://##/',
  5730. 'http://foo.bar?q=Spaces should be encoded',
  5731. '//',
  5732. '//a',
  5733. '///a',
  5734. '///',
  5735. 'http:///a',
  5736. 'foo.com',
  5737. 'rdar://1234',
  5738. 'h://test',
  5739. 'http:// shouldfail.com',
  5740. ':// should fail',
  5741. 'http://foo.bar/foo(bar)baz quux',
  5742. 'ftps://foo.bar/',
  5743. 'http://-error-.invalid/',
  5744. 'http://a.b--c.de/',
  5745. 'http://-a.b.co',
  5746. 'http://a.b-.co',
  5747. 'http://.www.foo.bar/',
  5748. 'http://www.foo.bar./',
  5749. 'http://.www.foo.bar./'
  5750. ];
  5751. var localURIs = [
  5752. 'http://intranetsite',
  5753. 'http://intranetsite/test',
  5754. 'http://intranetsite:80',
  5755. 'http://intranetsite:80/test',
  5756. 'http://user:pass@intranetsite',
  5757. 'http://user:pass@intranetsite/test',
  5758. 'http://user:pass@intranetsite:80',
  5759. 'http://user:pass@intranetsite:80/test',
  5760. 'http://10.1.1.0',
  5761. 'http://10.1.1.255',
  5762. 'http://10.1.1.1',
  5763. 'http://10.1.1.254',
  5764. 'http://127.0.0.1',
  5765. 'http://192.168.0.1',
  5766. 'http://0.0.0.0',
  5767. 'http://224.1.1.1',
  5768. 'http://1.1.1.1.1',
  5769. 'http://123.123.123',
  5770. 'http://3628126748'
  5771. ];
  5772. it('Valid URIs (allowLocal=false)', function() {
  5773. var me = this;
  5774. $.each(validGlobalURIs, function(index, uri) {
  5775. me.bv.resetForm();
  5776. me.$uri.val(uri);
  5777. me.bv.validate();
  5778. expect(me.bv.isValid()).toBeTruthy();
  5779. });
  5780. });
  5781. it('Invalid URIs (allowLocal=false)', function() {
  5782. var me = this;
  5783. $.each(invalidGlobalURIs.concat(localURIs), function(index, uri) {
  5784. me.bv.resetForm();
  5785. me.$uri.val(uri);
  5786. me.bv.validate();
  5787. expect(me.bv.isValid()).toEqual(false);
  5788. });
  5789. });
  5790. it('Valid URIs (allowLocal=true)', function() {
  5791. var me = this;
  5792. me.bv.updateOption('uri', 'uri', 'allowLocal', true);
  5793. $.each(validGlobalURIs.concat(localURIs), function(index, uri) {
  5794. me.bv.resetForm();
  5795. me.$uri.val(uri);
  5796. me.bv.validate();
  5797. expect(me.bv.isValid()).toBeTruthy();
  5798. });
  5799. });
  5800. it('Invalid URIs (allowLocal=true)', function() {
  5801. var me = this;
  5802. me.bv.updateOption('uri', 'uri', 'allowLocal', true);
  5803. $.each(invalidGlobalURIs, function(index, uri) {
  5804. me.bv.resetForm();
  5805. me.$uri.val(uri);
  5806. me.bv.validate();
  5807. expect(me.bv.isValid()).toEqual(false);
  5808. });
  5809. });
  5810. });
  5811. describe('vat', function() {
  5812. beforeEach(function() {
  5813. $([
  5814. '<form class="form-horizontal" id="vatForm">',
  5815. '<div class="form-group">',
  5816. '<select class="form-control" name="country">',
  5817. '<option value="AT">Austria</option>',
  5818. '<option value="BE">Belgium</option>',
  5819. '<option value="BG">Bulgaria</option>',
  5820. '<option value="HR">Croatia</option>',
  5821. '<option value="CY">Cyprus</option>',
  5822. '<option value="CZ">Czech Republic</option>',
  5823. '<option value="DK">Denmark</option>',
  5824. '<option value="EE">Estonia</option>',
  5825. '<option value="FI">Finland</option>',
  5826. '<option value="FR">France</option>',
  5827. '<option value="DE">Germany</option>',
  5828. '<option value="GR">Greece</option>',
  5829. '<option value="HU">Hungary</option>',
  5830. '<option value="IE">Ireland</option>',
  5831. '<option value="IS">Iceland</option>',
  5832. '<option value="IT">Italy</option>',
  5833. '<option value="LV">Latvia</option>',
  5834. '<option value="LT">Lithuania</option>',
  5835. '<option value="LU">Luxembourg</option>',
  5836. '<option value="MT">Malta</option>',
  5837. '<option value="NL">Netherlands</option>',
  5838. '<option value="NO">Norway</option>',
  5839. '<option value="PL">Poland</option>',
  5840. '<option value="PT">Portugal</option>',
  5841. '<option value="RO">Romania</option>',
  5842. '<option value="RU">Russia</option>',
  5843. '<option value="RS">Serbia</option>',
  5844. '<option value="SK">Slovakia</option>',
  5845. '<option value="SI">Slovenia</option>',
  5846. '<option value="ES">Spain</option>',
  5847. '<option value="SE">Sweden</option>',
  5848. '<option value="CH">Switzerland</option>',
  5849. '<option value="GB">United Kingdom</option>',
  5850. '<option value="VE">Venezuela</option>',
  5851. '<option value="ZA">South Africa</option>',
  5852. '</select>',
  5853. '</div>',
  5854. '<div class="form-group">',
  5855. '<input type="text" name="vat" data-bv-vat />',
  5856. '</div>',
  5857. '</form>',
  5858. ].join('\n')).appendTo('body');
  5859. $('#vatForm').bootstrapValidator();
  5860. /**
  5861. * @type {BootstrapValidator}
  5862. */
  5863. this.bv = $('#vatForm').data('bootstrapValidator');
  5864. this.$country = this.bv.getFieldElements('country');
  5865. this.$vat = this.bv.getFieldElements('vat');
  5866. });
  5867. afterEach(function() {
  5868. $('#vatForm').bootstrapValidator('destroy').remove();
  5869. });
  5870. it('dynamic country', function() {
  5871. this.$vat.attr('data-bv-vat-country', 'country');
  5872. this.bv.destroy();
  5873. this.bv = $('#vatForm').bootstrapValidator().data('bootstrapValidator');
  5874. this.$country.val('AT');
  5875. this.$vat.val('ATU13585627');
  5876. this.bv.validate();
  5877. expect(this.bv.isValid()).toBeTruthy();
  5878. this.bv.resetForm();
  5879. this.$country.val('BG');
  5880. this.$vat.val('BE0428759497');
  5881. this.bv.validate();
  5882. expect(this.bv.isValid()).toEqual(false);
  5883. this.bv.resetForm();
  5884. this.$country.val('BE');
  5885. this.$vat.val('BE431150351');
  5886. this.bv.validate();
  5887. expect(this.bv.isValid()).toEqual(false);
  5888. });
  5889. it('Austrian VAT number', function() {
  5890. this.bv.updateOption('vat', 'vat', 'country', 'AT');
  5891. // Valid samples
  5892. var validSamples = ['ATU13585627', 'U13585627'];
  5893. for (var i in validSamples) {
  5894. this.bv.resetForm();
  5895. this.$vat.val(validSamples[i]);
  5896. this.bv.validate();
  5897. expect(this.bv.isValid()).toBeTruthy();
  5898. }
  5899. // Invalid samples
  5900. var invalidSamples = ['ATU13585626', 'U13585626'];
  5901. for (i in invalidSamples) {
  5902. this.bv.resetForm();
  5903. this.$vat.val(invalidSamples[i]);
  5904. this.bv.validate();
  5905. expect(this.bv.isValid()).toEqual(false);
  5906. }
  5907. });
  5908. it('Belgian VAT number', function() {
  5909. this.bv.updateOption('vat', 'vat', 'country', 'BE');
  5910. // Valid samples
  5911. var validSamples = ['BE0428759497', '0428759497'];
  5912. for (var i in validSamples) {
  5913. this.bv.resetForm();
  5914. this.$vat.val(validSamples[i]);
  5915. this.bv.validate();
  5916. expect(this.bv.isValid()).toBeTruthy();
  5917. }
  5918. // Invalid samples
  5919. var invalidSamples = ['BE431150351', '431150351'];
  5920. for (i in invalidSamples) {
  5921. this.bv.resetForm();
  5922. this.$vat.val(invalidSamples[i]);
  5923. this.bv.validate();
  5924. expect(this.bv.isValid()).toEqual(false);
  5925. }
  5926. });
  5927. it('Bulgarian VAT number', function() {
  5928. this.bv.updateOption('vat', 'vat', 'country', 'BG');
  5929. // Valid samples
  5930. var validSamples = ['BG175074752', 'BG7523169263', 'BG8032056031', 'BG7542011030', 'BG7111042925', '175074752', '7523169263', '8032056031'];
  5931. for (var i in validSamples) {
  5932. this.bv.resetForm();
  5933. this.$vat.val(validSamples[i]);
  5934. this.bv.validate();
  5935. expect(this.bv.isValid()).toBeTruthy();
  5936. }
  5937. // Invalid samples
  5938. var invalidSamples = ['BG175074753', 'BG7552A10004', 'BG7111042922', '175074753', '7552A10004'];
  5939. for (i in invalidSamples) {
  5940. this.bv.resetForm();
  5941. this.$vat.val(invalidSamples[i]);
  5942. this.bv.validate();
  5943. expect(this.bv.isValid()).toEqual(false);
  5944. }
  5945. });
  5946. it('Cypriot VAT number', function() {
  5947. this.bv.updateOption('vat', 'vat', 'country', 'CY');
  5948. // Valid samples
  5949. var validSamples = ['CY10259033P', '10259033P'];
  5950. for (var i in validSamples) {
  5951. this.bv.resetForm();
  5952. this.$vat.val(validSamples[i]);
  5953. this.bv.validate();
  5954. expect(this.bv.isValid()).toBeTruthy();
  5955. }
  5956. // Invalid samples
  5957. var invalidSamples = ['CY10259033Z', '10259033Z'];
  5958. for (i in invalidSamples) {
  5959. this.bv.resetForm();
  5960. this.$vat.val(invalidSamples[i]);
  5961. this.bv.validate();
  5962. expect(this.bv.isValid()).toEqual(false);
  5963. }
  5964. });
  5965. it('Czech Republic VAT number', function() {
  5966. this.bv.updateOption('vat', 'vat', 'country', 'CZ');
  5967. // Valid samples
  5968. var validSamples = ['CZ25123891', 'CZ7103192745', 'CZ991231123', 'CZ640903926', '25123891', '7103192745'];
  5969. for (var i in validSamples) {
  5970. this.bv.resetForm();
  5971. this.$vat.val(validSamples[i]);
  5972. this.bv.validate();
  5973. expect(this.bv.isValid()).toBeTruthy();
  5974. }
  5975. // Invalid samples
  5976. var invalidSamples = ['CZ25123890', 'CZ1103492745', 'CZ590312123', '25123890', '1103492745'];
  5977. for (i in invalidSamples) {
  5978. this.bv.resetForm();
  5979. this.$vat.val(invalidSamples[i]);
  5980. this.bv.validate();
  5981. expect(this.bv.isValid()).toEqual(false);
  5982. }
  5983. });
  5984. it('German VAT number', function() {
  5985. this.bv.updateOption('vat', 'vat', 'country', 'DE');
  5986. // Valid samples
  5987. var validSamples = ['DE136695976', '136695976'];
  5988. for (var i in validSamples) {
  5989. this.bv.resetForm();
  5990. this.$vat.val(validSamples[i]);
  5991. this.bv.validate();
  5992. expect(this.bv.isValid()).toBeTruthy();
  5993. }
  5994. // Invalid samples
  5995. var invalidSamples = ['DE136695978', '136695978'];
  5996. for (i in invalidSamples) {
  5997. this.bv.resetForm();
  5998. this.$vat.val(invalidSamples[i]);
  5999. this.bv.validate();
  6000. expect(this.bv.isValid()).toEqual(false);
  6001. }
  6002. });
  6003. it('Danish VAT number', function() {
  6004. this.bv.updateOption('vat', 'vat', 'country', 'DK');
  6005. // Valid samples
  6006. var validSamples = ['DK13585628', '13585628'];
  6007. for (var i in validSamples) {
  6008. this.bv.resetForm();
  6009. this.$vat.val(validSamples[i]);
  6010. this.bv.validate();
  6011. expect(this.bv.isValid()).toBeTruthy();
  6012. }
  6013. // Invalid samples
  6014. var invalidSamples = ['DK13585627', '13585627'];
  6015. for (i in invalidSamples) {
  6016. this.bv.resetForm();
  6017. this.$vat.val(invalidSamples[i]);
  6018. this.bv.validate();
  6019. expect(this.bv.isValid()).toEqual(false);
  6020. }
  6021. });
  6022. it('Estonian VAT number', function() {
  6023. this.bv.updateOption('vat', 'vat', 'country', 'EE');
  6024. // Valid samples
  6025. var validSamples = ['EE100931558', 'EE100594102', '100931558', '100594102'];
  6026. for (var i in validSamples) {
  6027. this.bv.resetForm();
  6028. this.$vat.val(validSamples[i]);
  6029. this.bv.validate();
  6030. expect(this.bv.isValid()).toBeTruthy();
  6031. }
  6032. // Invalid samples
  6033. var invalidSamples = ['EE100594103', '100594103'];
  6034. for (i in invalidSamples) {
  6035. this.bv.resetForm();
  6036. this.$vat.val(invalidSamples[i]);
  6037. this.bv.validate();
  6038. expect(this.bv.isValid()).toEqual(false);
  6039. }
  6040. });
  6041. it('Spanish VAT number (NIF)', function() {
  6042. this.bv.updateOption('vat', 'vat', 'country', 'ES');
  6043. // Valid samples
  6044. var validSamples = ['ES54362315K', 'ESX2482300W', 'ESX5253868R', 'ESM1234567L', 'ESJ99216582', 'ESB58378431', 'ESB64717838', '54362315K', 'X2482300W', 'X5253868R', 'M1234567L', 'J99216582'];
  6045. for (var i in validSamples) {
  6046. this.bv.resetForm();
  6047. this.$vat.val(validSamples[i]);
  6048. this.bv.validate();
  6049. expect(this.bv.isValid()).toBeTruthy();
  6050. }
  6051. // Invalid samples
  6052. var invalidSamples = ['ES54362315Z', 'ESX2482300A', 'ESJ99216583', '54362315Z', 'X2482300A'];
  6053. for (i in invalidSamples) {
  6054. this.bv.resetForm();
  6055. this.$vat.val(invalidSamples[i]);
  6056. this.bv.validate();
  6057. expect(this.bv.isValid()).toEqual(false);
  6058. }
  6059. });
  6060. it('Finnish VAT number', function() {
  6061. this.bv.updateOption('vat', 'vat', 'country', 'FI');
  6062. // Valid samples
  6063. var validSamples = ['FI20774740', '20774740'];
  6064. for (var i in validSamples) {
  6065. this.bv.resetForm();
  6066. this.$vat.val(validSamples[i]);
  6067. this.bv.validate();
  6068. expect(this.bv.isValid()).toBeTruthy();
  6069. }
  6070. // Invalid samples
  6071. var invalidSamples = ['FI20774741', '20774741'];
  6072. for (i in invalidSamples) {
  6073. this.bv.resetForm();
  6074. this.$vat.val(invalidSamples[i]);
  6075. this.bv.validate();
  6076. expect(this.bv.isValid()).toEqual(false);
  6077. }
  6078. });
  6079. it('French VAT number (TVA)', function() {
  6080. this.bv.updateOption('vat', 'vat', 'country', 'FR');
  6081. // Valid samples
  6082. var validSamples = ['FR40303265045', 'FR23334175221', 'FRK7399859412', 'FR4Z123456782', '40303265045', '23334175221', 'K7399859412'];
  6083. for (var i in validSamples) {
  6084. this.bv.resetForm();
  6085. this.$vat.val(validSamples[i]);
  6086. this.bv.validate();
  6087. expect(this.bv.isValid()).toBeTruthy();
  6088. }
  6089. // Invalid samples
  6090. var invalidSamples = ['FR84323140391', '84323140391'];
  6091. for (i in invalidSamples) {
  6092. this.bv.resetForm();
  6093. this.$vat.val(invalidSamples[i]);
  6094. this.bv.validate();
  6095. expect(this.bv.isValid()).toEqual(false);
  6096. }
  6097. });
  6098. it('United Kingdom VAT number', function() {
  6099. this.bv.updateOption('vat', 'vat', 'country', 'GB');
  6100. // Valid samples
  6101. var validSamples = ['GB980780684', '980780684'];
  6102. for (var i in validSamples) {
  6103. this.bv.resetForm();
  6104. this.$vat.val(validSamples[i]);
  6105. this.bv.validate();
  6106. expect(this.bv.isValid()).toBeTruthy();
  6107. }
  6108. // Invalid samples
  6109. var invalidSamples = ['GB802311781', '802311781'];
  6110. for (i in invalidSamples) {
  6111. this.bv.resetForm();
  6112. this.$vat.val(invalidSamples[i]);
  6113. this.bv.validate();
  6114. expect(this.bv.isValid()).toEqual(false);
  6115. }
  6116. });
  6117. it('Greek VAT number', function() {
  6118. this.bv.updateOption('vat', 'vat', 'country', 'GR');
  6119. // Valid samples
  6120. var validSamples = ['GR023456780', 'EL094259216', '023456780', '094259216'];
  6121. for (var i in validSamples) {
  6122. this.bv.resetForm();
  6123. this.$vat.val(validSamples[i]);
  6124. this.bv.validate();
  6125. expect(this.bv.isValid()).toBeTruthy();
  6126. }
  6127. // Invalid samples
  6128. var invalidSamples = ['GR123456781', '123456781'];
  6129. for (i in invalidSamples) {
  6130. this.bv.resetForm();
  6131. this.$vat.val(invalidSamples[i]);
  6132. this.bv.validate();
  6133. expect(this.bv.isValid()).toEqual(false);
  6134. }
  6135. });
  6136. it('Hungarian VAT number', function() {
  6137. this.bv.updateOption('vat', 'vat', 'country', 'HU');
  6138. // Valid samples
  6139. var validSamples = ['HU12892312', '12892312'];
  6140. for (var i in validSamples) {
  6141. this.bv.resetForm();
  6142. this.$vat.val(validSamples[i]);
  6143. this.bv.validate();
  6144. expect(this.bv.isValid()).toBeTruthy();
  6145. }
  6146. // Invalid samples
  6147. var invalidSamples = ['HU12892313', '12892313'];
  6148. for (i in invalidSamples) {
  6149. this.bv.resetForm();
  6150. this.$vat.val(invalidSamples[i]);
  6151. this.bv.validate();
  6152. expect(this.bv.isValid()).toEqual(false);
  6153. }
  6154. });
  6155. it('Croatian VAT number', function() {
  6156. this.bv.updateOption('vat', 'vat', 'country', 'HR');
  6157. // Valid samples
  6158. var validSamples = ['HR33392005961', '33392005961'];
  6159. for (var i in validSamples) {
  6160. this.bv.resetForm();
  6161. this.$vat.val(validSamples[i]);
  6162. this.bv.validate();
  6163. expect(this.bv.isValid()).toBeTruthy();
  6164. }
  6165. // Invalid samples
  6166. var invalidSamples = ['HR33392005962', '33392005962'];
  6167. for (i in invalidSamples) {
  6168. this.bv.resetForm();
  6169. this.$vat.val(invalidSamples[i]);
  6170. this.bv.validate();
  6171. expect(this.bv.isValid()).toEqual(false);
  6172. }
  6173. });
  6174. it('Irish VAT number', function() {
  6175. this.bv.updateOption('vat', 'vat', 'country', 'IE');
  6176. // Valid samples
  6177. var validSamples = ['IE6433435F', 'IE6433435OA', 'IE8D79739I', '6433435F', '6433435OA', '8D79739I'];
  6178. for (var i in validSamples) {
  6179. this.bv.resetForm();
  6180. this.$vat.val(validSamples[i]);
  6181. this.bv.validate();
  6182. expect(this.bv.isValid()).toBeTruthy();
  6183. }
  6184. // Invalid samples
  6185. var invalidSamples = ['IE8D79738J', '8D79738J'];
  6186. for (i in invalidSamples) {
  6187. this.bv.resetForm();
  6188. this.$vat.val(invalidSamples[i]);
  6189. this.bv.validate();
  6190. expect(this.bv.isValid()).toEqual(false);
  6191. }
  6192. });
  6193. it('Iceland VAT (VSK) number', function() {
  6194. this.bv.updateOption('vat', 'vat', 'country', 'IS');
  6195. // Valid samples
  6196. var validSamples = ['IS11111', 'IS111111', '11111', '111111'];
  6197. for (var i in validSamples) {
  6198. this.bv.resetForm();
  6199. this.$vat.val(validSamples[i]);
  6200. this.bv.validate();
  6201. expect(this.bv.isValid()).toBeTruthy();
  6202. }
  6203. // Invalid samples
  6204. var invalidSamples = ['IS1234567', 'IS123456ABC', '1234567', '123456ABC'];
  6205. for (i in invalidSamples) {
  6206. this.bv.resetForm();
  6207. this.$vat.val(invalidSamples[i]);
  6208. this.bv.validate();
  6209. expect(this.bv.isValid()).toEqual(false);
  6210. }
  6211. });
  6212. it('Italian VAT number', function() {
  6213. this.bv.updateOption('vat', 'vat', 'country', 'IT');
  6214. // Valid samples
  6215. var validSamples = ['IT00743110157', '00743110157'];
  6216. for (var i in validSamples) {
  6217. this.bv.resetForm();
  6218. this.$vat.val(validSamples[i]);
  6219. this.bv.validate();
  6220. expect(this.bv.isValid()).toBeTruthy();
  6221. }
  6222. // Invalid samples
  6223. var invalidSamples = ['IT00743110158', '00743110158'];
  6224. for (i in invalidSamples) {
  6225. this.bv.resetForm();
  6226. this.$vat.val(invalidSamples[i]);
  6227. this.bv.validate();
  6228. expect(this.bv.isValid()).toEqual(false);
  6229. }
  6230. });
  6231. it('Lithuanian VAT number', function() {
  6232. this.bv.updateOption('vat', 'vat', 'country', 'LT');
  6233. // Valid samples
  6234. var validSamples = ['LT119511515', 'LT100001919017', 'LT100004801610', '119511515', '100001919017', '100004801610'];
  6235. for (var i in validSamples) {
  6236. this.bv.resetForm();
  6237. this.$vat.val(validSamples[i]);
  6238. this.bv.validate();
  6239. expect(this.bv.isValid()).toBeTruthy();
  6240. }
  6241. // Invalid samples
  6242. var invalidSamples = ['LT100001919018', '100001919018'];
  6243. for (i in invalidSamples) {
  6244. this.bv.resetForm();
  6245. this.$vat.val(invalidSamples[i]);
  6246. this.bv.validate();
  6247. expect(this.bv.isValid()).toEqual(false);
  6248. }
  6249. });
  6250. it('Luxembourg VAT number', function() {
  6251. this.bv.updateOption('vat', 'vat', 'country', 'LU');
  6252. // Valid samples
  6253. var validSamples = ['LU15027442', '15027442'];
  6254. for (var i in validSamples) {
  6255. this.bv.resetForm();
  6256. this.$vat.val(validSamples[i]);
  6257. this.bv.validate();
  6258. expect(this.bv.isValid()).toBeTruthy();
  6259. }
  6260. // Invalid samples
  6261. var invalidSamples = ['LU15027443', '15027443'];
  6262. for (i in invalidSamples) {
  6263. this.bv.resetForm();
  6264. this.$vat.val(invalidSamples[i]);
  6265. this.bv.validate();
  6266. expect(this.bv.isValid()).toEqual(false);
  6267. }
  6268. });
  6269. it('Latvian VAT number', function() {
  6270. this.bv.updateOption('vat', 'vat', 'country', 'LV');
  6271. // Valid samples
  6272. var validSamples = ['LV40003521600', 'LV16117519997', '40003521600', '16117519997'];
  6273. for (var i in validSamples) {
  6274. this.bv.resetForm();
  6275. this.$vat.val(validSamples[i]);
  6276. this.bv.validate();
  6277. expect(this.bv.isValid()).toBeTruthy();
  6278. }
  6279. // Invalid samples
  6280. var invalidSamples = ['LV40003521601', 'LV16137519997', '40003521601', '16137519997'];
  6281. for (i in invalidSamples) {
  6282. this.bv.resetForm();
  6283. this.$vat.val(invalidSamples[i]);
  6284. this.bv.validate();
  6285. expect(this.bv.isValid()).toEqual(false);
  6286. }
  6287. });
  6288. it('Maltese VAT number', function() {
  6289. this.bv.updateOption('vat', 'vat', 'country', 'MT');
  6290. // Valid samples
  6291. var validSamples = ['MT11679112', '11679112'];
  6292. for (var i in validSamples) {
  6293. this.bv.resetForm();
  6294. this.$vat.val(validSamples[i]);
  6295. this.bv.validate();
  6296. expect(this.bv.isValid()).toBeTruthy();
  6297. }
  6298. // Invalid samples
  6299. var invalidSamples = ['MT11679113', '11679113'];
  6300. for (i in invalidSamples) {
  6301. this.bv.resetForm();
  6302. this.$vat.val(invalidSamples[i]);
  6303. this.bv.validate();
  6304. expect(this.bv.isValid()).toEqual(false);
  6305. }
  6306. });
  6307. it('Dutch VAT number', function() {
  6308. this.bv.updateOption('vat', 'vat', 'country', 'NL');
  6309. // Valid samples
  6310. var validSamples = ['NL004495445B01', '004495445B01'];
  6311. for (var i in validSamples) {
  6312. this.bv.resetForm();
  6313. this.$vat.val(validSamples[i]);
  6314. this.bv.validate();
  6315. expect(this.bv.isValid()).toBeTruthy();
  6316. }
  6317. // Invalid samples
  6318. var invalidSamples = ['NL123456789B90', '123456789B90'];
  6319. for (i in invalidSamples) {
  6320. this.bv.resetForm();
  6321. this.$vat.val(invalidSamples[i]);
  6322. this.bv.validate();
  6323. expect(this.bv.isValid()).toEqual(false);
  6324. }
  6325. });
  6326. it('Polish VAT number', function() {
  6327. this.bv.updateOption('vat', 'vat', 'country', 'PL');
  6328. // Valid samples
  6329. var validSamples = ['PL8567346215', '8567346215'];
  6330. for (var i in validSamples) {
  6331. this.bv.resetForm();
  6332. this.$vat.val(validSamples[i]);
  6333. this.bv.validate();
  6334. expect(this.bv.isValid()).toBeTruthy();
  6335. }
  6336. // Invalid samples
  6337. var invalidSamples = ['PL8567346216', '8567346216'];
  6338. for (i in invalidSamples) {
  6339. this.bv.resetForm();
  6340. this.$vat.val(invalidSamples[i]);
  6341. this.bv.validate();
  6342. expect(this.bv.isValid()).toEqual(false);
  6343. }
  6344. });
  6345. it('Portuguese VAT number', function() {
  6346. this.bv.updateOption('vat', 'vat', 'country', 'PT');
  6347. // Valid samples
  6348. var validSamples = ['PT501964843', '501964843'];
  6349. for (var i in validSamples) {
  6350. this.bv.resetForm();
  6351. this.$vat.val(validSamples[i]);
  6352. this.bv.validate();
  6353. expect(this.bv.isValid()).toBeTruthy();
  6354. }
  6355. // Invalid samples
  6356. var invalidSamples = ['PT501964842', '501964842'];
  6357. for (i in invalidSamples) {
  6358. this.bv.resetForm();
  6359. this.$vat.val(invalidSamples[i]);
  6360. this.bv.validate();
  6361. expect(this.bv.isValid()).toEqual(false);
  6362. }
  6363. });
  6364. it('Romanian VAT number', function() {
  6365. this.bv.updateOption('vat', 'vat', 'country', 'RO');
  6366. // Valid samples
  6367. var validSamples = ['RO18547290', '18547290'];
  6368. for (var i in validSamples) {
  6369. this.bv.resetForm();
  6370. this.$vat.val(validSamples[i]);
  6371. this.bv.validate();
  6372. expect(this.bv.isValid()).toBeTruthy();
  6373. }
  6374. // Invalid samples
  6375. var invalidSamples = ['RO18547291', '18547291'];
  6376. for (i in invalidSamples) {
  6377. this.bv.resetForm();
  6378. this.$vat.val(invalidSamples[i]);
  6379. this.bv.validate();
  6380. expect(this.bv.isValid()).toEqual(false);
  6381. }
  6382. });
  6383. it('Russian VAT number', function() {
  6384. this.bv.updateOption('vat', 'vat', 'country', 'RU');
  6385. // Valid samples
  6386. var validSamples = ['RU7805145876', 'RU781300557475', '7805145876', '781300557475'];
  6387. for (var i in validSamples) {
  6388. this.bv.resetForm();
  6389. this.$vat.val(validSamples[i]);
  6390. this.bv.validate();
  6391. expect(this.bv.isValid()).toBeTruthy();
  6392. }
  6393. // Invalid samples
  6394. var invalidSamples = ['RU7805145877', 'RU781300557474', '7805145877', '781300557474'];
  6395. for (i in invalidSamples) {
  6396. this.bv.resetForm();
  6397. this.$vat.val(invalidSamples[i]);
  6398. this.bv.validate();
  6399. expect(this.bv.isValid()).toEqual(false);
  6400. }
  6401. });
  6402. it('Swedish VAT number', function() {
  6403. this.bv.updateOption('vat', 'vat', 'country', 'SE');
  6404. // Valid samples
  6405. var validSamples = ['SE123456789701', '123456789701'];
  6406. for (var i in validSamples) {
  6407. this.bv.resetForm();
  6408. this.$vat.val(validSamples[i]);
  6409. this.bv.validate();
  6410. expect(this.bv.isValid()).toBeTruthy();
  6411. }
  6412. // Invalid samples
  6413. var invalidSamples = ['SE123456789101', '123456789101'];
  6414. for (i in invalidSamples) {
  6415. this.bv.resetForm();
  6416. this.$vat.val(invalidSamples[i]);
  6417. this.bv.validate();
  6418. expect(this.bv.isValid()).toEqual(false);
  6419. }
  6420. });
  6421. it('Slovenian VAT number', function() {
  6422. this.bv.updateOption('vat', 'vat', 'country', 'SI');
  6423. // Valid samples
  6424. var validSamples = ['SI50223054', '50223054'];
  6425. for (var i in validSamples) {
  6426. this.bv.resetForm();
  6427. this.$vat.val(validSamples[i]);
  6428. this.bv.validate();
  6429. expect(this.bv.isValid()).toBeTruthy();
  6430. }
  6431. // Invalid samples
  6432. var invalidSamples = ['SI50223055', '50223055'];
  6433. for (i in invalidSamples) {
  6434. this.bv.resetForm();
  6435. this.$vat.val(invalidSamples[i]);
  6436. this.bv.validate();
  6437. expect(this.bv.isValid()).toEqual(false);
  6438. }
  6439. });
  6440. it('Slovak VAT number', function() {
  6441. this.bv.updateOption('vat', 'vat', 'country', 'SK');
  6442. // Valid samples
  6443. var validSamples = ['SK2022749619', '2022749619'];
  6444. for (var i in validSamples) {
  6445. this.bv.resetForm();
  6446. this.$vat.val(validSamples[i]);
  6447. this.bv.validate();
  6448. expect(this.bv.isValid()).toBeTruthy();
  6449. }
  6450. // Invalid samples
  6451. var invalidSamples = ['SK2022749618', '2022749618'];
  6452. for (i in invalidSamples) {
  6453. this.bv.resetForm();
  6454. this.$vat.val(invalidSamples[i]);
  6455. this.bv.validate();
  6456. expect(this.bv.isValid()).toEqual(false);
  6457. }
  6458. });
  6459. it('South African VAT number', function() {
  6460. this.bv.updateOption('vat', 'vat', 'country', 'ZA');
  6461. // Valid samples
  6462. var validSamples = ['ZA4012345678', '4012345678'];
  6463. for (var i in validSamples) {
  6464. this.bv.resetForm();
  6465. this.$vat.val(validSamples[i]);
  6466. this.bv.validate();
  6467. expect(this.bv.isValid()).toBeTruthy();
  6468. }
  6469. // Invalid samples
  6470. var invalidSamples = ['ZA40123456789', 'ZA0123456789', '40123456789', '0123456789'];
  6471. for (i in invalidSamples) {
  6472. this.bv.resetForm();
  6473. this.$vat.val(invalidSamples[i]);
  6474. this.bv.validate();
  6475. expect(this.bv.isValid()).toEqual(false);
  6476. }
  6477. });
  6478. it('Venezuelan VAT number (RIF)', function() {
  6479. this.bv.updateOption('vat', 'vat', 'country', 'VE');
  6480. // Valid samples
  6481. var validSamples = ['VEJ309272292', 'VEV242818101', 'VEJ000126518', 'VEJ000458324', 'J309272292', 'V242818101', 'J000126518', 'J000458324'];
  6482. for (var i in validSamples) {
  6483. this.bv.resetForm();
  6484. this.$vat.val(validSamples[i]);
  6485. this.bv.validate();
  6486. expect(this.bv.isValid()).toBeTruthy();
  6487. }
  6488. // Invalid samples
  6489. var invalidSamples = ['VEJ309272293', 'VEV242818100', 'J000126519', 'J000458323'];
  6490. for (i in invalidSamples) {
  6491. this.bv.resetForm();
  6492. this.$vat.val(invalidSamples[i]);
  6493. this.bv.validate();
  6494. expect(this.bv.isValid()).toEqual(false);
  6495. }
  6496. });
  6497. });
  6498. function getCountryCode(value, validator, $field) {
  6499. $('#msg').html('getCountryCode() called');
  6500. return validator.getFieldElements('country').val();
  6501. };
  6502. TestSuite = $.extend({}, TestSuite, {
  6503. ZipCode: {
  6504. getCountryCode: function(value, validator, $field) {
  6505. $('#msg').html('TestSuite.ZipCode.getCountryCode() called');
  6506. return validator.getFieldElements('country').val();
  6507. }
  6508. }
  6509. });
  6510. describe('zipCode', function() {
  6511. beforeEach(function() {
  6512. $([
  6513. '<form class="form-horizontal" id="zipCodeForm">',
  6514. '<div id="msg"></div>',
  6515. '<div class="form-group">',
  6516. '<label class="col-md-3 control-label">Country:</label>',
  6517. '<div class="col-md-2">',
  6518. '<select class="form-control" name="country">',
  6519. '<option value="">Select a country</option>',
  6520. '<option value="CA">Canada</option>',
  6521. '<option value="CZ">Czech Republic</option>',
  6522. '<option value="DK">Denmark</option>',
  6523. '<option value="FR">France</option>',
  6524. '<option value="GB">United Kingdom</option>',
  6525. '<option value="IE">Ireland</option>',
  6526. '<option value="IT">Italy</option>',
  6527. '<option value="NL">Netherlands</option>',
  6528. '<option value="SE">Sweden</option>',
  6529. '<option value="SK">Slovakia</option>',
  6530. '<option value="US">United States</option>',
  6531. '</select>',
  6532. '</div>',
  6533. '</div>',
  6534. '<div class="form-group">',
  6535. '<label class="col-md-3 control-label">Zipcode</label>',
  6536. '<div class="col-md-2">',
  6537. '<input type="text" class="form-control" name="zc" data-bv-zipcode data-bv-zipcode-country="US" />',
  6538. '</div>',
  6539. '</div>',
  6540. '</form>'
  6541. ].join('\n')).appendTo('body');
  6542. $('#zipCodeForm').bootstrapValidator();
  6543. /**
  6544. * @type {BootstrapValidator}
  6545. */
  6546. this.bv = $('#zipCodeForm').data('bootstrapValidator');
  6547. this.$country = this.bv.getFieldElements('country');
  6548. this.$zipCode = this.bv.getFieldElements('zc');
  6549. });
  6550. afterEach(function() {
  6551. $('#zipCodeForm').bootstrapValidator('destroy').remove();
  6552. });
  6553. it('country code updateOption()', function() {
  6554. // Check IT postal code
  6555. this.bv.updateOption('zc', 'zipCode', 'country', 'IT');
  6556. this.$zipCode.val('1234');
  6557. this.bv.validate();
  6558. expect(this.bv.isValid()).toEqual(false);
  6559. this.bv.resetForm();
  6560. this.$zipCode.val('IT-12345');
  6561. this.bv.validate();
  6562. expect(this.bv.isValid()).toBeTruthy();
  6563. // Check United Kingdom postal code
  6564. this.bv.updateOption('zc', 'zipCode', 'country', 'GB');
  6565. var validUkSamples = ['EC1A 1BB', 'W1A 1HQ', 'M1 1AA', 'B33 8TH', 'CR2 6XH', 'DN55 1PT', 'AI-2640', 'ASCN 1ZZ', 'GIR 0AA'];
  6566. for (var i in validUkSamples) {
  6567. this.bv.resetForm();
  6568. this.$zipCode.val(validUkSamples[i]);
  6569. this.bv.validate();
  6570. expect(this.bv.isValid()).toBeTruthy();
  6571. }
  6572. });
  6573. it('country code other field declarative', function() {
  6574. this.$zipCode.attr('data-bv-zipcode-country', 'country');
  6575. // Need to destroy the plugin instance ...
  6576. $('#zipCodeForm').bootstrapValidator('destroy');
  6577. // ... and re-create it
  6578. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  6579. this.$country.val('IT');
  6580. this.bv.resetForm();
  6581. this.$zipCode.val('1234');
  6582. this.bv.validate();
  6583. expect(this.bv.isValid()).toEqual(false);
  6584. this.bv.resetForm();
  6585. this.$zipCode.val('I-12345');
  6586. this.bv.validate();
  6587. expect(this.bv.isValid()).toBeTruthy();
  6588. });
  6589. it('country code callback declarative function', function() {
  6590. this.$zipCode.attr('data-bv-zipcode-country', 'getCountryCode');
  6591. $('#zipCodeForm').bootstrapValidator('destroy');
  6592. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  6593. this.$country.val('NL');
  6594. this.$zipCode.val('0123');
  6595. this.bv.validate();
  6596. expect($('#msg').html()).toEqual('getCountryCode() called');
  6597. expect(this.bv.isValid()).toEqual(false);
  6598. });
  6599. it('country code callback declarative function()', function() {
  6600. this.$zipCode.attr('data-bv-zipcode-country', 'getCountryCode()');
  6601. $('#zipCodeForm').bootstrapValidator('destroy');
  6602. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  6603. this.$country.val('NL');
  6604. this.$zipCode.val('1234 ab');
  6605. this.bv.validate();
  6606. expect($('#msg').html()).toEqual('getCountryCode() called');
  6607. expect(this.bv.isValid()).toBeTruthy();
  6608. });
  6609. it('country code callback declarative A.B.C', function() {
  6610. this.$zipCode.attr('data-bv-zipcode-country', 'TestSuite.ZipCode.getCountryCode');
  6611. $('#zipCodeForm').bootstrapValidator('destroy');
  6612. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  6613. this.$country.val('DK');
  6614. this.$zipCode.val('DK 123');
  6615. this.bv.validate();
  6616. expect($('#msg').html()).toEqual('TestSuite.ZipCode.getCountryCode() called');
  6617. expect(this.bv.isValid()).toEqual(false);
  6618. });
  6619. it('country code callback declarative A.B.C()', function() {
  6620. this.$zipCode.attr('data-bv-zipcode-country', 'TestSuite.ZipCode.getCountryCode()');
  6621. $('#zipCodeForm').bootstrapValidator('destroy');
  6622. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  6623. this.$country.val('DK');
  6624. this.$zipCode.val('DK-1234');
  6625. this.bv.validate();
  6626. expect($('#msg').html()).toEqual('TestSuite.ZipCode.getCountryCode() called');
  6627. expect(this.bv.isValid()).toBeTruthy();
  6628. });
  6629. it('country code callback programmatically', function() {
  6630. this.$zipCode.removeAttr('data-bv-zipcode-country');
  6631. $('#zipCodeForm').bootstrapValidator('destroy');
  6632. this.bv = $('#zipCodeForm')
  6633. .bootstrapValidator({
  6634. fields: {
  6635. zc: {
  6636. validators: {
  6637. zipCode: {
  6638. country: function(value, validator, $field) {
  6639. return getCountryCode(value, validator, $field);
  6640. }
  6641. }
  6642. }
  6643. }
  6644. }
  6645. })
  6646. .data('bootstrapValidator');
  6647. this.$country.val('SE');
  6648. this.bv.resetForm();
  6649. this.$zipCode.val('S-567 8');
  6650. this.bv.validate();
  6651. expect($('#msg').html()).toEqual('getCountryCode() called');
  6652. expect(this.bv.isValid()).toEqual(false);
  6653. this.bv.resetForm();
  6654. this.$zipCode.val('S-12345');
  6655. this.bv.validate();
  6656. expect($('#msg').html()).toEqual('getCountryCode() called');
  6657. expect(this.bv.isValid()).toBeTruthy();
  6658. });
  6659. it('not supported country code', function() {
  6660. this.$zipCode.attr('data-bv-zipcode-country', 'NOT_SUPPORTED');
  6661. $('#zipCodeForm').bootstrapValidator('destroy');
  6662. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  6663. this.bv.resetForm();
  6664. this.$zipCode.val('1234');
  6665. this.bv.validate();
  6666. expect(this.bv.isValid()).toEqual(false);
  6667. expect(this.bv.getMessages(this.$zipCode, 'zipCode')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, 'NOT_SUPPORTED'));
  6668. });
  6669. it('US zipcode', function() {
  6670. this.$zipCode.val('12345');
  6671. this.bv.validate();
  6672. expect(this.bv.isValid()).toBeTruthy();
  6673. this.bv.resetForm();
  6674. this.$zipCode.val('123');
  6675. this.bv.validate();
  6676. expect(this.bv.isValid()).toEqual(false);
  6677. });
  6678. it('Czech Republic postal code', function() {
  6679. this.bv.updateOption('zc', 'zipCode', 'country', 'CZ');
  6680. // Valid samples
  6681. var validSamples = ['12345', '123 45'];
  6682. for (var i in validSamples) {
  6683. this.bv.resetForm();
  6684. this.$zipCode.val(validSamples[i]);
  6685. this.bv.validate();
  6686. expect(this.bv.isValid()).toBeTruthy();
  6687. }
  6688. // Invalid samples
  6689. var invalidSamples = ['12 345', '123456', '1 2345', '1234 5', '12 3 45'];
  6690. for (i in invalidSamples) {
  6691. this.bv.resetForm();
  6692. this.$zipCode.val(invalidSamples[i]);
  6693. this.bv.validate();
  6694. expect(this.bv.isValid()).toEqual(false);
  6695. }
  6696. });
  6697. it('Slovakia postal code', function() {
  6698. this.bv.updateOption('zc', 'zipCode', 'country', 'SK');
  6699. // Valid samples
  6700. var validSamples = ['12345', '123 45'];
  6701. for (var i in validSamples) {
  6702. this.bv.resetForm();
  6703. this.$zipCode.val(validSamples[i]);
  6704. this.bv.validate();
  6705. expect(this.bv.isValid()).toBeTruthy();
  6706. }
  6707. // Invalid samples
  6708. var invalidSamples = ['12 345', '123456', '1 2345', '1234 5', '12 3 45'];
  6709. for (i in invalidSamples) {
  6710. this.bv.resetForm();
  6711. this.$zipCode.val(invalidSamples[i]);
  6712. this.bv.validate();
  6713. expect(this.bv.isValid()).toEqual(false);
  6714. }
  6715. });
  6716. it('France postal code', function() {
  6717. this.bv.updateOption('zc', 'zipCode', 'country', 'FR');
  6718. // Valid samples
  6719. var validSamples = ['12340', '01230', '75116'];
  6720. for (var i in validSamples) {
  6721. this.bv.resetForm();
  6722. this.$zipCode.val(validSamples[i]);
  6723. this.bv.validate();
  6724. expect(this.bv.isValid()).toBeTruthy();
  6725. }
  6726. // Invalid samples
  6727. var invalidSamples = ['123 45', '12 345', '123456', '1 2345', '1234 5', '12 3 45', '1234A'];
  6728. for (i in invalidSamples) {
  6729. this.bv.resetForm();
  6730. this.$zipCode.val(invalidSamples[i]);
  6731. this.bv.validate();
  6732. expect(this.bv.isValid()).toEqual(false);
  6733. }
  6734. });
  6735. it('Eircode (Ireland postal code)', function() {
  6736. this.bv.updateOption('zc', 'zipCode', 'country', 'IE');
  6737. // Valid samples
  6738. var validSamples = ['A65 F4E2', 'D6W FNT4', 'T37 F8HK'];
  6739. for (var i in validSamples) {
  6740. this.bv.resetForm();
  6741. this.$zipCode.val(validSamples[i]);
  6742. this.bv.validate();
  6743. expect(this.bv.isValid()).toBeTruthy();
  6744. }
  6745. // Invalid samples
  6746. var invalidSamples = ['a65 f4e2', 'D6W FNTO', 'T37F8HK'];
  6747. for (i in invalidSamples) {
  6748. this.bv.resetForm();
  6749. this.$zipCode.val(invalidSamples[i]);
  6750. this.bv.validate();
  6751. expect(this.bv.isValid()).toEqual(false);
  6752. }
  6753. });
  6754. });