bootstrapValidator.js 244 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482
  1. /*!
  2. * BootstrapValidator (http://bootstrapvalidator.com)
  3. * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  4. *
  5. * @version v0.5.0-dev, built on 2014-07-09 10:07:03 AM
  6. * @author https://twitter.com/nghuuphuoc
  7. * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
  8. * @license MIT
  9. */
  10. (function($) {
  11. var BootstrapValidator = function(form, options) {
  12. this.$form = $(form);
  13. this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options);
  14. this.$invalidFields = $([]); // Array of invalid fields
  15. this.$submitButton = null; // The submit button which is clicked to submit form
  16. // Validating status
  17. this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
  18. this.STATUS_VALIDATING = 'VALIDATING';
  19. this.STATUS_INVALID = 'INVALID';
  20. this.STATUS_VALID = 'VALID';
  21. // Determine the event that is fired when user change the field value
  22. // Most modern browsers supports input event except IE 7, 8.
  23. // IE 9 supports input event but the event is still not fired if I press the backspace key.
  24. // Get IE version
  25. // https://gist.github.com/padolsey/527683/#comment-7595
  26. var ieVersion = (function() {
  27. var v = 3, div = document.createElement('div'), a = div.all || [];
  28. while (div.innerHTML = '<!--[if gt IE '+(++v)+']><br><![endif]-->', a[0]) {}
  29. return v > 4 ? v : !v;
  30. }());
  31. var el = document.createElement('div');
  32. this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input';
  33. // The flag to indicate that the form is ready to submit when a remote/callback validator returns
  34. this._submitIfValid = null;
  35. // Field elements
  36. this._cacheFields = {};
  37. this._init();
  38. };
  39. BootstrapValidator.prototype = {
  40. constructor: BootstrapValidator,
  41. /**
  42. * Init form
  43. */
  44. _init: function() {
  45. var that = this,
  46. options = {
  47. excluded: this.$form.attr('data-bv-excluded'),
  48. trigger: this.$form.attr('data-bv-trigger'),
  49. message: this.$form.attr('data-bv-message'),
  50. container: this.$form.attr('data-bv-container'),
  51. group: this.$form.attr('data-bv-group'),
  52. submitButtons: this.$form.attr('data-bv-submitbuttons'),
  53. threshold: this.$form.attr('data-bv-threshold'),
  54. live: this.$form.attr('data-bv-live'),
  55. onSuccess: this.$form.attr('data-bv-onsuccess'),
  56. onError: this.$form.attr('data-bv-onerror'),
  57. fields: {},
  58. feedbackIcons: {
  59. valid: this.$form.attr('data-bv-feedbackicons-valid'),
  60. invalid: this.$form.attr('data-bv-feedbackicons-invalid'),
  61. validating: this.$form.attr('data-bv-feedbackicons-validating')
  62. }
  63. };
  64. this.$form
  65. // Disable client side validation in HTML 5
  66. .attr('novalidate', 'novalidate')
  67. .addClass(this.options.elementClass)
  68. // Disable the default submission first
  69. .on('submit.bv', function(e) {
  70. e.preventDefault();
  71. that.validate();
  72. })
  73. .on('click.bv', this.options.submitButtons, function() {
  74. that.$submitButton = $(this);
  75. // The user just click the submit button
  76. that._submitIfValid = true;
  77. })
  78. // Find all fields which have either "name" or "data-bv-field" attribute
  79. .find('[name], [data-bv-field]')
  80. .each(function() {
  81. var $field = $(this),
  82. field = $field.attr('name') || $field.attr('data-bv-field'),
  83. opts = that._parseOptions($field);
  84. if (opts) {
  85. $field.attr('data-bv-field', field);
  86. options.fields[field] = $.extend({}, opts, options.fields[field]);
  87. }
  88. });
  89. this.options = $.extend(true, this.options, options);
  90. for (var field in this.options.fields) {
  91. this._initField(field);
  92. }
  93. this.$form.trigger($.Event('init.form.bv'), {
  94. options: this.options
  95. });
  96. // Prepare the events
  97. if (this.options.onSuccess) {
  98. this.$form.on('success.form.bv', function(e) {
  99. $.fn.bootstrapValidator.helpers.call(that.options.onSuccess, [e]);
  100. });
  101. }
  102. if (this.options.onError) {
  103. this.$form.on('error.form.bv', function(e) {
  104. $.fn.bootstrapValidator.helpers.call(that.options.onError, [e]);
  105. });
  106. }
  107. },
  108. /**
  109. * Parse the validator options from HTML attributes
  110. *
  111. * @param {jQuery} $field The field element
  112. * @returns {Object}
  113. */
  114. _parseOptions: function($field) {
  115. var field = $field.attr('name') || $field.attr('data-bv-field'),
  116. validators = {},
  117. validator,
  118. v, // Validator name
  119. enabled,
  120. optionName,
  121. optionValue,
  122. html5AttrName,
  123. html5AttrMap;
  124. for (v in $.fn.bootstrapValidator.validators) {
  125. validator = $.fn.bootstrapValidator.validators[v];
  126. enabled = $field.attr('data-bv-' + v.toLowerCase()) + '';
  127. html5AttrMap = ('function' === typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;
  128. if ((html5AttrMap && enabled !== 'false')
  129. || (html5AttrMap !== true && ('' === enabled || 'true' === enabled)))
  130. {
  131. // Try to parse the options via attributes
  132. validator.html5Attributes = validator.html5Attributes || { message: 'message' };
  133. validators[v] = $.extend({}, html5AttrMap === true ? {} : html5AttrMap, validators[v]);
  134. for (html5AttrName in validator.html5Attributes) {
  135. optionName = validator.html5Attributes[html5AttrName];
  136. optionValue = $field.attr('data-bv-' + v.toLowerCase() + '-' + html5AttrName);
  137. if (optionValue) {
  138. if ('true' === optionValue) {
  139. optionValue = true;
  140. } else if ('false' === optionValue) {
  141. optionValue = false;
  142. }
  143. validators[v][optionName] = optionValue;
  144. }
  145. }
  146. }
  147. }
  148. var opts = {
  149. excluded: $field.attr('data-bv-excluded'),
  150. feedbackIcons: $field.attr('data-bv-feedbackicons'),
  151. trigger: $field.attr('data-bv-trigger'),
  152. message: $field.attr('data-bv-message'),
  153. container: $field.attr('data-bv-container'),
  154. group: $field.attr('data-bv-group'),
  155. selector: $field.attr('data-bv-selector'),
  156. threshold: $field.attr('data-bv-threshold'),
  157. onSuccess: $field.attr('data-bv-onsuccess'),
  158. onError: $field.attr('data-bv-onerror'),
  159. validators: validators
  160. },
  161. emptyOptions = $.isEmptyObject(opts), // Check if the field options are set using HTML attributes
  162. emptyValidators = $.isEmptyObject(validators); // Check if the field validators are set using HTML attributes
  163. if (!emptyValidators || (!emptyOptions && this.options.fields && this.options.fields[field])) {
  164. opts.validators = validators;
  165. return opts;
  166. } else {
  167. return null;
  168. }
  169. },
  170. /**
  171. * Init field
  172. *
  173. * @param {String|jQuery} field The field name or field element
  174. */
  175. _initField: function(field) {
  176. var fields = $([]);
  177. switch (typeof field) {
  178. case 'object':
  179. fields = field;
  180. field = field.attr('data-bv-field');
  181. break;
  182. case 'string':
  183. fields = this.getFieldElements(field);
  184. fields.attr('data-bv-field', field);
  185. break;
  186. default:
  187. break;
  188. }
  189. if (this.options.fields[field] === null || this.options.fields[field].validators === null) {
  190. return;
  191. }
  192. // We don't need to validate non-existing fields
  193. if (fields.length === 0) {
  194. delete this.options.fields[field];
  195. return;
  196. }
  197. var validatorName;
  198. for (validatorName in this.options.fields[field].validators) {
  199. if (!$.fn.bootstrapValidator.validators[validatorName]) {
  200. delete this.options.fields[field].validators[validatorName];
  201. }
  202. }
  203. if (this.options.fields[field].enabled === null) {
  204. this.options.fields[field].enabled = true;
  205. }
  206. var that = this,
  207. total = fields.length,
  208. type = fields.attr('type'),
  209. updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
  210. event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent,
  211. trigger = (this.options.fields[field].trigger || this.options.trigger || event).split(' '),
  212. events = $.map(trigger, function(item) {
  213. return item + '.update.bv';
  214. }).join(' ');
  215. for (var i = 0; i < total; i++) {
  216. var $field = fields.eq(i),
  217. group = this.options.fields[field].group || this.options.group,
  218. $parent = $field.parents(group),
  219. // Allow user to indicate where the error messages are shown
  220. container = this.options.fields[field].container || this.options.container,
  221. $message = (container && container !== 'tooltip' && container !== 'popover') ? $(container) : this._getMessageContainer($field, group);
  222. if (container && container !== 'tooltip' && container !== 'popover') {
  223. $message.addClass('has-error');
  224. }
  225. // Remove all error messages and feedback icons
  226. $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove();
  227. $parent.find('i[data-bv-icon-for="' + field + '"]').remove();
  228. // Whenever the user change the field value, mark it as not validated yet
  229. $field.off(events).on(events, function() {
  230. that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
  231. });
  232. // Create help block elements for showing the error messages
  233. $field.data('bv.messages', $message);
  234. for (validatorName in this.options.fields[field].validators) {
  235. $field.data('bv.result.' + validatorName, this.STATUS_NOT_VALIDATED);
  236. if (!updateAll || i === total - 1) {
  237. $('<small/>')
  238. .css('display', 'none')
  239. .addClass('help-block')
  240. .attr('data-bv-validator', validatorName)
  241. .attr('data-bv-for', field)
  242. .attr('data-bv-result', this.STATUS_NOT_VALIDATED)
  243. .html(this._getMessage(field, validatorName))
  244. .appendTo($message);
  245. }
  246. }
  247. // Prepare the feedback icons
  248. // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
  249. if (this.options.fields[field].feedbackIcons !== false && this.options.fields[field].feedbackIcons !== 'false'
  250. && this.options.feedbackIcons
  251. && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
  252. && (!updateAll || i === total - 1))
  253. {
  254. $parent.removeClass('has-success').removeClass('has-error').addClass('has-feedback');
  255. var $icon = $('<i/>')
  256. .css('display', 'none')
  257. .addClass('form-control-feedback')
  258. .attr('data-bv-icon-for', field)
  259. // Place it after the label containing the checkbox/radio
  260. // so when clicking the icon, it doesn't effect to the checkbox/radio element
  261. .insertAfter(('checkbox' === type || 'radio' === type) ? $field.parent() : $field);
  262. // The feedback icon does not render correctly if there is no label
  263. // https://github.com/twbs/bootstrap/issues/12873
  264. if ($parent.find('label').length === 0) {
  265. $icon.css('top', 0);
  266. }
  267. // Fix feedback icons in input-group
  268. if ($parent.find('.input-group').length !== 0) {
  269. $icon.css({
  270. 'top': 0,
  271. 'z-index': 100
  272. }).insertAfter($parent.find('.input-group').eq(0));
  273. }
  274. }
  275. }
  276. // Prepare the events
  277. if (this.options.fields[field].onSuccess) {
  278. fields.on('success.field.bv', function(e, data) {
  279. $.fn.bootstrapValidator.helpers.call(that.options.fields[field].onSuccess, [e, data]);
  280. });
  281. }
  282. if (this.options.fields[field].onError) {
  283. fields.on('error.field.bv', function(e, data) {
  284. $.fn.bootstrapValidator.helpers.call(that.options.fields[field].onError, [e, data]);
  285. });
  286. }
  287. // Set live mode
  288. events = $.map(trigger, function(item) {
  289. return item + '.live.bv';
  290. }).join(' ');
  291. switch (this.options.live) {
  292. case 'submitted':
  293. break;
  294. case 'disabled':
  295. fields.off(events);
  296. break;
  297. case 'enabled':
  298. /* falls through */
  299. default:
  300. fields.off(events).on(events, function() {
  301. if (that._exceedThreshold($(this))) {
  302. that.validateField($(this));
  303. }
  304. });
  305. break;
  306. }
  307. this.$form.trigger($.Event('init.field.bv'), {
  308. field: field,
  309. element: fields
  310. });
  311. },
  312. /**
  313. * Get the error message for given field and validator
  314. *
  315. * @param {String} field The field name
  316. * @param {String} validatorName The validator name
  317. * @returns {String}
  318. */
  319. _getMessage: function(field, validatorName) {
  320. if (!this.options.fields[field] || !$.fn.bootstrapValidator.validators[validatorName]
  321. || !this.options.fields[field].validators || !this.options.fields[field].validators[validatorName])
  322. {
  323. return '';
  324. }
  325. var options = this.options.fields[field].validators[validatorName];
  326. switch (true) {
  327. case (!!options.message):
  328. return options.message;
  329. case (!!this.options.fields[field].message):
  330. return this.options.fields[field].message;
  331. case (!!$.fn.bootstrapValidator.i18n[validatorName]):
  332. return $.fn.bootstrapValidator.i18n[validatorName]['default'];
  333. default:
  334. return this.options.message;
  335. }
  336. },
  337. /**
  338. * Get the element to place the error messages
  339. *
  340. * @param {jQuery} $field The field element
  341. * @param {String} group
  342. * @returns {jQuery}
  343. */
  344. _getMessageContainer: function($field, group) {
  345. var $parent = $field.parent();
  346. if ($parent.is(group)) {
  347. return $parent;
  348. }
  349. var cssClasses = $parent.attr('class');
  350. if (!cssClasses) {
  351. return this._getMessageContainer($parent, group);
  352. }
  353. cssClasses = cssClasses.split(' ');
  354. var n = cssClasses.length;
  355. for (var i = 0; i < n; i++) {
  356. if (/^col-(xs|sm|md|lg)-\d+$/.test(cssClasses[i]) || /^col-(xs|sm|md|lg)-offset-\d+$/.test(cssClasses[i])) {
  357. return $parent;
  358. }
  359. }
  360. return this._getMessageContainer($parent, group);
  361. },
  362. /**
  363. * Called when all validations are completed
  364. */
  365. _submit: function() {
  366. var isValid = this.isValid(),
  367. eventType = isValid ? 'success.form.bv' : 'error.form.bv',
  368. e = $.Event(eventType);
  369. this.$form.trigger(e);
  370. // Call default handler
  371. // Check if whether the submit button is clicked
  372. if (this.$submitButton) {
  373. isValid ? this._onSuccess(e) : this._onError(e);
  374. }
  375. },
  376. /**
  377. * Check if the field is excluded.
  378. * Returning true means that the field will not be validated
  379. *
  380. * @param {jQuery} $field The field element
  381. * @returns {Boolean}
  382. */
  383. _isExcluded: function($field) {
  384. var excludedAttr = $field.attr('data-bv-excluded'),
  385. // I still need to check the 'name' attribute while initializing the field
  386. field = $field.attr('data-bv-field') || $field.attr('name');
  387. switch (true) {
  388. case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'true' || this.options.fields[field].excluded === true)):
  389. case (excludedAttr === 'true'):
  390. case (excludedAttr === ''):
  391. return true;
  392. case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'false' || this.options.fields[field].excluded === false)):
  393. case (excludedAttr === 'false'):
  394. return false;
  395. default:
  396. if (this.options.excluded) {
  397. // Convert to array first
  398. if ('string' === typeof this.options.excluded) {
  399. this.options.excluded = $.map(this.options.excluded.split(','), function(item) {
  400. // Trim the spaces
  401. return $.trim(item);
  402. });
  403. }
  404. var length = this.options.excluded.length;
  405. for (var i = 0; i < length; i++) {
  406. if (('string' === typeof this.options.excluded[i] && $field.is(this.options.excluded[i]))
  407. || ('function' === typeof this.options.excluded[i] && this.options.excluded[i].call(this, $field, this) === true))
  408. {
  409. return true;
  410. }
  411. }
  412. }
  413. return false;
  414. }
  415. },
  416. /**
  417. * Check if the number of characters of field value exceed the threshold or not
  418. *
  419. * @param {jQuery} $field The field element
  420. * @returns {Boolean}
  421. */
  422. _exceedThreshold: function($field) {
  423. var field = $field.attr('data-bv-field'),
  424. threshold = this.options.fields[field].threshold || this.options.threshold;
  425. if (!threshold) {
  426. return true;
  427. }
  428. var cannotType = $.inArray($field.attr('type'), ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit']) !== -1;
  429. return (cannotType || $field.val().length >= threshold);
  430. },
  431. // ---
  432. // Events
  433. // ---
  434. /**
  435. * The default handler of error.form.bv event.
  436. * It will be called when there is a invalid field
  437. *
  438. * @param {jQuery.Event} e The jQuery event object
  439. */
  440. _onError: function(e) {
  441. if (e.isDefaultPrevented()) {
  442. return;
  443. }
  444. if ('submitted' === this.options.live) {
  445. // Enable live mode
  446. this.options.live = 'enabled';
  447. var that = this;
  448. for (var field in this.options.fields) {
  449. (function(f) {
  450. var fields = that.getFieldElements(f);
  451. if (fields.length) {
  452. var type = $(fields[0]).attr('type'),
  453. event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === $(fields[0]).get(0).tagName) ? 'change' : that._changeEvent,
  454. trigger = that.options.fields[field].trigger || that.options.trigger || event,
  455. events = $.map(trigger.split(' '), function(item) {
  456. return item + '.live.bv';
  457. }).join(' ');
  458. fields.off(events).on(events, function() {
  459. if (that._exceedThreshold($(this))) {
  460. that.validateField($(this));
  461. }
  462. });
  463. }
  464. })(field);
  465. }
  466. }
  467. var $invalidField = this.$invalidFields.eq(0);
  468. if ($invalidField) {
  469. // Activate the tab containing the invalid field if exists
  470. var $tabPane = $invalidField.parents('.tab-pane'), tabId;
  471. if ($tabPane && (tabId = $tabPane.attr('id'))) {
  472. $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
  473. }
  474. // Focus to the first invalid field
  475. $invalidField.focus();
  476. }
  477. },
  478. /**
  479. * The default handler of success.form.bv event.
  480. * It will be called when all the fields are valid
  481. *
  482. * @param {jQuery.Event} e The jQuery event object
  483. */
  484. _onSuccess: function(e) {
  485. if (e.isDefaultPrevented()) {
  486. return;
  487. }
  488. // Call the custom submission if enabled
  489. if (this.options.submitHandler && 'function' === typeof this.options.submitHandler) {
  490. // If you want to submit the form inside your submit handler, please call defaultSubmit() method
  491. this.options.submitHandler.call(this, this, this.$form);
  492. } else {
  493. this.disableSubmitButtons(true).defaultSubmit();
  494. }
  495. },
  496. /**
  497. * Called after validating a field element
  498. *
  499. * @param {jQuery} $field The field element
  500. * @param {String} [validatorName] The validator name
  501. */
  502. _onFieldValidated: function($field, validatorName) {
  503. var field = $field.attr('data-bv-field'),
  504. validators = this.options.fields[field].validators,
  505. counter = {},
  506. numValidators = 0;
  507. // Trigger an event after given validator completes
  508. if (validatorName) {
  509. var data = {
  510. field: field,
  511. element: $field,
  512. validator: validatorName
  513. };
  514. switch ($field.data('bv.result.' + validatorName)) {
  515. case this.STATUS_INVALID:
  516. this.$form.trigger($.Event('error.validator.bv'), data);
  517. break;
  518. case this.STATUS_VALID:
  519. this.$form.trigger($.Event('success.validator.bv'), data);
  520. break;
  521. default:
  522. break;
  523. }
  524. }
  525. counter[this.STATUS_NOT_VALIDATED] = 0;
  526. counter[this.STATUS_VALIDATING] = 0;
  527. counter[this.STATUS_INVALID] = 0;
  528. counter[this.STATUS_VALID] = 0;
  529. for (var v in validators) {
  530. if (validators[v].enabled === false) {
  531. continue;
  532. }
  533. numValidators++;
  534. var result = $field.data('bv.result.' + v);
  535. if (result) {
  536. counter[result]++;
  537. }
  538. }
  539. if (counter[this.STATUS_VALID] === numValidators) {
  540. // Remove from the list of invalid fields
  541. this.$invalidFields = this.$invalidFields.not($field);
  542. this.$form.trigger($.Event('success.field.bv'), {
  543. field: field,
  544. element: $field
  545. });
  546. $field.trigger($.Event('success.field.bv'), {
  547. field: field,
  548. element: $field,
  549. validator: this
  550. });
  551. }
  552. // If all validators are completed and there is at least one validator which doesn't pass
  553. else if (counter[this.STATUS_NOT_VALIDATED] === 0 && counter[this.STATUS_VALIDATING] === 0 && counter[this.STATUS_INVALID] > 0) {
  554. // Add to the list of invalid fields
  555. this.$invalidFields = this.$invalidFields.add($field);
  556. this.$form.trigger($.Event('error.field.bv'), {
  557. field: field,
  558. element: $field
  559. });
  560. $field.trigger($.Event('error.field.bv'), {
  561. field: field,
  562. element: $field,
  563. validator: this
  564. });
  565. }
  566. },
  567. // ---
  568. // Public methods
  569. // ---
  570. /**
  571. * Retrieve the field elements by given name
  572. *
  573. * @param {String} field The field name
  574. * @returns {null|jQuery[]}
  575. */
  576. getFieldElements: function(field) {
  577. if (!this._cacheFields[field]) {
  578. this._cacheFields[field] = (this.options.fields[field] && this.options.fields[field].selector)
  579. ? $(this.options.fields[field].selector)
  580. : this.$form.find('[name="' + field + '"]');
  581. }
  582. return this._cacheFields[field];
  583. },
  584. /**
  585. * Disable/enable submit buttons
  586. *
  587. * @param {Boolean} disabled Can be true or false
  588. * @returns {BootstrapValidator}
  589. */
  590. disableSubmitButtons: function(disabled) {
  591. if (!disabled) {
  592. this.$form.find(this.options.submitButtons).removeAttr('disabled');
  593. } else if (this.options.live !== 'disabled') {
  594. // Don't disable if the live validating mode is disabled
  595. this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
  596. }
  597. return this;
  598. },
  599. /**
  600. * Validate the form
  601. *
  602. * @returns {BootstrapValidator}
  603. */
  604. validate: function() {
  605. if (!this.options.fields) {
  606. return this;
  607. }
  608. this.disableSubmitButtons(true);
  609. for (var field in this.options.fields) {
  610. this.validateField(field);
  611. }
  612. this._submit();
  613. return this;
  614. },
  615. /**
  616. * Validate given field
  617. *
  618. * @param {String|jQuery} field The field name or field element
  619. * @returns {BootstrapValidator}
  620. */
  621. validateField: function(field) {
  622. var fields = $([]);
  623. switch (typeof field) {
  624. case 'object':
  625. fields = field;
  626. field = field.attr('data-bv-field');
  627. break;
  628. case 'string':
  629. fields = this.getFieldElements(field);
  630. break;
  631. default:
  632. break;
  633. }
  634. if (this.options.fields[field] && this.options.fields[field].enabled === false) {
  635. return this;
  636. }
  637. var that = this,
  638. type = fields.attr('type'),
  639. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  640. updateAll = ('radio' === type || 'checkbox' === type),
  641. validators = this.options.fields[field].validators,
  642. validatorName,
  643. validateResult;
  644. for (var i = 0; i < total; i++) {
  645. var $field = fields.eq(i);
  646. if (this._isExcluded($field)) {
  647. continue;
  648. }
  649. for (validatorName in validators) {
  650. if ($field.data('bv.dfs.' + validatorName)) {
  651. $field.data('bv.dfs.' + validatorName).reject();
  652. }
  653. // Don't validate field if it is already done
  654. var result = $field.data('bv.result.' + validatorName);
  655. if (result === this.STATUS_VALID || result === this.STATUS_INVALID || validators[validatorName].enabled === false) {
  656. this._onFieldValidated($field, validatorName);
  657. continue;
  658. }
  659. $field.data('bv.result.' + validatorName, this.STATUS_VALIDATING);
  660. validateResult = $.fn.bootstrapValidator.validators[validatorName].validate(this, $field, validators[validatorName]);
  661. // validateResult can be a $.Deferred object ...
  662. if ('object' === typeof validateResult && validateResult.resolve) {
  663. this.updateStatus(updateAll ? field : $field, this.STATUS_VALIDATING, validatorName);
  664. $field.data('bv.dfs.' + validatorName, validateResult);
  665. validateResult.done(function($f, v, isValid, message) {
  666. // v is validator name
  667. $f.removeData('bv.dfs.' + v);
  668. if (message) {
  669. that.updateMessage($f, v, message);
  670. }
  671. that.updateStatus(updateAll ? $f.attr('data-bv-field') : $f, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
  672. if (isValid && that._submitIfValid === true) {
  673. // If a remote validator returns true and the form is ready to submit, then do it
  674. that._submit();
  675. }
  676. });
  677. }
  678. // ... or object { valid: true/false, message: 'dynamic message' }
  679. else if ('object' === typeof validateResult && validateResult.valid !== undefined && validateResult.message !== undefined) {
  680. this.updateMessage(updateAll ? field : $field, validatorName, validateResult.message);
  681. this.updateStatus(updateAll ? field : $field, validateResult.valid ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  682. }
  683. // ... or a boolean value
  684. else if ('boolean' === typeof validateResult) {
  685. this.updateStatus(updateAll ? field : $field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  686. }
  687. }
  688. }
  689. return this;
  690. },
  691. /**
  692. * Update the error message
  693. *
  694. * @param {String|jQuery} field The field name or field element
  695. * @param {String} validator The validator name
  696. * @param {String} message The message
  697. * @returns {BootstrapValidator}
  698. */
  699. updateMessage: function(field, validator, message) {
  700. var $fields = $([]);
  701. switch (typeof field) {
  702. case 'object':
  703. $fields = field;
  704. field = field.attr('data-bv-field');
  705. break;
  706. case 'string':
  707. $fields = this.getFieldElements(field);
  708. break;
  709. default:
  710. break;
  711. }
  712. $fields.each(function() {
  713. $(this).data('bv.messages').find('.help-block[data-bv-validator="' + validator + '"][data-bv-for="' + field + '"]').html(message);
  714. });
  715. },
  716. /**
  717. * Update all validating results of field
  718. *
  719. * @param {String|jQuery} field The field name or field element
  720. * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
  721. * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
  722. * @returns {BootstrapValidator}
  723. */
  724. updateStatus: function(field, status, validatorName) {
  725. var fields = $([]);
  726. switch (typeof field) {
  727. case 'object':
  728. fields = field;
  729. field = field.attr('data-bv-field');
  730. break;
  731. case 'string':
  732. fields = this.getFieldElements(field);
  733. break;
  734. default:
  735. break;
  736. }
  737. if (status === this.STATUS_NOT_VALIDATED) {
  738. // Reset the flag
  739. this._submitIfValid = false;
  740. }
  741. var that = this,
  742. type = fields.attr('type'),
  743. group = this.options.fields[field].group || this.options.group,
  744. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  745. for (var i = 0; i < total; i++) {
  746. var $field = fields.eq(i);
  747. if (this._isExcluded($field)) {
  748. continue;
  749. }
  750. var $parent = $field.parents(group),
  751. $message = $field.data('bv.messages'),
  752. $allErrors = $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]'),
  753. $errors = validatorName ? $allErrors.filter('[data-bv-validator="' + validatorName + '"]') : $allErrors,
  754. $icon = $parent.find('.form-control-feedback[data-bv-icon-for="' + field + '"]'),
  755. container = this.options.fields[field].container || this.options.container,
  756. isValidField = null;
  757. // Update status
  758. if (validatorName) {
  759. $field.data('bv.result.' + validatorName, status);
  760. } else {
  761. for (var v in this.options.fields[field].validators) {
  762. $field.data('bv.result.' + v, status);
  763. }
  764. }
  765. // Show/hide error elements and feedback icons
  766. $errors.attr('data-bv-result', status);
  767. // Determine the tab containing the element
  768. var $tabPane = $field.parents('.tab-pane'),
  769. tabId, $tab;
  770. if ($tabPane && (tabId = $tabPane.attr('id'))) {
  771. $tab = $('a[href="#' + tabId + '"][data-toggle="tab"]').parent();
  772. }
  773. switch (status) {
  774. case this.STATUS_VALIDATING:
  775. isValidField = null;
  776. this.disableSubmitButtons(true);
  777. $parent.removeClass('has-success').removeClass('has-error');
  778. if ($icon) {
  779. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).addClass(this.options.feedbackIcons.validating).show();
  780. }
  781. if ($tab) {
  782. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
  783. }
  784. break;
  785. case this.STATUS_INVALID:
  786. isValidField = false;
  787. this.disableSubmitButtons(true);
  788. $parent.removeClass('has-success').addClass('has-error');
  789. if ($icon) {
  790. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
  791. }
  792. if ($tab) {
  793. $tab.removeClass('bv-tab-success').addClass('bv-tab-error');
  794. }
  795. break;
  796. case this.STATUS_VALID:
  797. // If the field is valid (passes all validators)
  798. isValidField = ($allErrors.filter('[data-bv-result="' + this.STATUS_NOT_VALIDATED +'"]').length === 0)
  799. ? ($allErrors.filter('[data-bv-result="' + this.STATUS_VALID +'"]').length === $allErrors.length) // All validators are completed
  800. : null; // There are some validators that have not done
  801. if (isValidField !== null) {
  802. this.disableSubmitButtons(this.$submitButton ? !this.isValid() : !isValidField);
  803. if ($icon) {
  804. $icon
  805. .removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).removeClass(this.options.feedbackIcons.valid)
  806. .addClass(isValidField ? this.options.feedbackIcons.valid : this.options.feedbackIcons.invalid)
  807. .show();
  808. }
  809. }
  810. $parent.removeClass('has-error has-success').addClass(this.isValidContainer($parent) ? 'has-success' : 'has-error');
  811. if ($tab) {
  812. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error').addClass(this.isValidContainer($tabPane) ? 'bv-tab-success' : 'bv-tab-error');
  813. }
  814. break;
  815. case this.STATUS_NOT_VALIDATED:
  816. /* falls through */
  817. default:
  818. isValidField = null;
  819. this.disableSubmitButtons(false);
  820. $parent.removeClass('has-success').removeClass('has-error');
  821. if ($icon) {
  822. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).hide();
  823. }
  824. if ($tab) {
  825. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
  826. }
  827. break;
  828. }
  829. switch (true) {
  830. // Only show the first error message if it is placed inside a tooltip ...
  831. case ($icon && 'tooltip' === container):
  832. (isValidField === false)
  833. ? $icon.css('cursor', 'pointer').tooltip('destroy').tooltip({
  834. html: true,
  835. placement: 'top',
  836. title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
  837. })
  838. : $icon.css('cursor', '').tooltip('destroy');
  839. break;
  840. // ... or popover
  841. case ($icon && 'popover' === container):
  842. (isValidField === false)
  843. ? $icon.css('cursor', 'pointer').popover('destroy').popover({
  844. content: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html(),
  845. html: true,
  846. placement: 'top',
  847. trigger: 'hover click'
  848. })
  849. : $icon.css('cursor', '').popover('destroy');
  850. break;
  851. default:
  852. (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
  853. break;
  854. }
  855. // Trigger an event
  856. this.$form.trigger($.Event('status.field.bv'), {
  857. field: field,
  858. element: $field,
  859. status: status
  860. });
  861. this._onFieldValidated($field, validatorName);
  862. }
  863. return this;
  864. },
  865. /**
  866. * Check the form validity
  867. *
  868. * @returns {Boolean}
  869. */
  870. isValid: function() {
  871. for (var field in this.options.fields) {
  872. if (!this.isValidField(field)) {
  873. return false;
  874. }
  875. }
  876. return true;
  877. },
  878. /**
  879. * Check if the field is valid or not
  880. *
  881. * @param {String|jQuery} field The field name or field element
  882. * @returns {Boolean}
  883. */
  884. isValidField: function(field) {
  885. var fields = $([]);
  886. switch (typeof field) {
  887. case 'object':
  888. fields = field;
  889. field = field.attr('data-bv-field');
  890. break;
  891. case 'string':
  892. fields = this.getFieldElements(field);
  893. break;
  894. default:
  895. break;
  896. }
  897. if (fields.length === 0 || this.options.fields[field] === null || this.options.fields[field].enabled === false) {
  898. return true;
  899. }
  900. var type = fields.attr('type'),
  901. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  902. $field, validatorName, status;
  903. for (var i = 0; i < total; i++) {
  904. $field = fields.eq(i);
  905. if (this._isExcluded($field)) {
  906. continue;
  907. }
  908. for (validatorName in this.options.fields[field].validators) {
  909. if (this.options.fields[field].validators[validatorName].enabled === false) {
  910. continue;
  911. }
  912. status = $field.data('bv.result.' + validatorName);
  913. if (status !== this.STATUS_VALID) {
  914. return false;
  915. }
  916. }
  917. }
  918. return true;
  919. },
  920. /**
  921. * Check if all fields inside a given container are valid.
  922. * It's useful when working with a wizard-like such as tab, collapse
  923. *
  924. * @param {jQuery} $container The container element
  925. * @returns {Boolean}
  926. */
  927. isValidContainer: function($container) {
  928. var that = this, map = {};
  929. $container.find('[data-bv-field]').each(function() {
  930. var $field = $(this),
  931. field = $field.attr('data-bv-field');
  932. if (!that._isExcluded($field) && !map[field]) {
  933. map[field] = $field;
  934. }
  935. });
  936. for (var field in map) {
  937. var $f = map[field];
  938. if ($f.data('bv.messages')
  939. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
  940. .filter(function() {
  941. var v = $(this).attr('data-bv-validator'),
  942. f = $(this).attr('data-bv-for');
  943. return (that.options.fields[f].validators[v].enabled !== false
  944. && $f.data('bv.result.' + v) && $f.data('bv.result.' + v) !== that.STATUS_VALID);
  945. })
  946. .length !== 0)
  947. {
  948. // The field is not valid
  949. return false;
  950. }
  951. }
  952. return true;
  953. },
  954. /**
  955. * Submit the form using default submission.
  956. * It also does not perform any validations when submitting the form
  957. *
  958. * It might be used when you want to submit the form right inside the submitHandler()
  959. */
  960. defaultSubmit: function() {
  961. if (this.$submitButton) {
  962. // Create hidden input to send the submit buttons
  963. $('<input/>')
  964. .attr('type', 'hidden')
  965. .attr('data-bv-submit-hidden', '')
  966. .attr('name', this.$submitButton.attr('name'))
  967. .val(this.$submitButton.val())
  968. .appendTo(this.$form);
  969. }
  970. // Submit form
  971. this.$form.off('submit.bv').submit();
  972. },
  973. // ---
  974. // Useful APIs which aren't used internally
  975. // ---
  976. /**
  977. * Get the list of invalid fields
  978. *
  979. * @returns {jQuery[]}
  980. */
  981. getInvalidFields: function() {
  982. return this.$invalidFields;
  983. },
  984. /**
  985. * Returns the clicked submit button
  986. *
  987. * @returns {jQuery}
  988. */
  989. getSubmitButton: function() {
  990. return this.$submitButton;
  991. },
  992. /**
  993. * Get the error messages
  994. *
  995. * @param {String|jQuery} [field] The field name or field element
  996. * If the field is not defined, the method returns all error messages of all fields
  997. * @param {String} [validator] The name of validator
  998. * If the validator is not defined, the method returns error messages of all validators
  999. * @returns {String[]}
  1000. */
  1001. getMessages: function(field, validator) {
  1002. var that = this,
  1003. messages = [],
  1004. $fields = $([]);
  1005. switch (true) {
  1006. case (field && 'object' === typeof field):
  1007. $fields = field;
  1008. break;
  1009. case (field && 'string' === typeof field):
  1010. var f = this.getFieldElements(field);
  1011. if (f.length > 0) {
  1012. var type = f.attr('type');
  1013. $fields = ('radio' === type || 'checkbox' === type) ? f.eq(0) : f;
  1014. }
  1015. break;
  1016. default:
  1017. $fields = this.$invalidFields;
  1018. break;
  1019. }
  1020. var filter = validator ? '[data-bv-validator="' + validator + '"]' : '';
  1021. $fields.each(function() {
  1022. messages = messages.concat(
  1023. $(this)
  1024. .data('bv.messages')
  1025. .find('.help-block[data-bv-for="' + $(this).attr('data-bv-field') + '"][data-bv-result="' + that.STATUS_INVALID + '"]' + filter)
  1026. .map(function() {
  1027. var v = $(this).attr('data-bv-validator'),
  1028. f = $(this).attr('data-bv-for');
  1029. return (that.options.fields[f].validators[v].enabled === false) ? '' : $(this).html();
  1030. })
  1031. .get()
  1032. );
  1033. });
  1034. return messages;
  1035. },
  1036. /**
  1037. * Get the field options
  1038. *
  1039. * @param {String|jQuery} [field] The field name or field element. If it is not set, the method returns the form options
  1040. * @param {String} [validator] The name of validator. It null, the method returns form options
  1041. * @param {String} [option] The option name
  1042. * @return {String|Object}
  1043. */
  1044. getOptions: function(field, validator, option) {
  1045. if (!field) {
  1046. return this.options;
  1047. }
  1048. if ('object' === typeof field) {
  1049. field = field.attr('data-bv-field');
  1050. }
  1051. if (!this.options.fields[field]) {
  1052. return null;
  1053. }
  1054. var options = this.options.fields[field];
  1055. if (!validator) {
  1056. return options;
  1057. }
  1058. if (!options.validators || !options.validators[validator]) {
  1059. return null;
  1060. }
  1061. return option ? options.validators[validator][option] : options.validators[validator];
  1062. },
  1063. /**
  1064. * Update the option of a specific validator
  1065. *
  1066. * @param {String|jQuery} field The field name or field element
  1067. * @param {String} validator The validator name
  1068. * @param {String} option The option name
  1069. * @param {String} value The value to set
  1070. * @returns {BootstrapValidator}
  1071. */
  1072. updateOption: function(field, validator, option, value) {
  1073. if ('object' === typeof field) {
  1074. field = field.attr('data-bv-field');
  1075. }
  1076. if (this.options.fields[field] && this.options.fields[field].validators[validator]) {
  1077. this.options.fields[field].validators[validator][option] = value;
  1078. this.updateStatus(field, this.STATUS_NOT_VALIDATED, validator);
  1079. }
  1080. return this;
  1081. },
  1082. /**
  1083. * Add a new field
  1084. *
  1085. * @param {String|jQuery} field The field name or field element
  1086. * @param {Object} [options] The validator rules
  1087. * @returns {BootstrapValidator}
  1088. */
  1089. addField: function(field, options) {
  1090. var fields = $([]);
  1091. switch (typeof field) {
  1092. case 'object':
  1093. fields = field;
  1094. field = field.attr('data-bv-field') || field.attr('name');
  1095. break;
  1096. case 'string':
  1097. delete this._cacheFields[field];
  1098. fields = this.getFieldElements(field);
  1099. break;
  1100. default:
  1101. break;
  1102. }
  1103. fields.attr('data-bv-field', field);
  1104. var type = fields.attr('type'),
  1105. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1106. for (var i = 0; i < total; i++) {
  1107. var $field = fields.eq(i);
  1108. // Try to parse the options from HTML attributes
  1109. var opts = this._parseOptions($field);
  1110. opts = (opts === null) ? options : $.extend(true, options, opts);
  1111. this.options.fields[field] = $.extend(true, this.options.fields[field], opts);
  1112. // Update the cache
  1113. this._cacheFields[field] = this._cacheFields[field] ? this._cacheFields[field].add($field) : $field;
  1114. // Init the element
  1115. this._initField(('checkbox' === type || 'radio' === type) ? field : $field);
  1116. }
  1117. this.disableSubmitButtons(false);
  1118. // Trigger an event
  1119. this.$form.trigger($.Event('added.field.bv'), {
  1120. field: field,
  1121. element: fields,
  1122. options: this.options.fields[field]
  1123. });
  1124. return this;
  1125. },
  1126. /**
  1127. * Remove a given field
  1128. *
  1129. * @param {String|jQuery} field The field name or field element
  1130. * @returns {BootstrapValidator}
  1131. */
  1132. removeField: function(field) {
  1133. var fields = $([]);
  1134. switch (typeof field) {
  1135. case 'object':
  1136. fields = field;
  1137. field = field.attr('data-bv-field') || field.attr('name');
  1138. fields.attr('data-bv-field', field);
  1139. break;
  1140. case 'string':
  1141. fields = this.getFieldElements(field);
  1142. break;
  1143. default:
  1144. break;
  1145. }
  1146. if (fields.length === 0) {
  1147. return this;
  1148. }
  1149. var type = fields.attr('type'),
  1150. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1151. for (var i = 0; i < total; i++) {
  1152. var $field = fields.eq(i);
  1153. // Remove from the list of invalid fields
  1154. this.$invalidFields = this.$invalidFields.not($field);
  1155. // Update the cache
  1156. this._cacheFields[field] = this._cacheFields[field].not($field);
  1157. }
  1158. if (!this._cacheFields[field] || this._cacheFields[field].length === 0) {
  1159. delete this.options.fields[field];
  1160. }
  1161. if ('checkbox' === type || 'radio' === type) {
  1162. this._initField(field);
  1163. }
  1164. this.disableSubmitButtons(false);
  1165. // Trigger an event
  1166. this.$form.trigger($.Event('removed.field.bv'), {
  1167. field: field,
  1168. element: fields
  1169. });
  1170. return this;
  1171. },
  1172. /**
  1173. * Reset given field
  1174. *
  1175. * @param {String|jQuery} field The field name or field element
  1176. * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  1177. * @returns {BootstrapValidator}
  1178. */
  1179. resetField: function(field, resetValue) {
  1180. var $fields = $([]);
  1181. switch (typeof field) {
  1182. case 'object':
  1183. $fields = field;
  1184. field = field.attr('data-bv-field');
  1185. break;
  1186. case 'string':
  1187. $fields = this.getFieldElements(field);
  1188. break;
  1189. default:
  1190. break;
  1191. }
  1192. var total = $fields.length;
  1193. if (this.options.fields[field]) {
  1194. for (var i = 0; i < total; i++) {
  1195. for (var validator in this.options.fields[field].validators) {
  1196. $fields.eq(i).removeData('bv.dfs.' + validator);
  1197. }
  1198. }
  1199. }
  1200. // Mark field as not validated yet
  1201. this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  1202. if (resetValue) {
  1203. var type = $fields.attr('type');
  1204. ('radio' === type || 'checkbox' === type) ? $fields.removeAttr('checked').removeAttr('selected') : $fields.val('');
  1205. }
  1206. return this;
  1207. },
  1208. /**
  1209. * Reset the form
  1210. *
  1211. * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  1212. * @returns {BootstrapValidator}
  1213. */
  1214. resetForm: function(resetValue) {
  1215. for (var field in this.options.fields) {
  1216. this.resetField(field, resetValue);
  1217. }
  1218. this.$invalidFields = $([]);
  1219. this.$submitButton = null;
  1220. // Enable submit buttons
  1221. this.disableSubmitButtons(false);
  1222. return this;
  1223. },
  1224. /**
  1225. * Revalidate given field
  1226. * It's used when you need to revalidate the field which its value is updated by other plugin
  1227. *
  1228. * @param {String|jQuery} field The field name of field element
  1229. * @returns {BootstrapValidator}
  1230. */
  1231. revalidateField: function(field) {
  1232. this.updateStatus(field, this.STATUS_NOT_VALIDATED)
  1233. .validateField(field);
  1234. return this;
  1235. },
  1236. /**
  1237. * Enable/Disable all validators to given field
  1238. *
  1239. * @param {String} field The field name
  1240. * @param {Boolean} enabled Enable/Disable field validators
  1241. * @param {String} [validatorName] The validator name. If null, all validators will be enabled/disabled
  1242. * @returns {BootstrapValidator}
  1243. */
  1244. enableFieldValidators: function(field, enabled, validatorName) {
  1245. var validators = this.options.fields[field].validators;
  1246. // Enable/disable particular validator
  1247. if (validatorName
  1248. && validators
  1249. && validators[validatorName] && validators[validatorName].enabled !== enabled)
  1250. {
  1251. this.options.fields[field].validators[validatorName].enabled = enabled;
  1252. this.updateStatus(field, this.STATUS_NOT_VALIDATED, validatorName);
  1253. }
  1254. // Enable/disable all validators
  1255. else if (!validatorName && this.options.fields[field].enabled !== enabled) {
  1256. this.options.fields[field].enabled = enabled;
  1257. for (var v in validators) {
  1258. this.enableFieldValidators(field, enabled, v);
  1259. }
  1260. }
  1261. return this;
  1262. },
  1263. /**
  1264. * Some other validators have option which its value is dynamic.
  1265. * For example, the zipCode validator which country is set by a select element.
  1266. *
  1267. * @param {String|Function} option The option which can be determined by:
  1268. * - a string
  1269. * - name of field which defines the value
  1270. * - name of function which returns the value
  1271. * - a function returns the value
  1272. *
  1273. * The callback function has the format of
  1274. * callback: function(value, validator, $field) {
  1275. * // value is the value of field
  1276. * // validator is the BootstrapValidator instance
  1277. * // $field is the field element
  1278. * }
  1279. *
  1280. * @param {jQuery|String} field The field name or element
  1281. * @returns {String}
  1282. */
  1283. getDynamicOption: function(option, field) {
  1284. var $field = ('string' === typeof field) ? this.getFieldElements(field) : field,
  1285. value = $field.val();
  1286. // Option can be determined by
  1287. // ... a function
  1288. if ('function' === typeof option) {
  1289. return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]);
  1290. }
  1291. // ... value of other field
  1292. else if ('string' === typeof option) {
  1293. var $f = this.getFieldElements(option);
  1294. if ($f.length) {
  1295. return $f.val();
  1296. }
  1297. // ... return value of callback
  1298. else {
  1299. return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]);
  1300. }
  1301. }
  1302. return null;
  1303. },
  1304. /**
  1305. * Destroy the plugin
  1306. * It will remove all error messages, feedback icons and turn off the events
  1307. */
  1308. destroy: function() {
  1309. var field, fields, $field, validator, $icon, container, group;
  1310. for (field in this.options.fields) {
  1311. fields = this.getFieldElements(field);
  1312. container = this.options.fields[field].container || this.options.container,
  1313. group = this.options.fields[field].group || this.options.group;
  1314. for (var i = 0; i < fields.length; i++) {
  1315. $field = fields.eq(i);
  1316. $field
  1317. // Remove all error messages
  1318. .data('bv.messages')
  1319. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove().end()
  1320. .end()
  1321. .removeData('bv.messages')
  1322. // Remove feedback classes
  1323. .parents(group)
  1324. .removeClass('has-feedback has-error has-success')
  1325. .end()
  1326. // Turn off events
  1327. .off('.bv')
  1328. .removeAttr('data-bv-field');
  1329. // Remove feedback icons, tooltip/popover container
  1330. $icon = $field.parents(group).find('i[data-bv-icon-for="' + field + '"]');
  1331. if ($icon) {
  1332. switch (container) {
  1333. case 'tooltip':
  1334. $icon.tooltip('destroy').remove();
  1335. break;
  1336. case 'popover':
  1337. $icon.popover('destroy').remove();
  1338. break;
  1339. default:
  1340. $icon.remove();
  1341. break;
  1342. }
  1343. }
  1344. for (validator in this.options.fields[field].validators) {
  1345. if ($field.data('bv.dfs.' + validator)) {
  1346. $field.data('bv.dfs.' + validator).reject();
  1347. }
  1348. $field.removeData('bv.result.' + validator).removeData('bv.dfs.' + validator);
  1349. }
  1350. }
  1351. }
  1352. // Enable submit buttons
  1353. this.disableSubmitButtons(false);
  1354. this.$form
  1355. .removeClass(this.options.elementClass)
  1356. .off('.bv')
  1357. .removeData('bootstrapValidator')
  1358. // Remove generated hidden elements
  1359. .find('[data-bv-submit-hidden]').remove();
  1360. }
  1361. };
  1362. // Plugin definition
  1363. $.fn.bootstrapValidator = function(option) {
  1364. var params = arguments;
  1365. return this.each(function() {
  1366. var $this = $(this),
  1367. data = $this.data('bootstrapValidator'),
  1368. options = 'object' === typeof option && option;
  1369. if (!data) {
  1370. data = new BootstrapValidator(this, options);
  1371. $this.data('bootstrapValidator', data);
  1372. }
  1373. // Allow to call plugin method
  1374. if ('string' === typeof option) {
  1375. data[option].apply(data, Array.prototype.slice.call(params, 1));
  1376. }
  1377. });
  1378. };
  1379. // The default options
  1380. $.fn.bootstrapValidator.DEFAULT_OPTIONS = {
  1381. // The form CSS class
  1382. elementClass: 'bv-form',
  1383. // Default invalid message
  1384. message: 'This value is not valid',
  1385. // The CSS selector for indicating the element consists the field
  1386. // By default, each field is placed inside the <div class="form-group"></div>
  1387. // You should adjust this option if your form group consists of many fields which not all of them need to be validated
  1388. group: '.form-group',
  1389. //The error messages container. It can be:
  1390. // - 'tooltip' if you want to use Bootstrap tooltip to show error messages
  1391. // - 'popover' if you want to use Bootstrap popover to show error messages
  1392. // - a CSS selector indicating the container
  1393. // In the first two cases, since the tooltip/popover should be small enough, the plugin only shows only one error message
  1394. // You also can define the message container for particular field
  1395. container: null,
  1396. // The field will not be live validated if its length is less than this number of characters
  1397. threshold: null,
  1398. // Indicate fields which won't be validated
  1399. // By default, the plugin will not validate the following kind of fields:
  1400. // - disabled
  1401. // - hidden
  1402. // - invisible
  1403. //
  1404. // The setting consists of jQuery filters. Accept 3 formats:
  1405. // - A string. Use a comma to separate filter
  1406. // - An array. Each element is a filter
  1407. // - An array. Each element can be a callback function
  1408. // function($field, validator) {
  1409. // $field is jQuery object representing the field element
  1410. // validator is the BootstrapValidator instance
  1411. // return true or false;
  1412. // }
  1413. //
  1414. // The 3 following settings are equivalent:
  1415. //
  1416. // 1) ':disabled, :hidden, :not(:visible)'
  1417. // 2) [':disabled', ':hidden', ':not(:visible)']
  1418. // 3) [':disabled', ':hidden', function($field) {
  1419. // return !$field.is(':visible');
  1420. // }]
  1421. excluded: [':disabled', ':hidden', ':not(:visible)'],
  1422. // Shows ok/error/loading icons based on the field validity.
  1423. // This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
  1424. // Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
  1425. // In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
  1426. //
  1427. // Examples:
  1428. // - Use Glyphicons icons:
  1429. // feedbackIcons: {
  1430. // valid: 'glyphicon glyphicon-ok',
  1431. // invalid: 'glyphicon glyphicon-remove',
  1432. // validating: 'glyphicon glyphicon-refresh'
  1433. // }
  1434. // - Use FontAwesome icons:
  1435. // feedbackIcons: {
  1436. // valid: 'fa fa-check',
  1437. // invalid: 'fa fa-times',
  1438. // validating: 'fa fa-refresh'
  1439. // }
  1440. feedbackIcons: {
  1441. valid: null,
  1442. invalid: null,
  1443. validating: null
  1444. },
  1445. // The submit buttons selector
  1446. // These buttons will be disabled to prevent the valid form from multiple submissions
  1447. submitButtons: '[type="submit"]',
  1448. // The custom submit handler
  1449. // It will prevent the form from the default submission
  1450. //
  1451. // submitHandler: function(validator, form) {
  1452. // - validator is the BootstrapValidator instance
  1453. // - form is the jQuery object presenting the current form
  1454. // }
  1455. submitHandler: null,
  1456. // Live validating option
  1457. // Can be one of 3 values:
  1458. // - enabled: The plugin validates fields as soon as they are changed
  1459. // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
  1460. // - submitted: The live validating is enabled after the form is submitted
  1461. live: 'enabled',
  1462. // Map the field name with validator rules
  1463. fields: null
  1464. };
  1465. // Available validators
  1466. $.fn.bootstrapValidator.validators = {};
  1467. // i18n
  1468. $.fn.bootstrapValidator.i18n = {};
  1469. $.fn.bootstrapValidator.Constructor = BootstrapValidator;
  1470. // Helper methods, which can be used in validator class
  1471. $.fn.bootstrapValidator.helpers = {
  1472. /**
  1473. * Execute a callback function
  1474. *
  1475. * @param {String|Function} functionName Can be
  1476. * - name of global function
  1477. * - name of namespace function (such as A.B.C)
  1478. * - a function
  1479. * @param {Array} args The callback arguments
  1480. */
  1481. call: function(functionName, args) {
  1482. if ('function' === typeof functionName) {
  1483. return functionName.apply(this, args);
  1484. } else if ('string' === typeof functionName) {
  1485. if ('()' === functionName.substring(functionName.length - 2)) {
  1486. functionName = functionName.substring(0, functionName.length - 2);
  1487. }
  1488. var ns = functionName.split('.'),
  1489. func = ns.pop(),
  1490. context = window;
  1491. for (var i = 0; i < ns.length; i++) {
  1492. context = context[ns[i]];
  1493. }
  1494. return context[func].apply(this, args);
  1495. }
  1496. },
  1497. /**
  1498. * Format a string
  1499. * It's used to format the error message
  1500. * format('The field must between %s and %s', [10, 20]) = 'The field must between 10 and 20'
  1501. *
  1502. * @param {String} message
  1503. * @param {Array} parameters
  1504. * @returns {String}
  1505. */
  1506. format: function(message, parameters) {
  1507. if (!$.isArray(parameters)) {
  1508. parameters = [parameters];
  1509. }
  1510. for (var i in parameters) {
  1511. message = message.replace('%s', parameters[i]);
  1512. }
  1513. return message;
  1514. },
  1515. /**
  1516. * Validate a date
  1517. *
  1518. * @param {Number} year The full year in 4 digits
  1519. * @param {Number} month The month number
  1520. * @param {Number} day The day number
  1521. * @param {Boolean} [notInFuture] If true, the date must not be in the future
  1522. * @returns {Boolean}
  1523. */
  1524. date: function(year, month, day, notInFuture) {
  1525. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  1526. return false;
  1527. }
  1528. day = parseInt(day, 10);
  1529. month = parseInt(month, 10);
  1530. year = parseInt(year, 10);
  1531. if (year < 1000 || year > 9999 || month === 0 || month > 12) {
  1532. return false;
  1533. }
  1534. var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1535. // Update the number of days in Feb of leap year
  1536. if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
  1537. numDays[1] = 29;
  1538. }
  1539. // Check the day
  1540. if (day <= 0 || day > numDays[month - 1]) {
  1541. return false;
  1542. }
  1543. if (notInFuture === true) {
  1544. var currentDate = new Date(),
  1545. currentYear = currentDate.getFullYear(),
  1546. currentMonth = currentDate.getMonth(),
  1547. currentDay = currentDate.getDate();
  1548. return (year < currentYear
  1549. || (year === currentYear && month - 1 < currentMonth)
  1550. || (year === currentYear && month - 1 === currentMonth && day < currentDay));
  1551. }
  1552. return true;
  1553. },
  1554. /**
  1555. * Implement Luhn validation algorithm
  1556. * Credit to https://gist.github.com/ShirtlessKirk/2134376
  1557. *
  1558. * @see http://en.wikipedia.org/wiki/Luhn
  1559. * @param {String} value
  1560. * @returns {Boolean}
  1561. */
  1562. luhn: function(value) {
  1563. var length = value.length,
  1564. mul = 0,
  1565. prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
  1566. sum = 0;
  1567. while (length--) {
  1568. sum += prodArr[mul][parseInt(value.charAt(length), 10)];
  1569. mul ^= 1;
  1570. }
  1571. return (sum % 10 === 0 && sum > 0);
  1572. },
  1573. /**
  1574. * Implement modulus 11, 10 (ISO 7064) algorithm
  1575. *
  1576. * @param {String} value
  1577. * @returns {Boolean}
  1578. */
  1579. mod11And10: function(value) {
  1580. var check = 5,
  1581. length = value.length;
  1582. for (var i = 0; i < length; i++) {
  1583. check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
  1584. }
  1585. return (check === 1);
  1586. },
  1587. /**
  1588. * Implements Mod 37, 36 (ISO 7064) algorithm
  1589. * Usages:
  1590. * mod37And36('A12425GABC1234002M')
  1591. * mod37And36('002006673085', '0123456789')
  1592. *
  1593. * @param {String} value
  1594. * @param {String} [alphabet]
  1595. * @returns {Boolean}
  1596. */
  1597. mod37And36: function(value, alphabet) {
  1598. alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1599. var modulus = alphabet.length,
  1600. length = value.length,
  1601. check = Math.floor(modulus / 2);
  1602. for (var i = 0; i < length; i++) {
  1603. check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
  1604. }
  1605. return (check === 1);
  1606. }
  1607. };
  1608. }(window.jQuery));
  1609. ;(function($) {
  1610. $.fn.bootstrapValidator.i18n.base64 = $.extend($.fn.bootstrapValidator.i18n.base64 || {}, {
  1611. 'default': 'Please enter a valid base 64 encoded'
  1612. });
  1613. $.fn.bootstrapValidator.validators.base64 = {
  1614. /**
  1615. * Return true if the input value is a base 64 encoded string.
  1616. *
  1617. * @param {BootstrapValidator} validator The validator plugin instance
  1618. * @param {jQuery} $field Field element
  1619. * @param {Object} options Can consist of the following keys:
  1620. * - message: The invalid message
  1621. * @returns {Boolean}
  1622. */
  1623. validate: function(validator, $field, options) {
  1624. var value = $field.val();
  1625. if (value === '') {
  1626. return true;
  1627. }
  1628. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
  1629. }
  1630. };
  1631. }(window.jQuery));
  1632. ;(function($) {
  1633. $.fn.bootstrapValidator.i18n.between = $.extend($.fn.bootstrapValidator.i18n.between || {}, {
  1634. 'default': 'Please enter a value between %s and %s',
  1635. notInclusive: 'Please enter a value between %s and %s strictly'
  1636. });
  1637. $.fn.bootstrapValidator.validators.between = {
  1638. html5Attributes: {
  1639. message: 'message',
  1640. min: 'min',
  1641. max: 'max',
  1642. inclusive: 'inclusive'
  1643. },
  1644. enableByHtml5: function($field) {
  1645. if ('range' === $field.attr('type')) {
  1646. return {
  1647. min: $field.attr('min'),
  1648. max: $field.attr('max')
  1649. };
  1650. }
  1651. return false;
  1652. },
  1653. /**
  1654. * Return true if the input value is between (strictly or not) two given numbers
  1655. *
  1656. * @param {BootstrapValidator} validator The validator plugin instance
  1657. * @param {jQuery} $field Field element
  1658. * @param {Object} options Can consist of the following keys:
  1659. * - min
  1660. * - max
  1661. *
  1662. * The min, max keys define the number which the field value compares to. min, max can be
  1663. * - A number
  1664. * - Name of field which its value defines the number
  1665. * - Name of callback function that returns the number
  1666. * - A callback function that returns the number
  1667. *
  1668. * - inclusive [optional]: Can be true or false. Default is true
  1669. * - message: The invalid message
  1670. * @returns {Boolean|Object}
  1671. */
  1672. validate: function(validator, $field, options) {
  1673. var value = $field.val();
  1674. if (value === '') {
  1675. return true;
  1676. }
  1677. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption(options.min, $field),
  1678. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption(options.max, $field);
  1679. value = parseFloat(value);
  1680. return (options.inclusive === true || options.inclusive === undefined)
  1681. ? {
  1682. valid: value >= min && value <= max,
  1683. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between['default'], [min, max])
  1684. }
  1685. : {
  1686. valid: value > min && value < max,
  1687. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between.notInclusive, [min, max])
  1688. };
  1689. }
  1690. };
  1691. }(window.jQuery));
  1692. ;(function($) {
  1693. $.fn.bootstrapValidator.i18n.callback = $.extend($.fn.bootstrapValidator.i18n.callback || {}, {
  1694. 'default': 'Please enter a valid value'
  1695. });
  1696. $.fn.bootstrapValidator.validators.callback = {
  1697. html5Attributes: {
  1698. message: 'message',
  1699. callback: 'callback'
  1700. },
  1701. /**
  1702. * Return result from the callback method
  1703. *
  1704. * @param {BootstrapValidator} validator The validator plugin instance
  1705. * @param {jQuery} $field Field element
  1706. * @param {Object} options Can consist of the following keys:
  1707. * - callback: The callback method that passes 2 parameters:
  1708. * callback: function(fieldValue, validator, $field) {
  1709. * // fieldValue is the value of field
  1710. * // validator is instance of BootstrapValidator
  1711. * // $field is the field element
  1712. * }
  1713. * - message: The invalid message
  1714. * @returns {Boolean|Deferred}
  1715. */
  1716. validate: function(validator, $field, options) {
  1717. var value = $field.val();
  1718. if (options.callback) {
  1719. var dfd = new $.Deferred(),
  1720. response = $.fn.bootstrapValidator.helpers.call(options.callback, [value, validator, $field]);
  1721. dfd.resolve($field, 'callback', 'boolean' === typeof response ? response : response.valid, 'object' === typeof response && response.message ? response.message : null);
  1722. return dfd;
  1723. }
  1724. return true;
  1725. }
  1726. };
  1727. }(window.jQuery));
  1728. ;(function($) {
  1729. $.fn.bootstrapValidator.i18n.choice = $.extend($.fn.bootstrapValidator.i18n.choice || {}, {
  1730. 'default': 'Please enter a valid value',
  1731. less: 'Please choose %s options at minimum',
  1732. more: 'Please choose %s options at maximum',
  1733. between: 'Please choose %s - %s options'
  1734. });
  1735. $.fn.bootstrapValidator.validators.choice = {
  1736. html5Attributes: {
  1737. message: 'message',
  1738. min: 'min',
  1739. max: 'max'
  1740. },
  1741. /**
  1742. * Check if the number of checked boxes are less or more than a given number
  1743. *
  1744. * @param {BootstrapValidator} validator The validator plugin instance
  1745. * @param {jQuery} $field Field element
  1746. * @param {Object} options Consists of following keys:
  1747. * - min
  1748. * - max
  1749. *
  1750. * At least one of two keys is required
  1751. * The min, max keys define the number which the field value compares to. min, max can be
  1752. * - A number
  1753. * - Name of field which its value defines the number
  1754. * - Name of callback function that returns the number
  1755. * - A callback function that returns the number
  1756. *
  1757. * - message: The invalid message
  1758. * @returns {Object}
  1759. */
  1760. validate: function(validator, $field, options) {
  1761. var numChoices = $field.is('select')
  1762. ? validator.getFieldElements($field.attr('data-bv-field')).find('option').filter(':selected').length
  1763. : validator.getFieldElements($field.attr('data-bv-field')).filter(':checked').length,
  1764. min = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption(options.min, $field)) : null,
  1765. max = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption(options.max, $field)) : null,
  1766. isValid = true,
  1767. message = options.message || $.fn.bootstrapValidator.i18n.choice['default'];
  1768. if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
  1769. isValid = false;
  1770. }
  1771. switch (true) {
  1772. case (!!min && !!max):
  1773. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.between, [parseInt(min, 10), parseInt(max, 10)]);
  1774. break;
  1775. case (!!min):
  1776. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.less, parseInt(min, 10));
  1777. break;
  1778. case (!!max):
  1779. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.more, parseInt(max, 10));
  1780. break;
  1781. default:
  1782. break;
  1783. }
  1784. return { valid: isValid, message: message };
  1785. }
  1786. };
  1787. }(window.jQuery));
  1788. ;(function($) {
  1789. $.fn.bootstrapValidator.i18n.creditCard = $.extend($.fn.bootstrapValidator.i18n.creditCard || {}, {
  1790. 'default': 'Please enter a valid credit card number'
  1791. });
  1792. $.fn.bootstrapValidator.validators.creditCard = {
  1793. /**
  1794. * Return true if the input value is valid credit card number
  1795. * Based on https://gist.github.com/DiegoSalazar/4075533
  1796. *
  1797. * @param {BootstrapValidator} validator The validator plugin instance
  1798. * @param {jQuery} $field Field element
  1799. * @param {Object} [options] Can consist of the following key:
  1800. * - message: The invalid message
  1801. * @returns {Boolean}
  1802. */
  1803. validate: function(validator, $field, options) {
  1804. var value = $field.val();
  1805. if (value === '') {
  1806. return true;
  1807. }
  1808. // Accept only digits, dashes or spaces
  1809. if (/[^0-9-\s]+/.test(value)) {
  1810. return false;
  1811. }
  1812. value = value.replace(/\D/g, '');
  1813. if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
  1814. return false;
  1815. }
  1816. // Validate the card number based on prefix (IIN ranges) and length
  1817. var cards = {
  1818. AMERICAN_EXPRESS: {
  1819. length: [15],
  1820. prefix: ['34', '37']
  1821. },
  1822. DINERS_CLUB: {
  1823. length: [14],
  1824. prefix: ['300', '301', '302', '303', '304', '305', '36']
  1825. },
  1826. DINERS_CLUB_US: {
  1827. length: [16],
  1828. prefix: ['54', '55']
  1829. },
  1830. DISCOVER: {
  1831. length: [16],
  1832. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  1833. '62214', '62215', '62216', '62217', '62218', '62219',
  1834. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  1835. '62290', '62291', '622920', '622921', '622922', '622923',
  1836. '622924', '622925', '644', '645', '646', '647', '648',
  1837. '649', '65']
  1838. },
  1839. JCB: {
  1840. length: [16],
  1841. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  1842. },
  1843. LASER: {
  1844. length: [16, 17, 18, 19],
  1845. prefix: ['6304', '6706', '6771', '6709']
  1846. },
  1847. MAESTRO: {
  1848. length: [12, 13, 14, 15, 16, 17, 18, 19],
  1849. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  1850. },
  1851. MASTERCARD: {
  1852. length: [16],
  1853. prefix: ['51', '52', '53', '54', '55']
  1854. },
  1855. SOLO: {
  1856. length: [16, 18, 19],
  1857. prefix: ['6334', '6767']
  1858. },
  1859. UNIONPAY: {
  1860. length: [16, 17, 18, 19],
  1861. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  1862. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  1863. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  1864. '622920', '622921', '622922', '622923', '622924', '622925']
  1865. },
  1866. VISA: {
  1867. length: [16],
  1868. prefix: ['4']
  1869. }
  1870. };
  1871. var type, i;
  1872. for (type in cards) {
  1873. for (i in cards[type].prefix) {
  1874. if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  1875. && $.inArray(value.length, cards[type].length) !== -1) // and length
  1876. {
  1877. return true;
  1878. }
  1879. }
  1880. }
  1881. return false;
  1882. }
  1883. };
  1884. }(window.jQuery));
  1885. ;(function($) {
  1886. $.fn.bootstrapValidator.i18n.cusip = $.extend($.fn.bootstrapValidator.i18n.cusip || {}, {
  1887. 'default': 'Please enter a valid CUSIP number'
  1888. });
  1889. $.fn.bootstrapValidator.validators.cusip = {
  1890. /**
  1891. * Validate a CUSIP
  1892. * Examples:
  1893. * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  1894. * - Invalid: 31430F200, 022615AC2
  1895. *
  1896. * @see http://en.wikipedia.org/wiki/CUSIP
  1897. * @param {BootstrapValidator} validator The validator plugin instance
  1898. * @param {jQuery} $field Field element
  1899. * @param {Object} [options] Can consist of the following keys:
  1900. * - message: The invalid message
  1901. * @returns {Boolean}
  1902. */
  1903. validate: function(validator, $field, options) {
  1904. var value = $field.val();
  1905. if (value === '') {
  1906. return true;
  1907. }
  1908. value = value.toUpperCase();
  1909. if (!/^[0-9A-Z]{9}$/.test(value)) {
  1910. return false;
  1911. }
  1912. var converted = $.map(value.split(''), function(item) {
  1913. var code = item.charCodeAt(0);
  1914. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  1915. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  1916. ? (code - 'A'.charCodeAt(0) + 10)
  1917. : item;
  1918. }),
  1919. length = converted.length,
  1920. sum = 0;
  1921. for (var i = 0; i < length - 1; i++) {
  1922. var num = parseInt(converted[i], 10);
  1923. if (i % 2 !== 0) {
  1924. num *= 2;
  1925. }
  1926. if (num > 9) {
  1927. num -= 9;
  1928. }
  1929. sum += num;
  1930. }
  1931. sum = (10 - (sum % 10)) % 10;
  1932. return sum === converted[length - 1];
  1933. }
  1934. };
  1935. }(window.jQuery));
  1936. ;(function($) {
  1937. $.fn.bootstrapValidator.i18n.cvv = $.extend($.fn.bootstrapValidator.i18n.cvv || {}, {
  1938. 'default': 'Please enter a valid CVV number'
  1939. });
  1940. $.fn.bootstrapValidator.validators.cvv = {
  1941. html5Attributes: {
  1942. message: 'message',
  1943. ccfield: 'creditCardField'
  1944. },
  1945. /**
  1946. * Return true if the input value is a valid CVV number.
  1947. *
  1948. * @param {BootstrapValidator} validator The validator plugin instance
  1949. * @param {jQuery} $field Field element
  1950. * @param {Object} options Can consist of the following keys:
  1951. * - creditCardField: The credit card number field. It can be null
  1952. * - message: The invalid message
  1953. * @returns {Boolean}
  1954. */
  1955. validate: function(validator, $field, options) {
  1956. var value = $field.val();
  1957. if (value === '') {
  1958. return true;
  1959. }
  1960. if (!/^[0-9]{3,4}$/.test(value)) {
  1961. return false;
  1962. }
  1963. if (!options.creditCardField) {
  1964. return true;
  1965. }
  1966. // Get the credit card number
  1967. var creditCard = validator.getFieldElements(options.creditCardField).val();
  1968. if (creditCard === '') {
  1969. return true;
  1970. }
  1971. creditCard = creditCard.replace(/\D/g, '');
  1972. // Supported credit card types
  1973. var cards = {
  1974. AMERICAN_EXPRESS: {
  1975. length: [15],
  1976. prefix: ['34', '37']
  1977. },
  1978. DINERS_CLUB: {
  1979. length: [14],
  1980. prefix: ['300', '301', '302', '303', '304', '305', '36']
  1981. },
  1982. DINERS_CLUB_US: {
  1983. length: [16],
  1984. prefix: ['54', '55']
  1985. },
  1986. DISCOVER: {
  1987. length: [16],
  1988. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  1989. '62214', '62215', '62216', '62217', '62218', '62219',
  1990. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  1991. '62290', '62291', '622920', '622921', '622922', '622923',
  1992. '622924', '622925', '644', '645', '646', '647', '648',
  1993. '649', '65']
  1994. },
  1995. JCB: {
  1996. length: [16],
  1997. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  1998. },
  1999. LASER: {
  2000. length: [16, 17, 18, 19],
  2001. prefix: ['6304', '6706', '6771', '6709']
  2002. },
  2003. MAESTRO: {
  2004. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2005. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2006. },
  2007. MASTERCARD: {
  2008. length: [16],
  2009. prefix: ['51', '52', '53', '54', '55']
  2010. },
  2011. SOLO: {
  2012. length: [16, 18, 19],
  2013. prefix: ['6334', '6767']
  2014. },
  2015. UNIONPAY: {
  2016. length: [16, 17, 18, 19],
  2017. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2018. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2019. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2020. '622920', '622921', '622922', '622923', '622924', '622925']
  2021. },
  2022. VISA: {
  2023. length: [16],
  2024. prefix: ['4']
  2025. }
  2026. };
  2027. var type, i, creditCardType = null;
  2028. for (type in cards) {
  2029. for (i in cards[type].prefix) {
  2030. if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2031. && $.inArray(creditCard.length, cards[type].length) !== -1) // and length
  2032. {
  2033. creditCardType = type;
  2034. break;
  2035. }
  2036. }
  2037. }
  2038. return (creditCardType === null)
  2039. ? false
  2040. : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
  2041. }
  2042. };
  2043. }(window.jQuery));
  2044. ;(function($) {
  2045. $.fn.bootstrapValidator.i18n.date = $.extend($.fn.bootstrapValidator.i18n.date || {}, {
  2046. 'default': 'Please enter a valid date'
  2047. });
  2048. $.fn.bootstrapValidator.validators.date = {
  2049. html5Attributes: {
  2050. message: 'message',
  2051. format: 'format',
  2052. separator: 'separator'
  2053. },
  2054. /**
  2055. * Return true if the input value is valid date
  2056. *
  2057. * @param {BootstrapValidator} validator The validator plugin instance
  2058. * @param {jQuery} $field Field element
  2059. * @param {Object} options Can consist of the following keys:
  2060. * - message: The invalid message
  2061. * - separator: Use to separate the date, month, and year.
  2062. * By default, it is /
  2063. * - format: The date format. Default is MM/DD/YYYY
  2064. * The format can be:
  2065. *
  2066. * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  2067. * ii) date and time:
  2068. * The time can consist of h, m, s parts which are separated by :
  2069. * ii) date, time and A (indicating AM or PM)
  2070. * @returns {Boolean}
  2071. */
  2072. validate: function(validator, $field, options) {
  2073. var value = $field.val();
  2074. if (value === '') {
  2075. return true;
  2076. }
  2077. options.format = options.format || 'MM/DD/YYYY';
  2078. var formats = options.format.split(' '),
  2079. dateFormat = formats[0],
  2080. timeFormat = (formats.length > 1) ? formats[1] : null,
  2081. amOrPm = (formats.length > 2) ? formats[2] : null,
  2082. sections = value.split(' '),
  2083. date = sections[0],
  2084. time = (sections.length > 1) ? sections[1] : null;
  2085. if (formats.length !== sections.length) {
  2086. return false;
  2087. }
  2088. // Determine the separator
  2089. var separator = options.separator;
  2090. if (!separator) {
  2091. separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
  2092. }
  2093. if (separator === null || date.indexOf(separator) === -1) {
  2094. return false;
  2095. }
  2096. // Determine the date
  2097. date = date.split(separator);
  2098. dateFormat = dateFormat.split(separator);
  2099. if (date.length !== dateFormat.length) {
  2100. return false;
  2101. }
  2102. var year = date[$.inArray('YYYY', dateFormat)],
  2103. month = date[$.inArray('MM', dateFormat)],
  2104. day = date[$.inArray('DD', dateFormat)];
  2105. if (!year || !month || !day) {
  2106. return false;
  2107. }
  2108. // Determine the time
  2109. var minutes = null, hours = null, seconds = null;
  2110. if (timeFormat) {
  2111. timeFormat = timeFormat.split(':');
  2112. time = time.split(':');
  2113. if (timeFormat.length !== time.length) {
  2114. return false;
  2115. }
  2116. hours = time.length > 0 ? time[0] : null;
  2117. minutes = time.length > 1 ? time[1] : null;
  2118. seconds = time.length > 2 ? time[2] : null;
  2119. // Validate seconds
  2120. if (seconds) {
  2121. seconds = parseInt(seconds, 10);
  2122. if (isNaN(seconds) || seconds < 0 || seconds > 60) {
  2123. return false;
  2124. }
  2125. }
  2126. // Validate hours
  2127. if (hours) {
  2128. hours = parseInt(hours, 10);
  2129. if (isNaN(hours) || hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  2130. return false;
  2131. }
  2132. }
  2133. // Validate minutes
  2134. if (minutes) {
  2135. minutes = parseInt(minutes, 10);
  2136. if (isNaN(minutes) || minutes < 0 || minutes > 59) {
  2137. return false;
  2138. }
  2139. }
  2140. }
  2141. // Validate day, month, and year
  2142. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  2143. }
  2144. };
  2145. }(window.jQuery));
  2146. ;(function($) {
  2147. $.fn.bootstrapValidator.i18n.different = $.extend($.fn.bootstrapValidator.i18n.different || {}, {
  2148. 'default': 'Please enter a different value'
  2149. });
  2150. $.fn.bootstrapValidator.validators.different = {
  2151. html5Attributes: {
  2152. message: 'message',
  2153. field: 'field'
  2154. },
  2155. /**
  2156. * Return true if the input value is different with given field's value
  2157. *
  2158. * @param {BootstrapValidator} validator The validator plugin instance
  2159. * @param {jQuery} $field Field element
  2160. * @param {Object} options Consists of the following key:
  2161. * - field: The name of field that will be used to compare with current one
  2162. * - message: The invalid message
  2163. * @returns {Boolean}
  2164. */
  2165. validate: function(validator, $field, options) {
  2166. var value = $field.val();
  2167. if (value === '') {
  2168. return true;
  2169. }
  2170. var compareWith = validator.getFieldElements(options.field);
  2171. if (compareWith === null) {
  2172. return true;
  2173. }
  2174. if (value !== compareWith.val()) {
  2175. validator.updateStatus(options.field, validator.STATUS_VALID, 'different');
  2176. return true;
  2177. } else {
  2178. return false;
  2179. }
  2180. }
  2181. };
  2182. }(window.jQuery));
  2183. ;(function($) {
  2184. $.fn.bootstrapValidator.i18n.digits = $.extend($.fn.bootstrapValidator.i18n.digits || {}, {
  2185. 'default': 'Please enter only digits'
  2186. });
  2187. $.fn.bootstrapValidator.validators.digits = {
  2188. /**
  2189. * Return true if the input value contains digits only
  2190. *
  2191. * @param {BootstrapValidator} validator Validate plugin instance
  2192. * @param {jQuery} $field Field element
  2193. * @param {Object} [options]
  2194. * @returns {Boolean}
  2195. */
  2196. validate: function(validator, $field, options) {
  2197. var value = $field.val();
  2198. if (value === '') {
  2199. return true;
  2200. }
  2201. return /^\d+$/.test(value);
  2202. }
  2203. };
  2204. }(window.jQuery));
  2205. ;(function($) {
  2206. $.fn.bootstrapValidator.i18n.ean = $.extend($.fn.bootstrapValidator.i18n.ean || {}, {
  2207. 'default': 'Please enter a valid EAN number'
  2208. });
  2209. $.fn.bootstrapValidator.validators.ean = {
  2210. /**
  2211. * Validate EAN (International Article Number)
  2212. * Examples:
  2213. * - Valid: 73513537, 9780471117094, 4006381333931
  2214. * - Invalid: 73513536
  2215. *
  2216. * @see http://en.wikipedia.org/wiki/European_Article_Number
  2217. * @param {BootstrapValidator} validator The validator plugin instance
  2218. * @param {jQuery} $field Field element
  2219. * @param {Object} options Can consist of the following keys:
  2220. * - message: The invalid message
  2221. * @returns {Boolean}
  2222. */
  2223. validate: function(validator, $field, options) {
  2224. var value = $field.val();
  2225. if (value === '') {
  2226. return true;
  2227. }
  2228. if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  2229. return false;
  2230. }
  2231. var length = value.length,
  2232. sum = 0,
  2233. weight = (length === 8) ? [3, 1] : [1, 3];
  2234. for (var i = 0; i < length - 1; i++) {
  2235. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  2236. }
  2237. sum = (10 - sum % 10) % 10;
  2238. return (sum + '' === value.charAt(length - 1));
  2239. }
  2240. };
  2241. }(window.jQuery));
  2242. ;(function($) {
  2243. $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
  2244. 'default': 'Please enter a valid email address'
  2245. });
  2246. $.fn.bootstrapValidator.validators.emailAddress = {
  2247. enableByHtml5: function($field) {
  2248. return ('email' === $field.attr('type'));
  2249. },
  2250. /**
  2251. * Return true if and only if the input value is a valid email address
  2252. *
  2253. * @param {BootstrapValidator} validator Validate plugin instance
  2254. * @param {jQuery} $field Field element
  2255. * @param {Object} [options]
  2256. * @returns {Boolean}
  2257. */
  2258. validate: function(validator, $field, options) {
  2259. var value = $field.val();
  2260. if (value === '') {
  2261. return true;
  2262. }
  2263. // Email address regular expression
  2264. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  2265. var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  2266. return emailRegExp.test(value);
  2267. }
  2268. };
  2269. }(window.jQuery));
  2270. ;(function($) {
  2271. $.fn.bootstrapValidator.i18n.file = $.extend($.fn.bootstrapValidator.i18n.file || {}, {
  2272. 'default': 'Please choose a valid file'
  2273. });
  2274. $.fn.bootstrapValidator.validators.file = {
  2275. html5Attributes: {
  2276. extension: 'extension',
  2277. maxsize: 'maxSize',
  2278. message: 'message',
  2279. type: 'type'
  2280. },
  2281. /**
  2282. * Validate upload file. Use HTML 5 API if the browser supports
  2283. *
  2284. * @param {BootstrapValidator} validator The validator plugin instance
  2285. * @param {jQuery} $field Field element
  2286. * @param {Object} options Can consist of the following keys:
  2287. * - extension: The allowed extensions, separated by a comma
  2288. * - maxSize: The maximum size in bytes
  2289. * - message: The invalid message
  2290. * - type: The allowed MIME type, separated by a comma
  2291. * @returns {Boolean}
  2292. */
  2293. validate: function(validator, $field, options) {
  2294. var value = $field.val();
  2295. if (value === '') {
  2296. return true;
  2297. }
  2298. var ext,
  2299. extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  2300. types = options.type ? options.type.toLowerCase().split(',') : null,
  2301. html5 = (window.File && window.FileList && window.FileReader);
  2302. if (html5) {
  2303. // Get FileList instance
  2304. var files = $field.get(0).files,
  2305. total = files.length;
  2306. for (var i = 0; i < total; i++) {
  2307. // Check file size
  2308. if (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) {
  2309. return false;
  2310. }
  2311. // Check file extension
  2312. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  2313. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2314. return false;
  2315. }
  2316. // Check file type
  2317. if (types && $.inArray(files[i].type.toLowerCase(), types) === -1) {
  2318. return false;
  2319. }
  2320. }
  2321. } else {
  2322. // Check file extension
  2323. ext = value.substr(value.lastIndexOf('.') + 1);
  2324. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2325. return false;
  2326. }
  2327. }
  2328. return true;
  2329. }
  2330. };
  2331. }(window.jQuery));
  2332. ;(function($) {
  2333. $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
  2334. 'default': 'Please enter a value greater than or equal to %s',
  2335. notInclusive: 'Please enter a value greater than %s'
  2336. });
  2337. $.fn.bootstrapValidator.validators.greaterThan = {
  2338. html5Attributes: {
  2339. message: 'message',
  2340. value: 'value',
  2341. inclusive: 'inclusive'
  2342. },
  2343. enableByHtml5: function($field) {
  2344. var min = $field.attr('min');
  2345. if (min) {
  2346. return {
  2347. value: min
  2348. };
  2349. }
  2350. return false;
  2351. },
  2352. /**
  2353. * Return true if the input value is greater than or equals to given number
  2354. *
  2355. * @param {BootstrapValidator} validator Validate plugin instance
  2356. * @param {jQuery} $field Field element
  2357. * @param {Object} options Can consist of the following keys:
  2358. * - value: Define the number to compare with. It can be
  2359. * - A number
  2360. * - Name of field which its value defines the number
  2361. * - Name of callback function that returns the number
  2362. * - A callback function that returns the number
  2363. *
  2364. * - inclusive [optional]: Can be true or false. Default is true
  2365. * - message: The invalid message
  2366. * @returns {Boolean|Object}
  2367. */
  2368. validate: function(validator, $field, options) {
  2369. var value = $field.val();
  2370. if (value === '') {
  2371. return true;
  2372. }
  2373. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption(options.value, $field);
  2374. value = parseFloat(value);
  2375. return (options.inclusive === true || options.inclusive === undefined)
  2376. ? {
  2377. valid: value >= compareTo,
  2378. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan['default'], compareTo)
  2379. }
  2380. : {
  2381. valid: value > compareTo,
  2382. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan.notInclusive, compareTo)
  2383. };
  2384. }
  2385. };
  2386. }(window.jQuery));
  2387. ;(function($) {
  2388. $.fn.bootstrapValidator.i18n.grid = $.extend($.fn.bootstrapValidator.i18n.grid || {}, {
  2389. 'default': 'Please enter a valid GRId number'
  2390. });
  2391. $.fn.bootstrapValidator.validators.grid = {
  2392. /**
  2393. * Validate GRId (Global Release Identifier)
  2394. * Examples:
  2395. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  2396. * - Invalid: A1-2425G-ABC1234002-Q
  2397. *
  2398. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  2399. * @param {BootstrapValidator} validator The validator plugin instance
  2400. * @param {jQuery} $field Field element
  2401. * @param {Object} options Can consist of the following keys:
  2402. * - message: The invalid message
  2403. * @returns {Boolean}
  2404. */
  2405. validate: function(validator, $field, options) {
  2406. var value = $field.val();
  2407. if (value === '') {
  2408. return true;
  2409. }
  2410. value = value.toUpperCase();
  2411. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  2412. return false;
  2413. }
  2414. value = value.replace(/\s/g, '').replace(/-/g, '');
  2415. if ('GRID:' === value.substr(0, 5)) {
  2416. value = value.substr(5);
  2417. }
  2418. return $.fn.bootstrapValidator.helpers.mod37And36(value);
  2419. }
  2420. };
  2421. }(window.jQuery));
  2422. ;(function($) {
  2423. $.fn.bootstrapValidator.i18n.hex = $.extend($.fn.bootstrapValidator.i18n.hex || {}, {
  2424. 'default': 'Please enter a valid hexadecimal number'
  2425. });
  2426. $.fn.bootstrapValidator.validators.hex = {
  2427. /**
  2428. * Return true if and only if the input value is a valid hexadecimal number
  2429. *
  2430. * @param {BootstrapValidator} validator The validator plugin instance
  2431. * @param {jQuery} $field Field element
  2432. * @param {Object} options Consist of key:
  2433. * - message: The invalid message
  2434. * @returns {Boolean}
  2435. */
  2436. validate: function(validator, $field, options) {
  2437. var value = $field.val();
  2438. if (value === '') {
  2439. return true;
  2440. }
  2441. return /^[0-9a-fA-F]+$/.test(value);
  2442. }
  2443. };
  2444. }(window.jQuery));
  2445. ;(function($) {
  2446. $.fn.bootstrapValidator.i18n.hexColor = $.extend($.fn.bootstrapValidator.i18n.hexColor || {}, {
  2447. 'default': 'Please enter a valid hex color'
  2448. });
  2449. $.fn.bootstrapValidator.validators.hexColor = {
  2450. enableByHtml5: function($field) {
  2451. return ('color' === $field.attr('type'));
  2452. },
  2453. /**
  2454. * Return true if the input value is a valid hex color
  2455. *
  2456. * @param {BootstrapValidator} validator The validator plugin instance
  2457. * @param {jQuery} $field Field element
  2458. * @param {Object} options Can consist of the following keys:
  2459. * - message: The invalid message
  2460. * @returns {Boolean}
  2461. */
  2462. validate: function(validator, $field, options) {
  2463. var value = $field.val();
  2464. if (value === '') {
  2465. return true;
  2466. }
  2467. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2468. }
  2469. };
  2470. }(window.jQuery));
  2471. ;(function($) {
  2472. $.fn.bootstrapValidator.i18n.iban = $.extend($.fn.bootstrapValidator.i18n.iban || {}, {
  2473. 'default': 'Please enter a valid IBAN number',
  2474. countryNotSupported: 'The country code %s is not supported',
  2475. country: 'Please enter a valid IBAN number in %s',
  2476. countries: {
  2477. AD: 'Andorra',
  2478. AE: 'United Arab Emirates',
  2479. AL: 'Albania',
  2480. AO: 'Angola',
  2481. AT: 'Austria',
  2482. AZ: 'Azerbaijan',
  2483. BA: 'Bosnia and Herzegovina',
  2484. BE: 'Belgium',
  2485. BF: 'Burkina Faso',
  2486. BG: 'Bulgaria',
  2487. BH: 'Bahrain',
  2488. BI: 'Burundi',
  2489. BJ: 'Benin',
  2490. BR: 'Brazil',
  2491. CH: 'Switzerland',
  2492. CI: 'Ivory Coast',
  2493. CM: 'Cameroon',
  2494. CR: 'Costa Rica',
  2495. CV: 'Cape Verde',
  2496. CY: 'Cyprus',
  2497. CZ: 'Czech Republic',
  2498. DE: 'Germany',
  2499. DK: 'Denmark',
  2500. DO: 'Dominican Republic',
  2501. DZ: 'Algeria',
  2502. EE: 'Estonia',
  2503. ES: 'Spain',
  2504. FI: 'Finland',
  2505. FO: 'Faroe Islands',
  2506. FR: 'France',
  2507. GB: 'United Kingdom',
  2508. GE: 'Georgia',
  2509. GI: 'Gibraltar',
  2510. GL: 'Greenland',
  2511. GR: 'Greece',
  2512. GT: 'Guatemala',
  2513. HR: 'Croatia',
  2514. HU: 'Hungary',
  2515. IE: 'Ireland',
  2516. IL: 'Israel',
  2517. IR: 'Iran',
  2518. IS: 'Iceland',
  2519. IT: 'Italy',
  2520. JO: 'Jordan',
  2521. KW: 'Kuwait',
  2522. KZ: 'Kazakhstan',
  2523. LB: 'Lebanon',
  2524. LI: 'Liechtenstein',
  2525. LT: 'Lithuania',
  2526. LU: 'Luxembourg',
  2527. LV: 'Latvia',
  2528. MC: 'Monaco',
  2529. MD: 'Moldova',
  2530. ME: 'Montenegro',
  2531. MG: 'Madagascar',
  2532. MK: 'Macedonia',
  2533. ML: 'Mali',
  2534. MR: 'Mauritania',
  2535. MT: 'Malta',
  2536. MU: 'Mauritius',
  2537. MZ: 'Mozambique',
  2538. NL: 'Netherlands',
  2539. NO: 'Norway',
  2540. PK: 'Pakistan',
  2541. PL: 'Poland',
  2542. PS: 'Palestinian',
  2543. PT: 'Portugal',
  2544. QA: 'Qatar',
  2545. RO: 'Romania',
  2546. RS: 'Serbia',
  2547. SA: 'Saudi Arabia',
  2548. SE: 'Sweden',
  2549. SI: 'Slovenia',
  2550. SK: 'Slovakia',
  2551. SM: 'San Marino',
  2552. SN: 'Senegal',
  2553. TN: 'Tunisia',
  2554. TR: 'Turkey',
  2555. VG: 'Virgin Islands, British'
  2556. }
  2557. });
  2558. $.fn.bootstrapValidator.validators.iban = {
  2559. html5Attributes: {
  2560. message: 'message',
  2561. country: 'country'
  2562. },
  2563. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  2564. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  2565. REGEX: {
  2566. 'AD': 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  2567. 'AE': 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  2568. 'AL': 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  2569. 'AO': 'AO[0-9]{2}[0-9]{21}', // Angola
  2570. 'AT': 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  2571. 'AZ': 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  2572. 'BA': 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  2573. 'BE': 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  2574. 'BF': 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  2575. 'BG': 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  2576. 'BH': 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  2577. 'BI': 'BI[0-9]{2}[0-9]{12}', // Burundi
  2578. 'BJ': 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  2579. 'BR': 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  2580. 'CH': 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  2581. 'CI': 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  2582. 'CM': 'CM[0-9]{2}[0-9]{23}', // Cameroon
  2583. 'CR': 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  2584. 'CV': 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  2585. 'CY': 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  2586. 'CZ': 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  2587. 'DE': 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  2588. 'DK': 'DK[0-9]{2}[0-9]{14}', // Denmark
  2589. 'DO': 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  2590. 'DZ': 'DZ[0-9]{2}[0-9]{20}', // Algeria
  2591. 'EE': 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  2592. 'ES': 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  2593. 'FI': 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  2594. 'FO': 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  2595. 'FR': 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  2596. 'GB': 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  2597. 'GE': 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  2598. 'GI': 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  2599. 'GL': 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland
  2600. 'GR': 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  2601. 'GT': 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  2602. 'HR': 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  2603. 'HU': 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  2604. 'IE': 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  2605. 'IL': 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  2606. 'IR': 'IR[0-9]{2}[0-9]{22}', // Iran
  2607. 'IS': 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  2608. 'IT': 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  2609. 'JO': 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  2610. 'KW': 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  2611. 'KZ': 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  2612. 'LB': 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  2613. 'LI': 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  2614. 'LT': 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  2615. 'LU': 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  2616. 'LV': 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  2617. 'MC': 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  2618. 'MD': 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  2619. 'ME': 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  2620. 'MG': 'MG[0-9]{2}[0-9]{23}', // Madagascar
  2621. 'MK': 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  2622. 'ML': 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  2623. 'MR': 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  2624. 'MT': 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  2625. 'MU': 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}',// Mauritius
  2626. 'MZ': 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  2627. 'NL': 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  2628. 'NO': 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  2629. 'PK': 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  2630. 'PL': 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  2631. 'PS': 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  2632. 'PT': 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  2633. 'QA': 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  2634. 'RO': 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  2635. 'RS': 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  2636. 'SA': 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  2637. 'SE': 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  2638. 'SI': 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  2639. 'SK': 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  2640. 'SM': 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  2641. 'SN': 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  2642. 'TN': 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  2643. 'TR': 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  2644. 'VG': 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  2645. },
  2646. /**
  2647. * Validate an International Bank Account Number (IBAN)
  2648. * To test it, take the sample IBAN from
  2649. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  2650. *
  2651. * @param {BootstrapValidator} validator The validator plugin instance
  2652. * @param {jQuery} $field Field element
  2653. * @param {Object} options Can consist of the following keys:
  2654. * - message: The invalid message
  2655. * - country: The ISO 3166-1 country code. It can be
  2656. * - A country code
  2657. * - Name of field which its value defines the country code
  2658. * - Name of callback function that returns the country code
  2659. * - A callback function that returns the country code
  2660. * @returns {Boolean|Object}
  2661. */
  2662. validate: function(validator, $field, options) {
  2663. var value = $field.val();
  2664. if (value === '') {
  2665. return true;
  2666. }
  2667. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  2668. var country = options.country;
  2669. if (!country) {
  2670. country = value.substr(0, 2);
  2671. } else if (typeof country !== 'string' || !this.REGEX[country]) {
  2672. // Determine the country code
  2673. country = validator.getDynamicOption(country, $field);
  2674. }
  2675. if (!this.REGEX[country]) {
  2676. return {
  2677. valid: false,
  2678. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.iban.countryNotSupported, country)
  2679. };
  2680. }
  2681. if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
  2682. return {
  2683. valid: false,
  2684. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  2685. };
  2686. }
  2687. value = value.substr(4) + value.substr(0, 4);
  2688. value = $.map(value.split(''), function(n) {
  2689. var code = n.charCodeAt(0);
  2690. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  2691. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  2692. ? (code - 'A'.charCodeAt(0) + 10)
  2693. : n;
  2694. });
  2695. value = value.join('');
  2696. var temp = parseInt(value.substr(0, 1), 10),
  2697. length = value.length;
  2698. for (var i = 1; i < length; ++i) {
  2699. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  2700. }
  2701. return {
  2702. valid: (temp === 1),
  2703. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  2704. };
  2705. }
  2706. };
  2707. }(window.jQuery));
  2708. ;(function($) {
  2709. $.fn.bootstrapValidator.i18n.id = $.extend($.fn.bootstrapValidator.i18n.id || {}, {
  2710. 'default': 'Please enter a valid identification number',
  2711. countryNotSupported: 'The country code %s is not supported',
  2712. country: 'Please enter a valid %s identification number',
  2713. countries: {
  2714. BA: 'Bosnia and Herzegovina',
  2715. BG: 'Bulgarian',
  2716. BR: 'Brazilian',
  2717. CH: 'Swiss',
  2718. CL: 'Chilean',
  2719. CZ: 'Czech',
  2720. DK: 'Danish',
  2721. EE: 'Estonian',
  2722. ES: 'Spanish',
  2723. FI: 'Finnish',
  2724. HR: 'Croatian',
  2725. IE: 'Irish',
  2726. IS: 'Iceland',
  2727. LT: 'Lithuanian',
  2728. LV: 'Latvian',
  2729. ME: 'Montenegro',
  2730. MK: 'Macedonian',
  2731. NL: 'Dutch',
  2732. RO: 'Romanian',
  2733. RS: 'Serbian',
  2734. SE: 'Swedish',
  2735. SI: 'Slovenian',
  2736. SK: 'Slovak',
  2737. SM: 'San Marino',
  2738. ZA: 'South African'
  2739. }
  2740. });
  2741. $.fn.bootstrapValidator.validators.id = {
  2742. html5Attributes: {
  2743. message: 'message',
  2744. country: 'country'
  2745. },
  2746. // Supported country codes
  2747. COUNTRY_CODES: [
  2748. 'BA', 'BG', 'BR', 'CH', 'CL', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL',
  2749. 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'ZA'
  2750. ],
  2751. /**
  2752. * Validate identification number in different countries
  2753. *
  2754. * @see http://en.wikipedia.org/wiki/National_identification_number
  2755. * @param {BootstrapValidator} validator The validator plugin instance
  2756. * @param {jQuery} $field Field element
  2757. * @param {Object} options Consist of key:
  2758. * - message: The invalid message
  2759. * - country: The ISO 3166-1 country code. It can be
  2760. * - One of country code defined in COUNTRY_CODES
  2761. * - Name of field which its value defines the country code
  2762. * - Name of callback function that returns the country code
  2763. * - A callback function that returns the country code
  2764. * @returns {Boolean|Object}
  2765. */
  2766. validate: function(validator, $field, options) {
  2767. var value = $field.val();
  2768. if (value === '') {
  2769. return true;
  2770. }
  2771. var country = options.country;
  2772. if (!country) {
  2773. country = value.substr(0, 2);
  2774. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  2775. // Determine the country code
  2776. country = validator.getDynamicOption(country, $field);
  2777. }
  2778. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  2779. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.id.countryNotSupported, country) };
  2780. }
  2781. var method = ['_', country.toLowerCase()].join('');
  2782. return this[method](value)
  2783. ? true
  2784. : {
  2785. valid: false,
  2786. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.id.country, $.fn.bootstrapValidator.i18n.id.countries[country.toUpperCase()])
  2787. };
  2788. },
  2789. /**
  2790. * Validate Unique Master Citizen Number which uses in
  2791. * - Bosnia and Herzegovina (country code: BA)
  2792. * - Macedonia (MK)
  2793. * - Montenegro (ME)
  2794. * - Serbia (RS)
  2795. * - Slovenia (SI)
  2796. *
  2797. * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  2798. * @param {String} value The ID
  2799. * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  2800. * @returns {Boolean}
  2801. */
  2802. _validateJMBG: function(value, countryCode) {
  2803. if (!/^\d{13}$/.test(value)) {
  2804. return false;
  2805. }
  2806. var day = parseInt(value.substr(0, 2), 10),
  2807. month = parseInt(value.substr(2, 2), 10),
  2808. year = parseInt(value.substr(4, 3), 10),
  2809. rr = parseInt(value.substr(7, 2), 10),
  2810. k = parseInt(value.substr(12, 1), 10);
  2811. // Validate date of birth
  2812. // FIXME: Validate the year of birth
  2813. if (day > 31 || month > 12) {
  2814. return false;
  2815. }
  2816. // Validate checksum
  2817. var sum = 0;
  2818. for (var i = 0; i < 6; i++) {
  2819. sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
  2820. }
  2821. sum = 11 - sum % 11;
  2822. if (sum === 10 || sum === 11) {
  2823. sum = 0;
  2824. }
  2825. if (sum !== k) {
  2826. return false;
  2827. }
  2828. // Validate political region
  2829. // rr is the political region of birth, which can be in ranges:
  2830. // 10-19: Bosnia and Herzegovina
  2831. // 20-29: Montenegro
  2832. // 30-39: Croatia (not used anymore)
  2833. // 41-49: Macedonia
  2834. // 50-59: Slovenia (only 50 is used)
  2835. // 70-79: Central Serbia
  2836. // 80-89: Serbian province of Vojvodina
  2837. // 90-99: Kosovo
  2838. switch (countryCode.toUpperCase()) {
  2839. case 'BA':
  2840. return (10 <= rr && rr <= 19);
  2841. case 'MK':
  2842. return (41 <= rr && rr <= 49);
  2843. case 'ME':
  2844. return (20 <= rr && rr <= 29);
  2845. case 'RS':
  2846. return (70 <= rr && rr <= 99);
  2847. case 'SI':
  2848. return (50 <= rr && rr <= 59);
  2849. default:
  2850. return true;
  2851. }
  2852. },
  2853. _ba: function(value) {
  2854. return this._validateJMBG(value, 'BA');
  2855. },
  2856. _mk: function(value) {
  2857. return this._validateJMBG(value, 'MK');
  2858. },
  2859. _me: function(value) {
  2860. return this._validateJMBG(value, 'ME');
  2861. },
  2862. _rs: function(value) {
  2863. return this._validateJMBG(value, 'RS');
  2864. },
  2865. /**
  2866. * Examples: 0101006500006
  2867. */
  2868. _si: function(value) {
  2869. return this._validateJMBG(value, 'SI');
  2870. },
  2871. /**
  2872. * Validate Bulgarian national identification number (EGN)
  2873. * Examples:
  2874. * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  2875. * - Invalid: 8019010008
  2876. *
  2877. * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  2878. * @param {String} value The ID
  2879. * @returns {Boolean}
  2880. */
  2881. _bg: function(value) {
  2882. if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  2883. return false;
  2884. }
  2885. value = value.replace(/\s/g, '');
  2886. // Check the birth date
  2887. var year = parseInt(value.substr(0, 2), 10) + 1900,
  2888. month = parseInt(value.substr(2, 2), 10),
  2889. day = parseInt(value.substr(4, 2), 10);
  2890. if (month > 40) {
  2891. year += 100;
  2892. month -= 40;
  2893. } else if (month > 20) {
  2894. year -= 100;
  2895. month -= 20;
  2896. }
  2897. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2898. return false;
  2899. }
  2900. var sum = 0,
  2901. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2902. for (var i = 0; i < 9; i++) {
  2903. sum += parseInt(value.charAt(i), 10) * weight[i];
  2904. }
  2905. sum = (sum % 11) % 10;
  2906. return (sum + '' === value.substr(9, 1));
  2907. },
  2908. /**
  2909. * Validate Brazilian national identification number (CPF)
  2910. * Examples:
  2911. * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  2912. * - Invalid: 231.002.999-00
  2913. *
  2914. * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  2915. * @param {String} value The ID
  2916. * @returns {Boolean}
  2917. */
  2918. _br: function(value) {
  2919. if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  2920. return false;
  2921. }
  2922. if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
  2923. return false;
  2924. }
  2925. value = value.replace(/\./g, '').replace(/-/g, '');
  2926. var d1 = 0;
  2927. for (var i = 0; i < 9; i++) {
  2928. d1 += (10 - i) * parseInt(value.charAt(i), 10);
  2929. }
  2930. d1 = 11 - d1 % 11;
  2931. if (d1 === 10 || d1 === 11) {
  2932. d1 = 0;
  2933. }
  2934. if (d1 + '' !== value.charAt(9)) {
  2935. return false;
  2936. }
  2937. var d2 = 0;
  2938. for (i = 0; i < 10; i++) {
  2939. d2 += (11 - i) * parseInt(value.charAt(i), 10);
  2940. }
  2941. d2 = 11 - d2 % 11;
  2942. if (d2 === 10 || d2 === 11) {
  2943. d2 = 0;
  2944. }
  2945. return (d2 + '' === value.charAt(10));
  2946. },
  2947. /**
  2948. * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  2949. * Examples:
  2950. * - Valid: 756.1234.5678.95, 7561234567895
  2951. *
  2952. * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  2953. * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  2954. * @param {String} value The ID
  2955. * @returns {Boolean}
  2956. */
  2957. _ch: function(value) {
  2958. if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  2959. return false;
  2960. }
  2961. value = value.replace(/\D/g, '').substr(3);
  2962. var length = value.length,
  2963. sum = 0,
  2964. weight = (length === 8) ? [3, 1] : [1, 3];
  2965. for (var i = 0; i < length - 1; i++) {
  2966. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  2967. }
  2968. sum = 10 - sum % 10;
  2969. return (sum + '' === value.charAt(length - 1));
  2970. },
  2971. /**
  2972. * Validate Chilean national identification number (RUN/RUT)
  2973. * Examples:
  2974. * - Valid: 76086428-5, 22060449-7, 12531909-2
  2975. *
  2976. * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  2977. * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  2978. * @param {String} value The ID
  2979. * @returns {Boolean}
  2980. */
  2981. _cl: function(value) {
  2982. if (!/^\d{7,8}[-]{0,1}[0-9K]$/.test(value)) {
  2983. return false;
  2984. }
  2985. value = value.replace(/\D/g, '');
  2986. while (value.length < 9) {
  2987. value = '0' + value;
  2988. }
  2989. var sum = 0,
  2990. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  2991. for (var i = 0; i < 8; i++) {
  2992. sum += parseInt(value.charAt(i), 10) * weight[i];
  2993. }
  2994. sum = 11 - sum % 11;
  2995. if (sum === 11) {
  2996. sum = 0;
  2997. } else if (sum === 10) {
  2998. sum = 'K';
  2999. }
  3000. return sum + '' === value.charAt(8);
  3001. },
  3002. /**
  3003. * Validate Czech national identification number (RC)
  3004. * Examples:
  3005. * - Valid: 7103192745, 991231123
  3006. * - Invalid: 1103492745, 590312123
  3007. *
  3008. * @param {String} value The ID
  3009. * @returns {Boolean}
  3010. */
  3011. _cz: function(value) {
  3012. if (!/^\d{9,10}$/.test(value)) {
  3013. return false;
  3014. }
  3015. var year = 1900 + parseInt(value.substr(0, 2), 10),
  3016. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  3017. day = parseInt(value.substr(4, 2), 10);
  3018. if (value.length === 9) {
  3019. if (year >= 1980) {
  3020. year -= 100;
  3021. }
  3022. if (year > 1953) {
  3023. return false;
  3024. }
  3025. } else if (year < 1954) {
  3026. year += 100;
  3027. }
  3028. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3029. return false;
  3030. }
  3031. // Check that the birth date is not in the future
  3032. if (value.length === 10) {
  3033. var check = parseInt(value.substr(0, 9), 10) % 11;
  3034. if (year < 1985) {
  3035. check = check % 10;
  3036. }
  3037. return (check + '' === value.substr(9, 1));
  3038. }
  3039. return true;
  3040. },
  3041. /**
  3042. * Validate Danish Personal Identification number (CPR)
  3043. * Examples:
  3044. * - Valid: 2110625629, 211062-5629
  3045. * - Invalid: 511062-5629
  3046. *
  3047. * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  3048. * @param {String} value The ID
  3049. * @returns {Boolean}
  3050. */
  3051. _dk: function(value) {
  3052. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  3053. return false;
  3054. }
  3055. value = value.replace(/-/g, '');
  3056. var day = parseInt(value.substr(0, 2), 10),
  3057. month = parseInt(value.substr(2, 2), 10),
  3058. year = parseInt(value.substr(4, 2), 10);
  3059. switch (true) {
  3060. case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
  3061. year += 1800;
  3062. break;
  3063. case ('0123'.indexOf(value.charAt(6)) !== -1):
  3064. case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
  3065. year += 1900;
  3066. break;
  3067. default:
  3068. year += 2000;
  3069. break;
  3070. }
  3071. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  3072. },
  3073. /**
  3074. * Validate Estonian Personal Identification Code (isikukood)
  3075. * Examples:
  3076. * - Valid: 37605030299
  3077. *
  3078. * @see http://et.wikipedia.org/wiki/Isikukood
  3079. * @param {String} value The ID
  3080. * @returns {Boolean}
  3081. */
  3082. _ee: function(value) {
  3083. // Use the same format as Lithuanian Personal Code
  3084. return this._lt(value);
  3085. },
  3086. /**
  3087. * Validate Spanish personal identity code (DNI)
  3088. * Support i) DNI (for Spanish citizens) and ii) NIE (for foreign people)
  3089. *
  3090. * Examples:
  3091. * - Valid: i) 54362315K, 54362315-K; ii) X2482300W, X-2482300W, X-2482300-W
  3092. * - Invalid: i) 54362315Z; ii) X-2482300A
  3093. *
  3094. * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  3095. * @param {String} value The ID
  3096. * @returns {Boolean}
  3097. */
  3098. _es: function(value) {
  3099. if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]$/.test(value) // DNI
  3100. && !/^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-Z]$/.test(value)) { // NIE
  3101. return false;
  3102. }
  3103. value = value.replace(/-/g, '');
  3104. var index = 'XYZ'.indexOf(value.charAt(0));
  3105. if (index !== -1) {
  3106. // It is NIE number
  3107. value = index + value.substr(1) + '';
  3108. }
  3109. var check = parseInt(value.substr(0, 8), 10);
  3110. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  3111. return (check === value.substr(8, 1));
  3112. },
  3113. /**
  3114. * Validate Finnish Personal Identity Code (HETU)
  3115. * Examples:
  3116. * - Valid: 311280-888Y, 131052-308T
  3117. * - Invalid: 131052-308U, 310252-308Y
  3118. *
  3119. * @param {String} value The ID
  3120. * @returns {Boolean}
  3121. */
  3122. _fi: function(value) {
  3123. if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  3124. return false;
  3125. }
  3126. var day = parseInt(value.substr(0, 2), 10),
  3127. month = parseInt(value.substr(2, 2), 10),
  3128. year = parseInt(value.substr(4, 2), 10),
  3129. centuries = {
  3130. '+': 1800,
  3131. '-': 1900,
  3132. 'A': 2000
  3133. };
  3134. year = centuries[value.charAt(6)] + year;
  3135. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3136. return false;
  3137. }
  3138. var individual = parseInt(value.substr(7, 3), 10);
  3139. if (individual < 2) {
  3140. return false;
  3141. }
  3142. var n = value.substr(0, 6) + value.substr(7, 3) + '';
  3143. n = parseInt(n, 10);
  3144. return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
  3145. },
  3146. /**
  3147. * Validate Croatian personal identification number (OIB)
  3148. * Examples:
  3149. * - Valid: 33392005961
  3150. * - Invalid: 33392005962
  3151. *
  3152. * @param {String} value The ID
  3153. * @returns {Boolean}
  3154. */
  3155. _hr: function(value) {
  3156. if (!/^[0-9]{11}$/.test(value)) {
  3157. return false;
  3158. }
  3159. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  3160. },
  3161. /**
  3162. * Validate Irish Personal Public Service Number (PPS)
  3163. * Examples:
  3164. * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  3165. * - Invalid: 6433435E, 6433435VH
  3166. *
  3167. * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  3168. * @param {String} value The ID
  3169. * @returns {Boolean}
  3170. */
  3171. _ie: function(value) {
  3172. if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  3173. return false;
  3174. }
  3175. var getCheckDigit = function(value) {
  3176. while (value.length < 7) {
  3177. value = '0' + value;
  3178. }
  3179. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  3180. sum = 0;
  3181. for (var i = 0; i < 7; i++) {
  3182. sum += parseInt(value.charAt(i), 10) * (8 - i);
  3183. }
  3184. sum += 9 * alphabet.indexOf(value.substr(7));
  3185. return alphabet[sum % 23];
  3186. };
  3187. // 2013 format
  3188. if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
  3189. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  3190. }
  3191. // The old format
  3192. else {
  3193. return value.charAt(7) === getCheckDigit(value.substr(0, 7));
  3194. }
  3195. },
  3196. /**
  3197. * Validate Iceland national identification number (Kennitala)
  3198. * Examples:
  3199. * - Valid: 120174-3399, 1201743399, 0902862349
  3200. *
  3201. * @see http://en.wikipedia.org/wiki/Kennitala
  3202. * @param {String} value The ID
  3203. * @returns {Boolean}
  3204. */
  3205. _is: function(value) {
  3206. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  3207. return false;
  3208. }
  3209. value = value.replace(/-/g, '');
  3210. var day = parseInt(value.substr(0, 2), 10),
  3211. month = parseInt(value.substr(2, 2), 10),
  3212. year = parseInt(value.substr(4, 2), 10),
  3213. century = parseInt(value.charAt(9), 10);
  3214. year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
  3215. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  3216. return false;
  3217. }
  3218. // Validate the check digit
  3219. var sum = 0,
  3220. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  3221. for (var i = 0; i < 8; i++) {
  3222. sum += parseInt(value.charAt(i), 10) * weight[i];
  3223. }
  3224. sum = 11 - sum % 11;
  3225. return (sum + '' === value.charAt(8));
  3226. },
  3227. /**
  3228. * Validate Lithuanian Personal Code (Asmens kodas)
  3229. * Examples:
  3230. * - Valid: 38703181745
  3231. * - Invalid: 38703181746, 78703181745, 38703421745
  3232. *
  3233. * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  3234. * @see http://www.adomas.org/midi2007/pcode.html
  3235. * @param {String} value The ID
  3236. * @returns {Boolean}
  3237. */
  3238. _lt: function(value) {
  3239. if (!/^[0-9]{11}$/.test(value)) {
  3240. return false;
  3241. }
  3242. var gender = parseInt(value.charAt(0), 10),
  3243. year = parseInt(value.substr(1, 2), 10),
  3244. month = parseInt(value.substr(3, 2), 10),
  3245. day = parseInt(value.substr(5, 2), 10),
  3246. century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  3247. year = century * 100 + year;
  3248. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  3249. return false;
  3250. }
  3251. // Validate the check digit
  3252. var sum = 0,
  3253. weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  3254. for (var i = 0; i < 10; i++) {
  3255. sum += parseInt(value.charAt(i), 10) * weight[i];
  3256. }
  3257. sum = sum % 11;
  3258. if (sum !== 10) {
  3259. return sum + '' === value.charAt(10);
  3260. }
  3261. // Re-calculate the check digit
  3262. sum = 0;
  3263. weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  3264. for (i = 0; i < 10; i++) {
  3265. sum += parseInt(value.charAt(i), 10) * weight[i];
  3266. }
  3267. sum = sum % 11;
  3268. if (sum === 10) {
  3269. sum = 0;
  3270. }
  3271. return (sum + '' === value.charAt(10));
  3272. },
  3273. /**
  3274. * Validate Latvian Personal Code (Personas kods)
  3275. * Examples:
  3276. * - Valid: 161175-19997, 16117519997
  3277. * - Invalid: 161375-19997
  3278. *
  3279. * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  3280. * @param {String} value The ID
  3281. * @returns {Boolean}
  3282. */
  3283. _lv: function(value) {
  3284. if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  3285. return false;
  3286. }
  3287. value = value.replace(/\D/g, '');
  3288. // Check birth date
  3289. var day = parseInt(value.substr(0, 2), 10),
  3290. month = parseInt(value.substr(2, 2), 10),
  3291. year = parseInt(value.substr(4, 2), 10);
  3292. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  3293. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  3294. return false;
  3295. }
  3296. // Check personal code
  3297. var sum = 0,
  3298. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  3299. for (var i = 0; i < 10; i++) {
  3300. sum += parseInt(value.charAt(i), 10) * weight[i];
  3301. }
  3302. sum = (sum + 1) % 11 % 10;
  3303. return (sum + '' === value.charAt(10));
  3304. },
  3305. /**
  3306. * Validate Dutch national identification number (BSN)
  3307. * Examples:
  3308. * - Valid: 111222333, 941331490, 9413.31.490
  3309. * - Invalid: 111252333
  3310. *
  3311. * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  3312. * @param {String} value The ID
  3313. * @returns {Boolean}
  3314. */
  3315. _nl: function(value) {
  3316. while (value.length < 9) {
  3317. value = '0' + value;
  3318. }
  3319. if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  3320. return false;
  3321. }
  3322. value = value.replace(/\./g, '');
  3323. if (parseInt(value, 10) === 0) {
  3324. return false;
  3325. }
  3326. var sum = 0,
  3327. length = value.length;
  3328. for (var i = 0; i < length - 1; i++) {
  3329. sum += (9 - i) * parseInt(value.charAt(i), 10);
  3330. }
  3331. sum = sum % 11;
  3332. if (sum === 10) {
  3333. sum = 0;
  3334. }
  3335. return (sum + '' === value.charAt(length - 1));
  3336. },
  3337. /**
  3338. * Validate Romanian numerical personal code (CNP)
  3339. * Examples:
  3340. * - Valid: 1630615123457, 1800101221144
  3341. * - Invalid: 8800101221144, 1632215123457, 1630615123458
  3342. *
  3343. * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  3344. * @param {String} value The ID
  3345. * @returns {Boolean}
  3346. */
  3347. _ro: function(value) {
  3348. if (!/^[0-9]{13}$/.test(value)) {
  3349. return false;
  3350. }
  3351. var gender = parseInt(value.charAt(0), 10);
  3352. if (gender === 0 || gender === 7 || gender === 8) {
  3353. return false;
  3354. }
  3355. // Determine the date of birth
  3356. var year = parseInt(value.substr(1, 2), 10),
  3357. month = parseInt(value.substr(3, 2), 10),
  3358. day = parseInt(value.substr(5, 2), 10),
  3359. // The year of date is determined base on the gender
  3360. centuries = {
  3361. '1': 1900, // Male born between 1900 and 1999
  3362. '2': 1900, // Female born between 1900 and 1999
  3363. '3': 1800, // Male born between 1800 and 1899
  3364. '4': 1800, // Female born between 1800 and 1899
  3365. '5': 2000, // Male born after 2000
  3366. '6': 2000 // Female born after 2000
  3367. };
  3368. if (day > 31 && month > 12) {
  3369. return false;
  3370. }
  3371. if (gender !== 9) {
  3372. year = centuries[gender + ''] + year;
  3373. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3374. return false;
  3375. }
  3376. }
  3377. // Validate the check digit
  3378. var sum = 0,
  3379. weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  3380. length = value.length;
  3381. for (var i = 0; i < length - 1; i++) {
  3382. sum += parseInt(value.charAt(i), 10) * weight[i];
  3383. }
  3384. sum = sum % 11;
  3385. if (sum === 10) {
  3386. sum = 1;
  3387. }
  3388. return (sum + '' === value.charAt(length - 1));
  3389. },
  3390. /**
  3391. * Validate Swedish personal identity number (personnummer)
  3392. * Examples:
  3393. * - Valid: 8112289874, 811228-9874, 811228+9874
  3394. * - Invalid: 811228-9873
  3395. *
  3396. * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  3397. * @param {String} value The ID
  3398. * @returns {Boolean}
  3399. */
  3400. _se: function(value) {
  3401. if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  3402. return false;
  3403. }
  3404. value = value.replace(/[^0-9]/g, '');
  3405. var year = parseInt(value.substr(0, 2), 10) + 1900,
  3406. month = parseInt(value.substr(2, 2), 10),
  3407. day = parseInt(value.substr(4, 2), 10);
  3408. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3409. return false;
  3410. }
  3411. // Validate the last check digit
  3412. return $.fn.bootstrapValidator.helpers.luhn(value);
  3413. },
  3414. /**
  3415. * Validate Slovak national identifier number (RC)
  3416. * Examples:
  3417. * - Valid: 7103192745, 991231123
  3418. * - Invalid: 7103192746, 1103492745
  3419. *
  3420. * @param {String} value The ID
  3421. * @returns {Boolean}
  3422. */
  3423. _sk: function(value) {
  3424. // Slovakia uses the same format as Czech Republic
  3425. return this._cz(value);
  3426. },
  3427. /**
  3428. * Validate San Marino citizen number
  3429. *
  3430. * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  3431. * @param {String} value The ID
  3432. * @returns {Boolean}
  3433. */
  3434. _sm: function(value) {
  3435. return /^\d{5}$/.test(value);
  3436. },
  3437. /**
  3438. * Validate South African ID
  3439. * Example:
  3440. * - Valid: 8001015009087
  3441. * - Invalid: 8001015009287, 8001015009086
  3442. *
  3443. * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  3444. * @param {String} value The ID
  3445. * @returns {Boolean}
  3446. */
  3447. _za: function(value) {
  3448. if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  3449. return false;
  3450. }
  3451. var year = parseInt(value.substr(0, 2), 10),
  3452. currentYear = new Date().getFullYear() % 100,
  3453. month = parseInt(value.substr(2, 2), 10),
  3454. day = parseInt(value.substr(4, 2), 10);
  3455. year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  3456. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3457. return false;
  3458. }
  3459. // Validate the last check digit
  3460. return $.fn.bootstrapValidator.helpers.luhn(value);
  3461. }
  3462. };
  3463. }(window.jQuery));
  3464. ;(function($) {
  3465. $.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
  3466. 'default': 'Please enter the same value'
  3467. });
  3468. $.fn.bootstrapValidator.validators.identical = {
  3469. html5Attributes: {
  3470. message: 'message',
  3471. field: 'field'
  3472. },
  3473. /**
  3474. * Check if input value equals to value of particular one
  3475. *
  3476. * @param {BootstrapValidator} validator The validator plugin instance
  3477. * @param {jQuery} $field Field element
  3478. * @param {Object} options Consists of the following key:
  3479. * - field: The name of field that will be used to compare with current one
  3480. * @returns {Boolean}
  3481. */
  3482. validate: function(validator, $field, options) {
  3483. var value = $field.val();
  3484. if (value === '') {
  3485. return true;
  3486. }
  3487. var compareWith = validator.getFieldElements(options.field);
  3488. if (compareWith === null) {
  3489. return true;
  3490. }
  3491. if (value === compareWith.val()) {
  3492. validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
  3493. return true;
  3494. } else {
  3495. return false;
  3496. }
  3497. }
  3498. };
  3499. }(window.jQuery));
  3500. ;(function($) {
  3501. $.fn.bootstrapValidator.i18n.imei = $.extend($.fn.bootstrapValidator.i18n.imei || {}, {
  3502. 'default': 'Please enter a valid IMEI number'
  3503. });
  3504. $.fn.bootstrapValidator.validators.imei = {
  3505. /**
  3506. * Validate IMEI (International Mobile Station Equipment Identity)
  3507. * Examples:
  3508. * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  3509. * - Invalid: 490154203237517
  3510. *
  3511. * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  3512. * @param {BootstrapValidator} validator The validator plugin instance
  3513. * @param {jQuery} $field Field element
  3514. * @param {Object} options Can consist of the following keys:
  3515. * - message: The invalid message
  3516. * @returns {Boolean}
  3517. */
  3518. validate: function(validator, $field, options) {
  3519. var value = $field.val();
  3520. if (value === '') {
  3521. return true;
  3522. }
  3523. switch (true) {
  3524. case /^\d{15}$/.test(value):
  3525. case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  3526. case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  3527. value = value.replace(/[^0-9]/g, '');
  3528. return $.fn.bootstrapValidator.helpers.luhn(value);
  3529. case /^\d{14}$/.test(value):
  3530. case /^\d{16}$/.test(value):
  3531. case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  3532. case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  3533. return true;
  3534. default:
  3535. return false;
  3536. }
  3537. }
  3538. };
  3539. }(window.jQuery));
  3540. ;(function($) {
  3541. $.fn.bootstrapValidator.i18n.integer = $.extend($.fn.bootstrapValidator.i18n.integer || {}, {
  3542. 'default': 'Please enter a valid number'
  3543. });
  3544. $.fn.bootstrapValidator.validators.integer = {
  3545. enableByHtml5: function($field) {
  3546. return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
  3547. },
  3548. /**
  3549. * Return true if the input value is an integer
  3550. *
  3551. * @param {BootstrapValidator} validator The validator plugin instance
  3552. * @param {jQuery} $field Field element
  3553. * @param {Object} options Can consist of the following key:
  3554. * - message: The invalid message
  3555. * @returns {Boolean}
  3556. */
  3557. validate: function(validator, $field, options) {
  3558. var value = $field.val();
  3559. if (value === '') {
  3560. return true;
  3561. }
  3562. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  3563. }
  3564. };
  3565. }(window.jQuery));
  3566. ;(function($) {
  3567. $.fn.bootstrapValidator.i18n.ip = $.extend($.fn.bootstrapValidator.i18n.ip || {}, {
  3568. 'default': 'Please enter a valid IP address',
  3569. ipv4: 'Please enter a valid IPv4 address',
  3570. ipv6: 'Please enter a valid IPv6 address'
  3571. });
  3572. $.fn.bootstrapValidator.validators.ip = {
  3573. html5Attributes: {
  3574. message: 'message',
  3575. ipv4: 'ipv4',
  3576. ipv6: 'ipv6'
  3577. },
  3578. /**
  3579. * Return true if the input value is a IP address.
  3580. *
  3581. * @param {BootstrapValidator} validator The validator plugin instance
  3582. * @param {jQuery} $field Field element
  3583. * @param {Object} options Can consist of the following keys:
  3584. * - ipv4: Enable IPv4 validator, default to true
  3585. * - ipv6: Enable IPv6 validator, default to true
  3586. * - message: The invalid message
  3587. * @returns {Boolean|Object}
  3588. */
  3589. validate: function(validator, $field, options) {
  3590. var value = $field.val();
  3591. if (value === '') {
  3592. return true;
  3593. }
  3594. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  3595. if (options.ipv4) {
  3596. return {
  3597. valid: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(value),
  3598. message: options.message || $.fn.bootstrapValidator.i18n.ip.ipv4
  3599. };
  3600. } else if (options.ipv6) {
  3601. return {
  3602. valid: /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/.test(value),
  3603. message: options.message || $.fn.bootstrapValidator.i18n.ip.ipv6
  3604. };
  3605. }
  3606. return false;
  3607. }
  3608. };
  3609. }(window.jQuery));
  3610. ;(function($) {
  3611. $.fn.bootstrapValidator.i18n.isbn = $.extend($.fn.bootstrapValidator.i18n.isbn || {}, {
  3612. 'default': 'Please enter a valid ISBN number'
  3613. });
  3614. $.fn.bootstrapValidator.validators.isbn = {
  3615. /**
  3616. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  3617. * Examples:
  3618. * - Valid:
  3619. * ISBN 10: 99921-58-10-7, 9971-5-0210-0, 960-425-059-0, 80-902734-1-6, 85-359-0277-5, 1-84356-028-3, 0-684-84328-5, 0-8044-2957-X, 0-85131-041-9, 0-943396-04-2, 0-9752298-0-X
  3620. * ISBN 13: 978-0-306-40615-7
  3621. * - Invalid:
  3622. * ISBN 10: 99921-58-10-6
  3623. * ISBN 13: 978-0-306-40615-6
  3624. *
  3625. * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  3626. * @param {BootstrapValidator} validator The validator plugin instance
  3627. * @param {jQuery} $field Field element
  3628. * @param {Object} [options] Can consist of the following keys:
  3629. * - message: The invalid message
  3630. * @returns {Boolean}
  3631. */
  3632. validate: function(validator, $field, options) {
  3633. var value = $field.val();
  3634. if (value === '') {
  3635. return true;
  3636. }
  3637. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  3638. // Groups are separated by a hyphen or a space
  3639. var type;
  3640. switch (true) {
  3641. case /^\d{9}[\dX]$/.test(value):
  3642. case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  3643. case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  3644. type = 'ISBN10';
  3645. break;
  3646. case /^(978|979)\d{9}[\dX]$/.test(value):
  3647. case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  3648. case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  3649. type = 'ISBN13';
  3650. break;
  3651. default:
  3652. return false;
  3653. }
  3654. // Replace all special characters except digits and X
  3655. value = value.replace(/[^0-9X]/gi, '');
  3656. var chars = value.split(''),
  3657. length = chars.length,
  3658. sum = 0,
  3659. i,
  3660. checksum;
  3661. switch (type) {
  3662. case 'ISBN10':
  3663. sum = 0;
  3664. for (i = 0; i < length - 1; i++) {
  3665. sum += parseInt(chars[i], 10) * (10 - i);
  3666. }
  3667. checksum = 11 - (sum % 11);
  3668. if (checksum === 11) {
  3669. checksum = 0;
  3670. } else if (checksum === 10) {
  3671. checksum = 'X';
  3672. }
  3673. return (checksum + '' === chars[length - 1]);
  3674. case 'ISBN13':
  3675. sum = 0;
  3676. for (i = 0; i < length - 1; i++) {
  3677. sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
  3678. }
  3679. checksum = 10 - (sum % 10);
  3680. if (checksum === 10) {
  3681. checksum = '0';
  3682. }
  3683. return (checksum + '' === chars[length - 1]);
  3684. default:
  3685. return false;
  3686. }
  3687. }
  3688. };
  3689. }(window.jQuery));
  3690. ;(function($) {
  3691. $.fn.bootstrapValidator.i18n.isin = $.extend($.fn.bootstrapValidator.i18n.isin || {}, {
  3692. 'default': 'Please enter a valid ISIN number'
  3693. });
  3694. $.fn.bootstrapValidator.validators.isin = {
  3695. // Available country codes
  3696. // See http://isin.net/country-codes/
  3697. COUNTRY_CODES: 'AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW',
  3698. /**
  3699. * Validate an ISIN (International Securities Identification Number)
  3700. * Examples:
  3701. * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  3702. * - Invalid: US0378331004, AA0000XVGZA3
  3703. *
  3704. * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  3705. * @param {BootstrapValidator} validator The validator plugin instance
  3706. * @param {jQuery} $field Field element
  3707. * @param {Object} options Can consist of the following keys:
  3708. * - message: The invalid message
  3709. * @returns {Boolean}
  3710. */
  3711. validate: function(validator, $field, options) {
  3712. var value = $field.val();
  3713. if (value === '') {
  3714. return true;
  3715. }
  3716. value = value.toUpperCase();
  3717. var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  3718. if (!regex.test(value)) {
  3719. return false;
  3720. }
  3721. var converted = '',
  3722. length = value.length;
  3723. // Convert letters to number
  3724. for (var i = 0; i < length - 1; i++) {
  3725. var c = value.charCodeAt(i);
  3726. converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  3727. }
  3728. var digits = '',
  3729. n = converted.length,
  3730. group = (n % 2 !== 0) ? 0 : 1;
  3731. for (i = 0; i < n; i++) {
  3732. digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
  3733. }
  3734. var sum = 0;
  3735. for (i = 0; i < digits.length; i++) {
  3736. sum += parseInt(digits.charAt(i), 10);
  3737. }
  3738. sum = (10 - (sum % 10)) % 10;
  3739. return sum + '' === value.charAt(length - 1);
  3740. }
  3741. };
  3742. }(window.jQuery));
  3743. ;(function($) {
  3744. $.fn.bootstrapValidator.i18n.ismn = $.extend($.fn.bootstrapValidator.i18n.ismn || {}, {
  3745. 'default': 'Please enter a valid ISMN number'
  3746. });
  3747. $.fn.bootstrapValidator.validators.ismn = {
  3748. /**
  3749. * Validate ISMN (International Standard Music Number)
  3750. * Examples:
  3751. * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  3752. * - Invalid: 9790060115614
  3753. *
  3754. * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  3755. * @param {BootstrapValidator} validator The validator plugin instance
  3756. * @param {jQuery} $field Field element
  3757. * @param {Object} options Can consist of the following keys:
  3758. * - message: The invalid message
  3759. * @returns {Boolean}
  3760. */
  3761. validate: function(validator, $field, options) {
  3762. var value = $field.val();
  3763. if (value === '') {
  3764. return true;
  3765. }
  3766. // Groups are separated by a hyphen or a space
  3767. var type;
  3768. switch (true) {
  3769. case /^M\d{9}$/.test(value):
  3770. case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  3771. case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3772. type = 'ISMN10';
  3773. break;
  3774. case /^9790\d{9}$/.test(value):
  3775. case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  3776. case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3777. type = 'ISMN13';
  3778. break;
  3779. default:
  3780. return false;
  3781. }
  3782. if ('ISMN10' === type) {
  3783. value = '9790' + value.substr(1);
  3784. }
  3785. // Replace all special characters except digits
  3786. value = value.replace(/[^0-9]/gi, '');
  3787. var length = value.length,
  3788. sum = 0,
  3789. weight = [1, 3];
  3790. for (var i = 0; i < length - 1; i++) {
  3791. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3792. }
  3793. sum = 10 - sum % 10;
  3794. return (sum + '' === value.charAt(length - 1));
  3795. }
  3796. };
  3797. }(window.jQuery));
  3798. ;(function($) {
  3799. $.fn.bootstrapValidator.i18n.issn = $.extend($.fn.bootstrapValidator.i18n.issn || {}, {
  3800. 'default': 'Please enter a valid ISSN number'
  3801. });
  3802. $.fn.bootstrapValidator.validators.issn = {
  3803. /**
  3804. * Validate ISSN (International Standard Serial Number)
  3805. * Examples:
  3806. * - Valid: 0378-5955, 0024-9319, 0032-1478
  3807. * - Invalid: 0032-147X
  3808. *
  3809. * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  3810. * @param {BootstrapValidator} validator The validator plugin instance
  3811. * @param {jQuery} $field Field element
  3812. * @param {Object} options Can consist of the following keys:
  3813. * - message: The invalid message
  3814. * @returns {Boolean}
  3815. */
  3816. validate: function(validator, $field, options) {
  3817. var value = $field.val();
  3818. if (value === '') {
  3819. return true;
  3820. }
  3821. // Groups are separated by a hyphen or a space
  3822. if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  3823. return false;
  3824. }
  3825. // Replace all special characters except digits and X
  3826. value = value.replace(/[^0-9X]/gi, '');
  3827. var chars = value.split(''),
  3828. length = chars.length,
  3829. sum = 0;
  3830. if (chars[7] === 'X') {
  3831. chars[7] = 10;
  3832. }
  3833. for (var i = 0; i < length; i++) {
  3834. sum += parseInt(chars[i], 10) * (8 - i);
  3835. }
  3836. return (sum % 11 === 0);
  3837. }
  3838. };
  3839. }(window.jQuery));
  3840. ;(function($) {
  3841. $.fn.bootstrapValidator.i18n.lessThan = $.extend($.fn.bootstrapValidator.i18n.lessThan || {}, {
  3842. 'default': 'Please enter a value less than or equal to %s',
  3843. notInclusive: 'Please enter a value less than %s'
  3844. });
  3845. $.fn.bootstrapValidator.validators.lessThan = {
  3846. html5Attributes: {
  3847. message: 'message',
  3848. value: 'value',
  3849. inclusive: 'inclusive'
  3850. },
  3851. enableByHtml5: function($field) {
  3852. var max = $field.attr('max');
  3853. if (max) {
  3854. return {
  3855. value: max
  3856. };
  3857. }
  3858. return false;
  3859. },
  3860. /**
  3861. * Return true if the input value is less than or equal to given number
  3862. *
  3863. * @param {BootstrapValidator} validator The validator plugin instance
  3864. * @param {jQuery} $field Field element
  3865. * @param {Object} options Can consist of the following keys:
  3866. * - value: The number used to compare to. It can be
  3867. * - A number
  3868. * - Name of field which its value defines the number
  3869. * - Name of callback function that returns the number
  3870. * - A callback function that returns the number
  3871. *
  3872. * - inclusive [optional]: Can be true or false. Default is true
  3873. * - message: The invalid message
  3874. * @returns {Boolean|Object}
  3875. */
  3876. validate: function(validator, $field, options) {
  3877. var value = $field.val();
  3878. if (value === '') {
  3879. return true;
  3880. }
  3881. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption(options.value, $field);
  3882. value = parseFloat(value);
  3883. return (options.inclusive === true || options.inclusive === undefined)
  3884. ? {
  3885. valid: value <= compareTo,
  3886. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan['default'], compareTo)
  3887. }
  3888. : {
  3889. valid: value < compareTo,
  3890. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan.notInclusive, compareTo)
  3891. };
  3892. }
  3893. };
  3894. }(window.jQuery));
  3895. ;(function($) {
  3896. $.fn.bootstrapValidator.i18n.mac = $.extend($.fn.bootstrapValidator.i18n.mac || {}, {
  3897. 'default': 'Please enter a valid MAC address'
  3898. });
  3899. $.fn.bootstrapValidator.validators.mac = {
  3900. /**
  3901. * Return true if the input value is a MAC address.
  3902. *
  3903. * @param {BootstrapValidator} validator The validator plugin instance
  3904. * @param {jQuery} $field Field element
  3905. * @param {Object} options Can consist of the following keys:
  3906. * - message: The invalid message
  3907. * @returns {Boolean}
  3908. */
  3909. validate: function(validator, $field, options) {
  3910. var value = $field.val();
  3911. if (value === '') {
  3912. return true;
  3913. }
  3914. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  3915. }
  3916. };
  3917. }(window.jQuery));
  3918. ;(function($) {
  3919. $.fn.bootstrapValidator.i18n.notEmpty = $.extend($.fn.bootstrapValidator.i18n.notEmpty || {}, {
  3920. 'default': 'Please enter a value'
  3921. });
  3922. $.fn.bootstrapValidator.validators.notEmpty = {
  3923. enableByHtml5: function($field) {
  3924. var required = $field.attr('required') + '';
  3925. return ('required' === required || 'true' === required);
  3926. },
  3927. /**
  3928. * Check if input value is empty or not
  3929. *
  3930. * @param {BootstrapValidator} validator The validator plugin instance
  3931. * @param {jQuery} $field Field element
  3932. * @param {Object} options
  3933. * @returns {Boolean}
  3934. */
  3935. validate: function(validator, $field, options) {
  3936. var type = $field.attr('type');
  3937. if ('radio' === type || 'checkbox' === type) {
  3938. return validator
  3939. .getFieldElements($field.attr('data-bv-field'))
  3940. .filter(':checked')
  3941. .length > 0;
  3942. }
  3943. return $.trim($field.val()) !== '';
  3944. }
  3945. };
  3946. }(window.jQuery));
  3947. ;(function($) {
  3948. $.fn.bootstrapValidator.i18n.numeric = $.extend($.fn.bootstrapValidator.i18n.numeric || {}, {
  3949. 'default': 'Please enter a valid float number'
  3950. });
  3951. $.fn.bootstrapValidator.validators.numeric = {
  3952. html5Attributes: {
  3953. message: 'message',
  3954. separator: 'separator'
  3955. },
  3956. enableByHtml5: function($field) {
  3957. return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
  3958. },
  3959. /**
  3960. * Validate decimal number
  3961. *
  3962. * @param {BootstrapValidator} validator The validator plugin instance
  3963. * @param {jQuery} $field Field element
  3964. * @param {Object} options Consist of key:
  3965. * - message: The invalid message
  3966. * - separator: The decimal separator. Can be "." (default), ","
  3967. * @returns {Boolean}
  3968. */
  3969. validate: function(validator, $field, options) {
  3970. var value = $field.val();
  3971. if (value === '') {
  3972. return true;
  3973. }
  3974. var separator = options.separator || '.';
  3975. if (separator !== '.') {
  3976. value = value.replace(separator, '.');
  3977. }
  3978. return !isNaN(parseFloat(value)) && isFinite(value);
  3979. }
  3980. };
  3981. }(window.jQuery));
  3982. ;(function($) {
  3983. $.fn.bootstrapValidator.i18n.phone = $.extend($.fn.bootstrapValidator.i18n.phone || {}, {
  3984. 'default': 'Please enter a valid phone number',
  3985. countryNotSupported: 'The country code %s is not supported',
  3986. country: 'Please enter a valid phone number in %s',
  3987. countries: {
  3988. GB: 'United Kingdom',
  3989. US: 'USA'
  3990. }
  3991. });
  3992. $.fn.bootstrapValidator.validators.phone = {
  3993. html5Attributes: {
  3994. message: 'message',
  3995. country: 'country'
  3996. },
  3997. // The supported countries
  3998. COUNTRY_CODES: ['GB', 'US'],
  3999. /**
  4000. * Return true if the input value contains a valid phone number for the country
  4001. * selected in the options
  4002. *
  4003. * @param {BootstrapValidator} validator Validate plugin instance
  4004. * @param {jQuery} $field Field element
  4005. * @param {Object} options Consist of key:
  4006. * - message: The invalid message
  4007. * - country: The ISO-3166 country code. It can be
  4008. * - A country code
  4009. * - Name of field which its value defines the country code
  4010. * - Name of callback function that returns the country code
  4011. * - A callback function that returns the country code
  4012. *
  4013. * Currently it only supports United State (US) or United Kingdom (GB) countries
  4014. * @returns {Boolean|Object}
  4015. */
  4016. validate: function(validator, $field, options) {
  4017. var value = $field.val();
  4018. if (value === '') {
  4019. return true;
  4020. }
  4021. var country = options.country;
  4022. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  4023. // Try to determine the country
  4024. country = validator.getDynamicOption(country, $field);
  4025. }
  4026. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  4027. return {
  4028. valid: false,
  4029. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.phone.countryNotSupported, country)
  4030. };
  4031. }
  4032. var isValid = true;
  4033. switch (country.toUpperCase()) {
  4034. case 'GB':
  4035. // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
  4036. // Test: http://regexr.com/38uhv
  4037. value = $.trim(value);
  4038. isValid = (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
  4039. break;
  4040. case 'US':
  4041. /* falls through */
  4042. default:
  4043. // Make sure US phone numbers have 10 digits
  4044. // May start with 1, +1, or 1-; should discard
  4045. // Area code may be delimited with (), & sections may be delimited with . or -
  4046. // Test: http://regexr.com/38mqi
  4047. value = value.replace(/\D/g, '');
  4048. isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length === 10);
  4049. break;
  4050. }
  4051. return {
  4052. valid: isValid,
  4053. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.phone.country, $.fn.bootstrapValidator.i18n.phone.countries[country])
  4054. };
  4055. }
  4056. };
  4057. }(window.jQuery));
  4058. ;(function($) {
  4059. $.fn.bootstrapValidator.i18n.regexp = $.extend($.fn.bootstrapValidator.i18n.regexp || {}, {
  4060. 'default': 'Please enter a value matching the pattern'
  4061. });
  4062. $.fn.bootstrapValidator.validators.regexp = {
  4063. html5Attributes: {
  4064. message: 'message',
  4065. regexp: 'regexp'
  4066. },
  4067. enableByHtml5: function($field) {
  4068. var pattern = $field.attr('pattern');
  4069. if (pattern) {
  4070. return {
  4071. regexp: pattern
  4072. };
  4073. }
  4074. return false;
  4075. },
  4076. /**
  4077. * Check if the element value matches given regular expression
  4078. *
  4079. * @param {BootstrapValidator} validator The validator plugin instance
  4080. * @param {jQuery} $field Field element
  4081. * @param {Object} options Consists of the following key:
  4082. * - regexp: The regular expression you need to check
  4083. * @returns {Boolean}
  4084. */
  4085. validate: function(validator, $field, options) {
  4086. var value = $field.val();
  4087. if (value === '') {
  4088. return true;
  4089. }
  4090. var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  4091. return regexp.test(value);
  4092. }
  4093. };
  4094. }(window.jQuery));
  4095. ;(function($) {
  4096. $.fn.bootstrapValidator.i18n.remote = $.extend($.fn.bootstrapValidator.i18n.remote || {}, {
  4097. 'default': 'Please enter a valid value'
  4098. });
  4099. $.fn.bootstrapValidator.validators.remote = {
  4100. html5Attributes: {
  4101. message: 'message',
  4102. url: 'url',
  4103. name: 'name'
  4104. },
  4105. /**
  4106. * Request a remote server to check the input value
  4107. *
  4108. * @param {BootstrapValidator} validator Plugin instance
  4109. * @param {jQuery} $field Field element
  4110. * @param {Object} options Can consist of the following keys:
  4111. * - url {String|Function}
  4112. * - type {String} [optional] Can be GET or POST (default)
  4113. * - data {Object|Function} [optional]: By default, it will take the value
  4114. * {
  4115. * <fieldName>: <fieldValue>
  4116. * }
  4117. * - name {String} [optional]: Override the field name for the request.
  4118. * - message: The invalid message
  4119. * @returns {Boolean|Deferred}
  4120. */
  4121. validate: function(validator, $field, options) {
  4122. var value = $field.val();
  4123. if (value === '') {
  4124. return true;
  4125. }
  4126. var name = $field.attr('data-bv-field'),
  4127. data = options.data || {},
  4128. url = options.url,
  4129. type = options.type || 'POST';
  4130. // Support dynamic data
  4131. if ('function' === typeof data) {
  4132. data = data.call(this, validator);
  4133. }
  4134. // Support dynamic url
  4135. if ('function' === typeof url) {
  4136. url = url.call(this, validator);
  4137. }
  4138. data[options.name || name] = value;
  4139. var dfd = new $.Deferred();
  4140. var xhr = $.ajax({
  4141. type: type,
  4142. url: url,
  4143. dataType: 'json',
  4144. data: data
  4145. });
  4146. xhr.then(function(response) {
  4147. dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true', response.message ? response.message : null);
  4148. });
  4149. dfd.fail(function() {
  4150. xhr.abort();
  4151. });
  4152. return dfd;
  4153. }
  4154. };
  4155. }(window.jQuery));
  4156. ;(function($) {
  4157. $.fn.bootstrapValidator.i18n.rtn = $.extend($.fn.bootstrapValidator.i18n.rtn || {}, {
  4158. 'default': 'Please enter a valid RTN number'
  4159. });
  4160. $.fn.bootstrapValidator.validators.rtn = {
  4161. /**
  4162. * Validate a RTN (Routing transit number)
  4163. * Examples:
  4164. * - Valid: 021200025, 789456124
  4165. *
  4166. * @see http://en.wikipedia.org/wiki/Routing_transit_number
  4167. * @param {BootstrapValidator} validator The validator plugin instance
  4168. * @param {jQuery} $field Field element
  4169. * @param {Object} options Can consist of the following keys:
  4170. * - message: The invalid message
  4171. * @returns {Boolean}
  4172. */
  4173. validate: function(validator, $field, options) {
  4174. var value = $field.val();
  4175. if (value === '') {
  4176. return true;
  4177. }
  4178. if (!/^\d{9}$/.test(value)) {
  4179. return false;
  4180. }
  4181. var sum = 0;
  4182. for (var i = 0; i < value.length; i += 3) {
  4183. sum += parseInt(value.charAt(i), 10) * 3
  4184. + parseInt(value.charAt(i + 1), 10) * 7
  4185. + parseInt(value.charAt(i + 2), 10);
  4186. }
  4187. return (sum !== 0 && sum % 10 === 0);
  4188. }
  4189. };
  4190. }(window.jQuery));
  4191. ;(function($) {
  4192. $.fn.bootstrapValidator.i18n.sedol = $.extend($.fn.bootstrapValidator.i18n.sedol || {}, {
  4193. 'default': 'Please enter a valid SEDOL number'
  4194. });
  4195. $.fn.bootstrapValidator.validators.sedol = {
  4196. /**
  4197. * Validate a SEDOL (Stock Exchange Daily Official List)
  4198. * Examples:
  4199. * - Valid: 0263494, B0WNLY7
  4200. *
  4201. * @see http://en.wikipedia.org/wiki/SEDOL
  4202. * @param {BootstrapValidator} validator The validator plugin instance
  4203. * @param {jQuery} $field Field element
  4204. * @param {Object} options Can consist of the following keys:
  4205. * - message: The invalid message
  4206. * @returns {Boolean}
  4207. */
  4208. validate: function(validator, $field, options) {
  4209. var value = $field.val();
  4210. if (value === '') {
  4211. return true;
  4212. }
  4213. value = value.toUpperCase();
  4214. if (!/^[0-9A-Z]{7}$/.test(value)) {
  4215. return false;
  4216. }
  4217. var sum = 0,
  4218. weight = [1, 3, 1, 7, 3, 9, 1],
  4219. length = value.length;
  4220. for (var i = 0; i < length - 1; i++) {
  4221. sum += weight[i] * parseInt(value.charAt(i), 36);
  4222. }
  4223. sum = (10 - sum % 10) % 10;
  4224. return sum + '' === value.charAt(length - 1);
  4225. }
  4226. };
  4227. }(window.jQuery));
  4228. ;(function($) {
  4229. $.fn.bootstrapValidator.i18n.siren = $.extend($.fn.bootstrapValidator.i18n.siren || {}, {
  4230. 'default': 'Please enter a valid SIREN number'
  4231. });
  4232. $.fn.bootstrapValidator.validators.siren = {
  4233. /**
  4234. * Check if a string is a siren number
  4235. *
  4236. * @param {BootstrapValidator} validator The validator plugin instance
  4237. * @param {jQuery} $field Field element
  4238. * @param {Object} options Consist of key:
  4239. * - message: The invalid message
  4240. * @returns {Boolean}
  4241. */
  4242. validate: function(validator, $field, options) {
  4243. var value = $field.val();
  4244. if (value === '') {
  4245. return true;
  4246. }
  4247. if (!/^\d{9}$/.test(value)) {
  4248. return false;
  4249. }
  4250. return $.fn.bootstrapValidator.helpers.luhn(value);
  4251. }
  4252. };
  4253. }(window.jQuery));
  4254. ;(function($) {
  4255. $.fn.bootstrapValidator.i18n.siret = $.extend($.fn.bootstrapValidator.i18n.siret || {}, {
  4256. 'default': 'Please enter a valid SIRET number'
  4257. });
  4258. $.fn.bootstrapValidator.validators.siret = {
  4259. /**
  4260. * Check if a string is a siret number
  4261. *
  4262. * @param {BootstrapValidator} validator The validator plugin instance
  4263. * @param {jQuery} $field Field element
  4264. * @param {Object} options Consist of key:
  4265. * - message: The invalid message
  4266. * @returns {Boolean}
  4267. */
  4268. validate: function(validator, $field, options) {
  4269. var value = $field.val();
  4270. if (value === '') {
  4271. return true;
  4272. }
  4273. var sum = 0,
  4274. length = value.length,
  4275. tmp;
  4276. for (var i = 0; i < length; i++) {
  4277. tmp = parseInt(value.charAt(i), 10);
  4278. if ((i % 2) === 0) {
  4279. tmp = tmp * 2;
  4280. if (tmp > 9) {
  4281. tmp -= 9;
  4282. }
  4283. }
  4284. sum += tmp;
  4285. }
  4286. return (sum % 10 === 0);
  4287. }
  4288. };
  4289. }(window.jQuery));
  4290. ;(function($) {
  4291. $.fn.bootstrapValidator.i18n.step = $.extend($.fn.bootstrapValidator.i18n.step || {}, {
  4292. 'default': 'Please enter a valid step of %s'
  4293. });
  4294. $.fn.bootstrapValidator.validators.step = {
  4295. html5Attributes: {
  4296. message: 'message',
  4297. base: 'baseValue',
  4298. step: 'step'
  4299. },
  4300. /**
  4301. * Return true if the input value is valid step one
  4302. *
  4303. * @param {BootstrapValidator} validator The validator plugin instance
  4304. * @param {jQuery} $field Field element
  4305. * @param {Object} options Can consist of the following keys:
  4306. * - baseValue: The base value
  4307. * - step: The step
  4308. * - message: The invalid message
  4309. * @returns {Boolean|Object}
  4310. */
  4311. validate: function(validator, $field, options) {
  4312. var value = $field.val();
  4313. if (value === '') {
  4314. return true;
  4315. }
  4316. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  4317. value = parseFloat(value);
  4318. if (!$.isNumeric(value)) {
  4319. return false;
  4320. }
  4321. var round = function(x, precision) {
  4322. var m = Math.pow(10, precision);
  4323. x = x * m;
  4324. var sign = (x > 0) | -(x < 0),
  4325. isHalf = (x % 1 === 0.5 * sign);
  4326. if (isHalf) {
  4327. return (Math.floor(x) + (sign > 0)) / m;
  4328. } else {
  4329. return Math.round(x) / m;
  4330. }
  4331. },
  4332. floatMod = function(x, y) {
  4333. if (y === 0.0) {
  4334. return 1.0;
  4335. }
  4336. var dotX = (x + '').split('.'),
  4337. dotY = (y + '').split('.'),
  4338. precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
  4339. return round(x - y * Math.floor(x / y), precision);
  4340. };
  4341. var mod = floatMod(value - options.baseValue, options.step);
  4342. return {
  4343. valid: mod === 0.0 || mod === options.step,
  4344. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.step['default'], [options.step])
  4345. };
  4346. }
  4347. };
  4348. }(window.jQuery));
  4349. ;(function($) {
  4350. $.fn.bootstrapValidator.i18n.stringCase = $.extend($.fn.bootstrapValidator.i18n.stringCase || {}, {
  4351. 'default': 'Please enter only lowercase characters',
  4352. upper: 'Please enter only uppercase characters'
  4353. });
  4354. $.fn.bootstrapValidator.validators.stringCase = {
  4355. html5Attributes: {
  4356. message: 'message',
  4357. 'case': 'case'
  4358. },
  4359. /**
  4360. * Check if a string is a lower or upper case one
  4361. *
  4362. * @param {BootstrapValidator} validator The validator plugin instance
  4363. * @param {jQuery} $field Field element
  4364. * @param {Object} options Consist of key:
  4365. * - message: The invalid message
  4366. * - case: Can be 'lower' (default) or 'upper'
  4367. * @returns {Object}
  4368. */
  4369. validate: function(validator, $field, options) {
  4370. var value = $field.val();
  4371. if (value === '') {
  4372. return true;
  4373. }
  4374. var stringCase = (options['case'] || 'lower').toLowerCase();
  4375. return {
  4376. valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
  4377. message: options.message || (('upper' === stringCase) ? $.fn.bootstrapValidator.i18n.stringCase.upper : $.fn.bootstrapValidator.i18n.stringCase['default'])
  4378. };
  4379. }
  4380. };
  4381. }(window.jQuery));
  4382. ;(function($) {
  4383. $.fn.bootstrapValidator.i18n.stringLength = $.extend($.fn.bootstrapValidator.i18n.stringLength || {}, {
  4384. 'default': 'Please enter a value with valid length',
  4385. less: 'Please enter less than %s characters',
  4386. more: 'Please enter more than %s characters',
  4387. between: 'Please enter value between %s and %s characters long'
  4388. });
  4389. $.fn.bootstrapValidator.validators.stringLength = {
  4390. html5Attributes: {
  4391. message: 'message',
  4392. min: 'min',
  4393. max: 'max'
  4394. },
  4395. enableByHtml5: function($field) {
  4396. var maxLength = $field.attr('maxlength');
  4397. if (maxLength) {
  4398. return {
  4399. max: parseInt(maxLength, 10)
  4400. };
  4401. }
  4402. return false;
  4403. },
  4404. /**
  4405. * Check if the length of element value is less or more than given number
  4406. *
  4407. * @param {BootstrapValidator} validator The validator plugin instance
  4408. * @param {jQuery} $field Field element
  4409. * @param {Object} options Consists of following keys:
  4410. * - min
  4411. * - max
  4412. * At least one of two keys is required
  4413. * The min, max keys define the number which the field value compares to. min, max can be
  4414. * - A number
  4415. * - Name of field which its value defines the number
  4416. * - Name of callback function that returns the number
  4417. * - A callback function that returns the number
  4418. *
  4419. * - message: The invalid message
  4420. * @returns {Object}
  4421. */
  4422. validate: function(validator, $field, options) {
  4423. var value = $field.val();
  4424. if (value === '') {
  4425. return true;
  4426. }
  4427. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption(options.min, $field),
  4428. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption(options.max, $field),
  4429. length = value.length,
  4430. isValid = true,
  4431. message = options.message || $.fn.bootstrapValidator.i18n.stringLength['default'];
  4432. if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
  4433. isValid = false;
  4434. }
  4435. switch (true) {
  4436. case (!!min && !!max):
  4437. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
  4438. break;
  4439. case (!!min):
  4440. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.more, parseInt(min, 10));
  4441. break;
  4442. case (!!max):
  4443. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.less, parseInt(max, 10));
  4444. break;
  4445. default:
  4446. break;
  4447. }
  4448. return { valid: isValid, message: message };
  4449. }
  4450. };
  4451. }(window.jQuery));
  4452. ;(function($) {
  4453. $.fn.bootstrapValidator.i18n.uri = $.extend($.fn.bootstrapValidator.i18n.uri || {}, {
  4454. 'default': 'Please enter a valid URI'
  4455. });
  4456. $.fn.bootstrapValidator.validators.uri = {
  4457. html5Attributes: {
  4458. message: 'message',
  4459. allowlocal: 'allowLocal'
  4460. },
  4461. enableByHtml5: function($field) {
  4462. return ('url' === $field.attr('type'));
  4463. },
  4464. /**
  4465. * Return true if the input value is a valid URL
  4466. *
  4467. * @param {BootstrapValidator} validator The validator plugin instance
  4468. * @param {jQuery} $field Field element
  4469. * @param {Object} options
  4470. * - message: The error message
  4471. * - allowLocal: Allow the private and local network IP. Default to false
  4472. * @returns {Boolean}
  4473. */
  4474. validate: function(validator, $field, options) {
  4475. var value = $field.val();
  4476. if (value === '') {
  4477. return true;
  4478. }
  4479. // Credit to https://gist.github.com/dperini/729294
  4480. //
  4481. // Regular Expression for URL validation
  4482. //
  4483. // Author: Diego Perini
  4484. // Updated: 2010/12/05
  4485. //
  4486. // the regular expression composed & commented
  4487. // could be easily tweaked for RFC compliance,
  4488. // it was expressly modified to fit & satisfy
  4489. // these test for an URL shortener:
  4490. //
  4491. // http://mathiasbynens.be/demo/url-regex
  4492. //
  4493. // Notes on possible differences from a standard/generic validation:
  4494. //
  4495. // - utf-8 char class take in consideration the full Unicode range
  4496. // - TLDs have been made mandatory so single names like "localhost" fails
  4497. // - protocols have been restricted to ftp, http and https only as requested
  4498. //
  4499. // Changes:
  4500. //
  4501. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  4502. // first and last IP address of each class is considered invalid
  4503. // (since they are broadcast/network addresses)
  4504. //
  4505. // - Added exclusion of private, reserved and/or local networks ranges
  4506. //
  4507. var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
  4508. urlExp = new RegExp(
  4509. "^" +
  4510. // protocol identifier
  4511. "(?:(?:https?|ftp)://)" +
  4512. // user:pass authentication
  4513. "(?:\\S+(?::\\S*)?@)?" +
  4514. "(?:" +
  4515. // IP address exclusion
  4516. // private & local networks
  4517. (allowLocal
  4518. ? ''
  4519. : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  4520. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  4521. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
  4522. // IP address dotted notation octets
  4523. // excludes loopback network 0.0.0.0
  4524. // excludes reserved space >= 224.0.0.0
  4525. // excludes network & broadcast addresses
  4526. // (first & last IP address of each class)
  4527. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  4528. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  4529. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  4530. "|" +
  4531. // host name
  4532. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  4533. // domain name
  4534. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  4535. // TLD identifier
  4536. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  4537. ")" +
  4538. // port number
  4539. "(?::\\d{2,5})?" +
  4540. // resource path
  4541. "(?:/[^\\s]*)?" +
  4542. "$", "i"
  4543. );
  4544. return urlExp.test(value);
  4545. }
  4546. };
  4547. }(window.jQuery));
  4548. ;(function($) {
  4549. $.fn.bootstrapValidator.i18n.uuid = $.extend($.fn.bootstrapValidator.i18n.uuid || {}, {
  4550. 'default': 'Please enter a valid UUID number',
  4551. version: 'Please enter a valid UUID version %s number'
  4552. });
  4553. $.fn.bootstrapValidator.validators.uuid = {
  4554. html5Attributes: {
  4555. message: 'message',
  4556. version: 'version'
  4557. },
  4558. /**
  4559. * Return true if and only if the input value is a valid UUID string
  4560. *
  4561. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  4562. * @param {BootstrapValidator} validator The validator plugin instance
  4563. * @param {jQuery} $field Field element
  4564. * @param {Object} options Consist of key:
  4565. * - message: The invalid message
  4566. * - version: Can be 3, 4, 5, null
  4567. * @returns {Boolean|Object}
  4568. */
  4569. validate: function(validator, $field, options) {
  4570. var value = $field.val();
  4571. if (value === '') {
  4572. return true;
  4573. }
  4574. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  4575. var patterns = {
  4576. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  4577. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  4578. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  4579. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  4580. },
  4581. version = options.version ? (options.version + '') : 'all';
  4582. return {
  4583. valid: (null === patterns[version]) ? true : patterns[version].test(value),
  4584. message: options.version
  4585. ? $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.uuid.version, options.version)
  4586. : (options.message || $.fn.bootstrapValidator.i18n.uuid['default'])
  4587. };
  4588. }
  4589. };
  4590. }(window.jQuery));
  4591. ;(function($) {
  4592. $.fn.bootstrapValidator.i18n.vat = $.extend($.fn.bootstrapValidator.i18n.vat || {}, {
  4593. 'default': 'Please enter a valid VAT number',
  4594. countryNotSupported: 'The country code %s is not supported',
  4595. country: 'Please enter a valid %s VAT number',
  4596. countries: {
  4597. AT: 'Austrian',
  4598. BE: 'Belgian',
  4599. BG: 'Bulgarian',
  4600. CH: 'Swiss',
  4601. CY: 'Cypriot',
  4602. CZ: 'Czech',
  4603. DE: 'German',
  4604. DK: 'Danish',
  4605. EE: 'Estonian',
  4606. ES: 'Spanish',
  4607. FI: 'Finnish',
  4608. FR: 'French',
  4609. GB: 'United Kingdom',
  4610. GR: 'Greek',
  4611. EL: 'Greek',
  4612. HU: 'Hungarian',
  4613. HR: 'Croatian',
  4614. IE: 'Irish',
  4615. IT: 'Italian',
  4616. LT: 'Lithuanian',
  4617. LU: 'Luxembourg',
  4618. LV: 'Latvian',
  4619. MT: 'Maltese',
  4620. NL: 'Dutch',
  4621. NO: 'Norwegian',
  4622. PL: 'Polish',
  4623. PT: 'Portuguese',
  4624. RO: 'Romanian',
  4625. RU: 'Russian',
  4626. RS: 'Serbian',
  4627. SE: 'Swedish',
  4628. SI: 'Slovenian',
  4629. SK: 'Slovak'
  4630. }
  4631. });
  4632. $.fn.bootstrapValidator.validators.vat = {
  4633. html5Attributes: {
  4634. message: 'message',
  4635. country: 'country'
  4636. },
  4637. // Supported country codes
  4638. COUNTRY_CODES: [
  4639. 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'EL', 'HU', 'IE', 'IT',
  4640. 'LV', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SK', 'SI', 'ES', 'SE', 'CH', 'GB'
  4641. ],
  4642. /**
  4643. * Validate an European VAT number
  4644. *
  4645. * @param {BootstrapValidator} validator The validator plugin instance
  4646. * @param {jQuery} $field Field element
  4647. * @param {Object} options Consist of key:
  4648. * - message: The invalid message
  4649. * - country: The ISO 3166-1 country code. It can be
  4650. * - One of country code defined in COUNTRY_CODES
  4651. * - Name of field which its value defines the country code
  4652. * - Name of callback function that returns the country code
  4653. * - A callback function that returns the country code
  4654. * @returns {Boolean|Object}
  4655. */
  4656. validate: function(validator, $field, options) {
  4657. var value = $field.val();
  4658. if (value === '') {
  4659. return true;
  4660. }
  4661. var country = options.country;
  4662. if (!country) {
  4663. country = value.substr(0, 2);
  4664. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  4665. // Determine the country code
  4666. country = validator.getDynamicOption(country, $field);
  4667. }
  4668. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  4669. return {
  4670. valid: false,
  4671. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.vat.countryNotSupported, country)
  4672. };
  4673. }
  4674. var method = ['_', country.toLowerCase()].join('');
  4675. return this[method](value)
  4676. ? true
  4677. : {
  4678. valid: false,
  4679. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.vat.country, $.fn.bootstrapValidator.i18n.vat.countries[country.toUpperCase()])
  4680. };
  4681. },
  4682. // VAT validators
  4683. /**
  4684. * Validate Austrian VAT number
  4685. * Example:
  4686. * - Valid: ATU13585627
  4687. * - Invalid: ATU13585626
  4688. *
  4689. * @param {String} value VAT number
  4690. * @returns {Boolean}
  4691. */
  4692. _at: function(value) {
  4693. if (!/^ATU[0-9]{8}$/.test(value)) {
  4694. return false;
  4695. }
  4696. value = value.substr(3);
  4697. var sum = 0,
  4698. weight = [1, 2, 1, 2, 1, 2, 1],
  4699. temp = 0;
  4700. for (var i = 0; i < 7; i++) {
  4701. temp = parseInt(value.charAt(i), 10) * weight[i];
  4702. if (temp > 9) {
  4703. temp = Math.floor(temp / 10) + temp % 10;
  4704. }
  4705. sum += temp;
  4706. }
  4707. sum = 10 - (sum + 4) % 10;
  4708. if (sum === 10) {
  4709. sum = 0;
  4710. }
  4711. return (sum + '' === value.substr(7, 1));
  4712. },
  4713. /**
  4714. * Validate Belgian VAT number
  4715. * Example:
  4716. * - Valid: BE0428759497
  4717. * - Invalid: BE431150351
  4718. *
  4719. * @param {String} value VAT number
  4720. * @returns {Boolean}
  4721. */
  4722. _be: function(value) {
  4723. if (!/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  4724. return false;
  4725. }
  4726. value = value.substr(2);
  4727. if (value.length === 9) {
  4728. value = '0' + value;
  4729. }
  4730. if (value.substr(1, 1) === '0') {
  4731. return false;
  4732. }
  4733. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  4734. return (sum % 97 === 0);
  4735. },
  4736. /**
  4737. * Validate Bulgarian VAT number
  4738. * Example:
  4739. * - Valid: BG175074752,
  4740. * BG7523169263, BG8032056031,
  4741. * BG7542011030,
  4742. * BG7111042925
  4743. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  4744. *
  4745. * @param {String} value VAT number
  4746. * @returns {Boolean}
  4747. */
  4748. _bg: function(value) {
  4749. if (!/^BG[0-9]{9,10}$/.test(value)) {
  4750. return false;
  4751. }
  4752. value = value.substr(2);
  4753. var sum = 0, i = 0;
  4754. // Legal entities
  4755. if (value.length === 9) {
  4756. for (i = 0; i < 8; i++) {
  4757. sum += parseInt(value.charAt(i), 10) * (i + 1);
  4758. }
  4759. sum = sum % 11;
  4760. if (sum === 10) {
  4761. sum = 0;
  4762. for (i = 0; i < 8; i++) {
  4763. sum += parseInt(value.charAt(i), 10) * (i + 3);
  4764. }
  4765. }
  4766. sum = sum % 10;
  4767. return (sum + '' === value.substr(8));
  4768. }
  4769. // Physical persons, foreigners and others
  4770. else if (value.length === 10) {
  4771. // Validate Bulgarian national identification numbers
  4772. var egn = function(value) {
  4773. // Check the birth date
  4774. var year = parseInt(value.substr(0, 2), 10) + 1900,
  4775. month = parseInt(value.substr(2, 2), 10),
  4776. day = parseInt(value.substr(4, 2), 10);
  4777. if (month > 40) {
  4778. year += 100;
  4779. month -= 40;
  4780. } else if (month > 20) {
  4781. year -= 100;
  4782. month -= 20;
  4783. }
  4784. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4785. return false;
  4786. }
  4787. var sum = 0,
  4788. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  4789. for (var i = 0; i < 9; i++) {
  4790. sum += parseInt(value.charAt(i), 10) * weight[i];
  4791. }
  4792. sum = (sum % 11) % 10;
  4793. return (sum + '' === value.substr(9, 1));
  4794. },
  4795. // Validate Bulgarian personal number of a foreigner
  4796. pnf = function(value) {
  4797. var sum = 0,
  4798. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  4799. for (var i = 0; i < 9; i++) {
  4800. sum += parseInt(value.charAt(i), 10) * weight[i];
  4801. }
  4802. sum = sum % 10;
  4803. return (sum + '' === value.substr(9, 1));
  4804. },
  4805. // Finally, consider it as a VAT number
  4806. vat = function(value) {
  4807. var sum = 0,
  4808. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  4809. for (var i = 0; i < 9; i++) {
  4810. sum += parseInt(value.charAt(i), 10) * weight[i];
  4811. }
  4812. sum = 11 - sum % 11;
  4813. if (sum === 10) {
  4814. return false;
  4815. }
  4816. if (sum === 11) {
  4817. sum = 0;
  4818. }
  4819. return (sum + '' === value.substr(9, 1));
  4820. };
  4821. return (egn(value) || pnf(value) || vat(value));
  4822. }
  4823. return false;
  4824. },
  4825. /**
  4826. * Validate Swiss VAT number
  4827. *
  4828. * @param {String} value VAT number
  4829. * @returns {Boolean}
  4830. */
  4831. _ch: function(value) {
  4832. if (!/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  4833. return false;
  4834. }
  4835. value = value.substr(3);
  4836. var sum = 0,
  4837. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  4838. for (var i = 0; i < 8; i++) {
  4839. sum += parseInt(value.charAt(i), 10) * weight[i];
  4840. }
  4841. sum = 11 - sum % 11;
  4842. if (sum === 10) {
  4843. return false;
  4844. }
  4845. if (sum === 11) {
  4846. sum = 0;
  4847. }
  4848. return (sum + '' === value.substr(8, 1));
  4849. },
  4850. /**
  4851. * Validate Cypriot VAT number
  4852. * Examples:
  4853. * - Valid: CY10259033P
  4854. * - Invalid: CY10259033Z
  4855. *
  4856. * @param {String} value VAT number
  4857. * @returns {Boolean}
  4858. */
  4859. _cy: function(value) {
  4860. if (!/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  4861. return false;
  4862. }
  4863. value = value.substr(2);
  4864. // Do not allow to start with "12"
  4865. if (value.substr(0, 2) === '12') {
  4866. return false;
  4867. }
  4868. // Extract the next digit and multiply by the counter.
  4869. var sum = 0,
  4870. translation = {
  4871. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  4872. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  4873. };
  4874. for (var i = 0; i < 8; i++) {
  4875. var temp = parseInt(value.charAt(i), 10);
  4876. if (i % 2 === 0) {
  4877. temp = translation[temp + ''];
  4878. }
  4879. sum += temp;
  4880. }
  4881. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  4882. return (sum + '' === value.substr(8, 1));
  4883. },
  4884. /**
  4885. * Validate Czech Republic VAT number
  4886. * Can be:
  4887. * i) Legal entities (8 digit numbers)
  4888. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  4889. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  4890. *
  4891. * Examples:
  4892. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  4893. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  4894. *
  4895. * @param {String} value VAT number
  4896. * @returns {Boolean}
  4897. */
  4898. _cz: function(value) {
  4899. if (!/^CZ[0-9]{8,10}$/.test(value)) {
  4900. return false;
  4901. }
  4902. value = value.substr(2);
  4903. var sum = 0,
  4904. i = 0;
  4905. if (value.length === 8) {
  4906. // Do not allow to start with '9'
  4907. if (value.charAt(0) + '' === '9') {
  4908. return false;
  4909. }
  4910. sum = 0;
  4911. for (i = 0; i < 7; i++) {
  4912. sum += parseInt(value.charAt(i), 10) * (8 - i);
  4913. }
  4914. sum = 11 - sum % 11;
  4915. if (sum === 10) {
  4916. sum = 0;
  4917. }
  4918. if (sum === 11) {
  4919. sum = 1;
  4920. }
  4921. return (sum + '' === value.substr(7, 1));
  4922. } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
  4923. sum = 0;
  4924. // Skip the first (which is 6)
  4925. for (i = 0; i < 7; i++) {
  4926. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  4927. }
  4928. sum = 11 - sum % 11;
  4929. if (sum === 10) {
  4930. sum = 0;
  4931. }
  4932. if (sum === 11) {
  4933. sum = 1;
  4934. }
  4935. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  4936. return (sum + '' === value.substr(8, 1));
  4937. } else if (value.length === 9 || value.length === 10) {
  4938. // Validate Czech birth number (Rodné číslo), which is also national identifier
  4939. var year = 1900 + parseInt(value.substr(0, 2), 10),
  4940. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  4941. day = parseInt(value.substr(4, 2), 10);
  4942. if (value.length === 9) {
  4943. if (year >= 1980) {
  4944. year -= 100;
  4945. }
  4946. if (year > 1953) {
  4947. return false;
  4948. }
  4949. } else if (year < 1954) {
  4950. year += 100;
  4951. }
  4952. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4953. return false;
  4954. }
  4955. // Check that the birth date is not in the future
  4956. if (value.length === 10) {
  4957. var check = parseInt(value.substr(0, 9), 10) % 11;
  4958. if (year < 1985) {
  4959. check = check % 10;
  4960. }
  4961. return (check + '' === value.substr(9, 1));
  4962. }
  4963. return true;
  4964. }
  4965. return false;
  4966. },
  4967. /**
  4968. * Validate German VAT number
  4969. * Examples:
  4970. * - Valid: DE136695976
  4971. * - Invalid: DE136695978
  4972. *
  4973. * @param {String} value VAT number
  4974. * @returns {Boolean}
  4975. */
  4976. _de: function(value) {
  4977. if (!/^DE[0-9]{9}$/.test(value)) {
  4978. return false;
  4979. }
  4980. value = value.substr(2);
  4981. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  4982. },
  4983. /**
  4984. * Validate Danish VAT number
  4985. * Example:
  4986. * - Valid: DK13585628
  4987. * - Invalid: DK13585627
  4988. *
  4989. * @param {String} value VAT number
  4990. * @returns {Boolean}
  4991. */
  4992. _dk: function(value) {
  4993. if (!/^DK[0-9]{8}$/.test(value)) {
  4994. return false;
  4995. }
  4996. value = value.substr(2);
  4997. var sum = 0,
  4998. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  4999. for (var i = 0; i < 8; i++) {
  5000. sum += parseInt(value.charAt(i), 10) * weight[i];
  5001. }
  5002. return (sum % 11 === 0);
  5003. },
  5004. /**
  5005. * Validate Estonian VAT number
  5006. * Examples:
  5007. * - Valid: EE100931558, EE100594102
  5008. * - Invalid: EE100594103
  5009. *
  5010. * @param {String} value VAT number
  5011. * @returns {Boolean}
  5012. */
  5013. _ee: function(value) {
  5014. if (!/^EE[0-9]{9}$/.test(value)) {
  5015. return false;
  5016. }
  5017. value = value.substr(2);
  5018. var sum = 0,
  5019. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  5020. for (var i = 0; i < 9; i++) {
  5021. sum += parseInt(value.charAt(i), 10) * weight[i];
  5022. }
  5023. return (sum % 10 === 0);
  5024. },
  5025. /**
  5026. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  5027. * Can be:
  5028. * i) DNI (Documento nacional de identidad), for Spaniards
  5029. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  5030. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  5031. *
  5032. * Examples:
  5033. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  5034. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  5035. *
  5036. * @param {String} value VAT number
  5037. * @returns {Boolean}
  5038. */
  5039. _es: function(value) {
  5040. if (!/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  5041. return false;
  5042. }
  5043. value = value.substr(2);
  5044. var dni = function(value) {
  5045. var check = parseInt(value.substr(0, 8), 10);
  5046. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  5047. return (check + '' === value.substr(8, 1));
  5048. },
  5049. nie = function(value) {
  5050. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  5051. check = parseInt(check, 10);
  5052. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  5053. return (check + '' === value.substr(8, 1));
  5054. },
  5055. cif = function(value) {
  5056. var first = value.charAt(0), check;
  5057. if ('KLM'.indexOf(first) !== -1) {
  5058. // K: Spanish younger than 14 year old
  5059. // L: Spanish living outside Spain without DNI
  5060. // M: Granted the tax to foreigners who have no NIE
  5061. check = parseInt(value.substr(1, 8), 10);
  5062. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  5063. return (check + '' === value.substr(8, 1));
  5064. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
  5065. var sum = 0,
  5066. weight = [2, 1, 2, 1, 2, 1, 2],
  5067. temp = 0;
  5068. for (var i = 0; i < 7; i++) {
  5069. temp = parseInt(value.charAt(i + 1), 10) * weight[i];
  5070. if (temp > 9) {
  5071. temp = Math.floor(temp / 10) + temp % 10;
  5072. }
  5073. sum += temp;
  5074. }
  5075. sum = 10 - sum % 10;
  5076. return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
  5077. }
  5078. return false;
  5079. };
  5080. var first = value.charAt(0);
  5081. if (/^[0-9]$/.test(first)) {
  5082. return dni(value);
  5083. } else if (/^[XYZ]$/.test(first)) {
  5084. return nie(value);
  5085. } else {
  5086. return cif(value);
  5087. }
  5088. },
  5089. /**
  5090. * Validate Finnish VAT number
  5091. * Examples:
  5092. * - Valid: FI20774740
  5093. * - Invalid: FI20774741
  5094. *
  5095. * @param {String} value VAT number
  5096. * @returns {Boolean}
  5097. */
  5098. _fi: function(value) {
  5099. if (!/^FI[0-9]{8}$/.test(value)) {
  5100. return false;
  5101. }
  5102. value = value.substr(2);
  5103. var sum = 0,
  5104. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  5105. for (var i = 0; i < 8; i++) {
  5106. sum += parseInt(value.charAt(i), 10) * weight[i];
  5107. }
  5108. return (sum % 11 === 0);
  5109. },
  5110. /**
  5111. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  5112. * It's constructed by a SIREN number, prefixed by two characters.
  5113. *
  5114. * Examples:
  5115. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  5116. * - Invalid: FR84323140391
  5117. *
  5118. * @param {String} value VAT number
  5119. * @returns {Boolean}
  5120. */
  5121. _fr: function(value) {
  5122. if (!/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  5123. return false;
  5124. }
  5125. value = value.substr(2);
  5126. if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
  5127. return false;
  5128. }
  5129. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  5130. // First two characters are digits
  5131. return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
  5132. } else {
  5133. // The first characters cann't be O and I
  5134. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  5135. check;
  5136. // First one is digit
  5137. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  5138. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  5139. } else {
  5140. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  5141. }
  5142. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
  5143. }
  5144. },
  5145. /**
  5146. * Validate United Kingdom VAT number
  5147. * Example:
  5148. * - Valid: GB980780684
  5149. * - Invalid: GB802311781
  5150. *
  5151. * @param {String} value VAT number
  5152. * @returns {Boolean}
  5153. */
  5154. _gb: function(value) {
  5155. if (!/^GB[0-9]{9}$/.test(value) /* Standard */
  5156. && !/^GB[0-9]{12}$/.test(value) /* Branches */
  5157. && !/^GBGD[0-9]{3}$/.test(value) /* Government department */
  5158. && !/^GBHA[0-9]{3}$/.test(value) /* Health authority */
  5159. && !/^GB(GD|HA)8888[0-9]{5}$/.test(value))
  5160. {
  5161. return false;
  5162. }
  5163. value = value.substr(2);
  5164. var length = value.length;
  5165. if (length === 5) {
  5166. var firstTwo = value.substr(0, 2),
  5167. lastThree = parseInt(value.substr(2), 10);
  5168. return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
  5169. } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
  5170. if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
  5171. || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
  5172. {
  5173. return false;
  5174. }
  5175. return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
  5176. } else if (length === 9 || length === 12) {
  5177. var sum = 0,
  5178. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  5179. for (var i = 0; i < 9; i++) {
  5180. sum += parseInt(value.charAt(i), 10) * weight[i];
  5181. }
  5182. sum = sum % 97;
  5183. if (parseInt(value.substr(0, 3), 10) >= 100) {
  5184. return (sum === 0 || sum === 42 || sum === 55);
  5185. } else {
  5186. return (sum === 0);
  5187. }
  5188. }
  5189. return true;
  5190. },
  5191. /**
  5192. * Validate Greek VAT number
  5193. * Examples:
  5194. * - Valid: GR023456780, EL094259216
  5195. * - Invalid: EL123456781
  5196. *
  5197. * @param {String} value VAT number
  5198. * @returns {Boolean}
  5199. */
  5200. _gr: function(value) {
  5201. if (!/^GR[0-9]{9}$/.test(value)) {
  5202. return false;
  5203. }
  5204. value = value.substr(2);
  5205. if (value.length === 8) {
  5206. value = '0' + value;
  5207. }
  5208. var sum = 0,
  5209. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  5210. for (var i = 0; i < 8; i++) {
  5211. sum += parseInt(value.charAt(i), 10) * weight[i];
  5212. }
  5213. sum = (sum % 11) % 10;
  5214. return (sum + '' === value.substr(8, 1));
  5215. },
  5216. // EL is traditionally prefix of Greek VAT numbers
  5217. _el: function(value) {
  5218. if (!/^EL[0-9]{9}$/.test(value)) {
  5219. return false;
  5220. }
  5221. value = 'GR' + value.substr(2);
  5222. return this._gr(value);
  5223. },
  5224. /**
  5225. * Validate Hungarian VAT number
  5226. * Examples:
  5227. * - Valid: HU12892312
  5228. * - Invalid: HU12892313
  5229. *
  5230. * @param {String} value VAT number
  5231. * @returns {Boolean}
  5232. */
  5233. _hu: function(value) {
  5234. if (!/^HU[0-9]{8}$/.test(value)) {
  5235. return false;
  5236. }
  5237. value = value.substr(2);
  5238. var sum = 0,
  5239. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  5240. for (var i = 0; i < 8; i++) {
  5241. sum += parseInt(value.charAt(i), 10) * weight[i];
  5242. }
  5243. return (sum % 10 === 0);
  5244. },
  5245. /**
  5246. * Validate Croatian VAT number
  5247. * Examples:
  5248. * - Valid: HR33392005961
  5249. * - Invalid: HR33392005962
  5250. *
  5251. * @param {String} value VAT number
  5252. * @returns {Boolean}
  5253. */
  5254. _hr: function(value) {
  5255. if (!/^HR[0-9]{11}$/.test(value)) {
  5256. return false;
  5257. }
  5258. value = value.substr(2);
  5259. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  5260. },
  5261. /**
  5262. * Validate Irish VAT number
  5263. * Examples:
  5264. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  5265. * - Invalid: IE8D79738J
  5266. *
  5267. * @param {String} value VAT number
  5268. * @returns {Boolean}
  5269. */
  5270. _ie: function(value) {
  5271. if (!/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  5272. return false;
  5273. }
  5274. value = value.substr(2);
  5275. var getCheckDigit = function(value) {
  5276. while (value.length < 7) {
  5277. value = '0' + value;
  5278. }
  5279. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  5280. sum = 0;
  5281. for (var i = 0; i < 7; i++) {
  5282. sum += parseInt(value.charAt(i), 10) * (8 - i);
  5283. }
  5284. sum += 9 * alphabet.indexOf(value.substr(7));
  5285. return alphabet[sum % 23];
  5286. };
  5287. // The first 7 characters are digits
  5288. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  5289. // New system
  5290. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  5291. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
  5292. // Old system
  5293. return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  5294. }
  5295. return true;
  5296. },
  5297. /**
  5298. * Validate Italian VAT number, which consists of 11 digits.
  5299. * - First 7 digits are a company identifier
  5300. * - Next 3 are the province of residence
  5301. * - The last one is a check digit
  5302. *
  5303. * Examples:
  5304. * - Valid: IT00743110157
  5305. * - Invalid: IT00743110158
  5306. *
  5307. * @param {String} value VAT number
  5308. * @returns {Boolean}
  5309. */
  5310. _it: function(value) {
  5311. if (!/^IT[0-9]{11}$/.test(value)) {
  5312. return false;
  5313. }
  5314. value = value.substr(2);
  5315. if (parseInt(value.substr(0, 7), 10) === 0) {
  5316. return false;
  5317. }
  5318. var lastThree = parseInt(value.substr(7, 3), 10);
  5319. if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
  5320. return false;
  5321. }
  5322. return $.fn.bootstrapValidator.helpers.luhn(value);
  5323. },
  5324. /**
  5325. * Validate Lithuanian VAT number
  5326. * It can be:
  5327. * - 9 digits, for legal entities
  5328. * - 12 digits, for temporarily registered taxpayers
  5329. *
  5330. * Examples:
  5331. * - Valid: LT119511515, LT100001919017, LT100004801610
  5332. * - Invalid: LT100001919018
  5333. *
  5334. * @param {String} value VAT number
  5335. * @returns {Boolean}
  5336. */
  5337. _lt: function(value) {
  5338. if (!/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  5339. return false;
  5340. }
  5341. value = value.substr(2);
  5342. var length = value.length,
  5343. sum = 0,
  5344. i;
  5345. for (i = 0; i < length - 1; i++) {
  5346. sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
  5347. }
  5348. var check = sum % 11;
  5349. if (check === 10) {
  5350. sum = 0;
  5351. for (i = 0; i < length - 1; i++) {
  5352. sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
  5353. }
  5354. }
  5355. check = check % 11 % 10;
  5356. return (check + '' === value.charAt(length - 1));
  5357. },
  5358. /**
  5359. * Validate Luxembourg VAT number
  5360. * Examples:
  5361. * - Valid: LU15027442
  5362. * - Invalid: LU15027443
  5363. *
  5364. * @param {String} value VAT number
  5365. * @returns {Boolean}
  5366. */
  5367. _lu: function(value) {
  5368. if (!/^LU[0-9]{8}$/.test(value)) {
  5369. return false;
  5370. }
  5371. value = value.substr(2);
  5372. return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
  5373. },
  5374. /**
  5375. * Validate Latvian VAT number
  5376. * Examples:
  5377. * - Valid: LV40003521600, LV16117519997
  5378. * - Invalid: LV40003521601, LV16137519997
  5379. *
  5380. * @param {String} value VAT number
  5381. * @returns {Boolean}
  5382. */
  5383. _lv: function(value) {
  5384. if (!/^LV[0-9]{11}$/.test(value)) {
  5385. return false;
  5386. }
  5387. value = value.substr(2);
  5388. var first = parseInt(value.charAt(0), 10),
  5389. sum = 0,
  5390. weight = [],
  5391. i,
  5392. length = value.length;
  5393. if (first > 3) {
  5394. // Legal entity
  5395. sum = 0;
  5396. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  5397. for (i = 0; i < length; i++) {
  5398. sum += parseInt(value.charAt(i), 10) * weight[i];
  5399. }
  5400. sum = sum % 11;
  5401. return (sum === 3);
  5402. } else {
  5403. // Check birth date
  5404. var day = parseInt(value.substr(0, 2), 10),
  5405. month = parseInt(value.substr(2, 2), 10),
  5406. year = parseInt(value.substr(4, 2), 10);
  5407. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  5408. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  5409. return false;
  5410. }
  5411. // Check personal code
  5412. sum = 0;
  5413. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  5414. for (i = 0; i < length - 1; i++) {
  5415. sum += parseInt(value.charAt(i), 10) * weight[i];
  5416. }
  5417. sum = (sum + 1) % 11 % 10;
  5418. return (sum + '' === value.charAt(length - 1));
  5419. }
  5420. },
  5421. /**
  5422. * Validate Maltese VAT number
  5423. * Examples:
  5424. * - Valid: MT11679112
  5425. * - Invalid: MT11679113
  5426. *
  5427. * @param {String} value VAT number
  5428. * @returns {Boolean}
  5429. */
  5430. _mt: function(value) {
  5431. if (!/^MT[0-9]{8}$/.test(value)) {
  5432. return false;
  5433. }
  5434. value = value.substr(2);
  5435. var sum = 0,
  5436. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  5437. for (var i = 0; i < 8; i++) {
  5438. sum += parseInt(value.charAt(i), 10) * weight[i];
  5439. }
  5440. return (sum % 37 === 0);
  5441. },
  5442. /**
  5443. * Validate Dutch VAT number
  5444. * Examples:
  5445. * - Valid: NL004495445B01
  5446. * - Invalid: NL123456789B90
  5447. *
  5448. * @param {String} value VAT number
  5449. * @returns {Boolean}
  5450. */
  5451. _nl: function(value) {
  5452. if (!/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  5453. return false;
  5454. }
  5455. value = value.substr(2);
  5456. var sum = 0,
  5457. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  5458. for (var i = 0; i < 8; i++) {
  5459. sum += parseInt(value.charAt(i), 10) * weight[i];
  5460. }
  5461. sum = sum % 11;
  5462. if (sum > 9) {
  5463. sum = 0;
  5464. }
  5465. return (sum + '' === value.substr(8, 1));
  5466. },
  5467. /**
  5468. * Validate Norwegian VAT number
  5469. *
  5470. * @see http://www.brreg.no/english/coordination/number.html
  5471. * @param {String} value VAT number
  5472. * @returns {Boolean}
  5473. */
  5474. _no: function(value) {
  5475. if (!/^NO[0-9]{9}$/.test(value)) {
  5476. return false;
  5477. }
  5478. value = value.substr(2);
  5479. var sum = 0,
  5480. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  5481. for (var i = 0; i < 8; i++) {
  5482. sum += parseInt(value.charAt(i), 10) * weight[i];
  5483. }
  5484. sum = 11 - sum % 11;
  5485. if (sum === 11) {
  5486. sum = 0;
  5487. }
  5488. return (sum + '' === value.substr(8, 1));
  5489. },
  5490. /**
  5491. * Validate Polish VAT number
  5492. * Examples:
  5493. * - Valid: PL8567346215
  5494. * - Invalid: PL8567346216
  5495. *
  5496. * @param {String} value VAT number
  5497. * @returns {Boolean}
  5498. */
  5499. _pl: function(value) {
  5500. if (!/^PL[0-9]{10}$/.test(value)) {
  5501. return false;
  5502. }
  5503. value = value.substr(2);
  5504. var sum = 0,
  5505. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  5506. for (var i = 0; i < 10; i++) {
  5507. sum += parseInt(value.charAt(i), 10) * weight[i];
  5508. }
  5509. return (sum % 11 === 0);
  5510. },
  5511. /**
  5512. * Validate Portuguese VAT number
  5513. * Examples:
  5514. * - Valid: PT501964843
  5515. * - Invalid: PT501964842
  5516. *
  5517. * @param {String} value VAT number
  5518. * @returns {Boolean}
  5519. */
  5520. _pt: function(value) {
  5521. if (!/^PT[0-9]{9}$/.test(value)) {
  5522. return false;
  5523. }
  5524. value = value.substr(2);
  5525. var sum = 0,
  5526. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  5527. for (var i = 0; i < 8; i++) {
  5528. sum += parseInt(value.charAt(i), 10) * weight[i];
  5529. }
  5530. sum = 11 - sum % 11;
  5531. if (sum > 9) {
  5532. sum = 0;
  5533. }
  5534. return (sum + '' === value.substr(8, 1));
  5535. },
  5536. /**
  5537. * Validate Romanian VAT number
  5538. * Examples:
  5539. * - Valid: RO18547290
  5540. * - Invalid: RO18547291
  5541. *
  5542. * @param {String} value VAT number
  5543. * @returns {Boolean}
  5544. */
  5545. _ro: function(value) {
  5546. if (!/^RO[1-9][0-9]{1,9}$/.test(value)) {
  5547. return false;
  5548. }
  5549. value = value.substr(2);
  5550. var length = value.length,
  5551. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  5552. sum = 0;
  5553. for (var i = 0; i < length - 1; i++) {
  5554. sum += parseInt(value.charAt(i), 10) * weight[i];
  5555. }
  5556. sum = (10 * sum) % 11 % 10;
  5557. return (sum + '' === value.substr(length - 1, 1));
  5558. },
  5559. /**
  5560. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  5561. *
  5562. * @param {String} value VAT number
  5563. * @returns {Boolean}
  5564. */
  5565. _ru: function(value) {
  5566. if (!/^RU([0-9]{9}|[0-9]{12})$/.test(value)) {
  5567. return false;
  5568. }
  5569. value = value.substr(2);
  5570. var i = 0;
  5571. if (value.length === 10) {
  5572. var sum = 0,
  5573. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  5574. for (i = 0; i < 10; i++) {
  5575. sum += parseInt(value.charAt(i), 10) * weight[i];
  5576. }
  5577. sum = sum % 11;
  5578. if (sum > 9) {
  5579. sum = sum % 10;
  5580. }
  5581. return (sum + '' === value.substr(9, 1));
  5582. } else if (value.length === 12) {
  5583. var sum1 = 0,
  5584. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  5585. sum2 = 0,
  5586. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  5587. for (i = 0; i < 11; i++) {
  5588. sum1 += parseInt(value.charAt(i), 10) * weight1[i];
  5589. sum2 += parseInt(value.charAt(i), 10) * weight2[i];
  5590. }
  5591. sum1 = sum1 % 11;
  5592. if (sum1 > 9) {
  5593. sum1 = sum1 % 10;
  5594. }
  5595. sum2 = sum2 % 11;
  5596. if (sum2 > 9) {
  5597. sum2 = sum2 % 10;
  5598. }
  5599. return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
  5600. }
  5601. return false;
  5602. },
  5603. /**
  5604. * Validate Serbian VAT number
  5605. *
  5606. * @param {String} value VAT number
  5607. * @returns {Boolean}
  5608. */
  5609. _rs: function(value) {
  5610. if (!/^RS[0-9]{9}$/.test(value)) {
  5611. return false;
  5612. }
  5613. value = value.substr(2);
  5614. var sum = 10,
  5615. temp = 0;
  5616. for (var i = 0; i < 8; i++) {
  5617. temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  5618. if (temp === 0) {
  5619. temp = 10;
  5620. }
  5621. sum = (2 * temp) % 11;
  5622. }
  5623. return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
  5624. },
  5625. /**
  5626. * Validate Swedish VAT number
  5627. * Examples:
  5628. * - Valid: SE123456789701
  5629. * - Invalid: SE123456789101
  5630. *
  5631. * @param {String} value VAT number
  5632. * @returns {Boolean}
  5633. */
  5634. _se: function(value) {
  5635. if (!/^SE[0-9]{10}01$/.test(value)) {
  5636. return false;
  5637. }
  5638. value = value.substr(2, 10);
  5639. return $.fn.bootstrapValidator.helpers.luhn(value);
  5640. },
  5641. /**
  5642. * Validate Slovenian VAT number
  5643. * Examples:
  5644. * - Valid: SI50223054
  5645. * - Invalid: SI50223055
  5646. *
  5647. * @param {String} value VAT number
  5648. * @returns {Boolean}
  5649. */
  5650. _si: function(value) {
  5651. if (!/^SI[0-9]{8}$/.test(value)) {
  5652. return false;
  5653. }
  5654. value = value.substr(2);
  5655. var sum = 0,
  5656. weight = [8, 7, 6, 5, 4, 3, 2];
  5657. for (var i = 0; i < 7; i++) {
  5658. sum += parseInt(value.charAt(i), 10) * weight[i];
  5659. }
  5660. sum = 11 - sum % 11;
  5661. if (sum === 10) {
  5662. sum = 0;
  5663. }
  5664. return (sum + '' === value.substr(7, 1));
  5665. },
  5666. /**
  5667. * Validate Slovak VAT number
  5668. * Examples:
  5669. * - Valid: SK2022749619
  5670. * - Invalid: SK2022749618
  5671. *
  5672. * @param {String} value VAT number
  5673. * @returns {Boolean}
  5674. */
  5675. _sk: function(value) {
  5676. if (!/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  5677. return false;
  5678. }
  5679. return (parseInt(value.substr(2), 10) % 11 === 0);
  5680. }
  5681. };
  5682. }(window.jQuery));
  5683. ;(function($) {
  5684. $.fn.bootstrapValidator.i18n.vin = $.extend($.fn.bootstrapValidator.i18n.vin || {}, {
  5685. 'default': 'Please enter a valid VIN number'
  5686. });
  5687. $.fn.bootstrapValidator.validators.vin = {
  5688. /**
  5689. * Validate an US VIN (Vehicle Identification Number)
  5690. *
  5691. * @param {BootstrapValidator} validator The validator plugin instance
  5692. * @param {jQuery} $field Field element
  5693. * @param {Object} options Consist of key:
  5694. * - message: The invalid message
  5695. * @returns {Boolean}
  5696. */
  5697. validate: function(validator, $field, options) {
  5698. var value = $field.val();
  5699. if (value === '') {
  5700. return true;
  5701. }
  5702. // Don't accept I, O, Q characters
  5703. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  5704. return false;
  5705. }
  5706. value = value.toUpperCase();
  5707. var chars = {
  5708. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  5709. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  5710. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  5711. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  5712. },
  5713. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  5714. sum = 0,
  5715. length = value.length;
  5716. for (var i = 0; i < length; i++) {
  5717. sum += chars[value.charAt(i) + ''] * weights[i];
  5718. }
  5719. var reminder = sum % 11;
  5720. if (reminder === 10) {
  5721. reminder = 'X';
  5722. }
  5723. return (reminder + '') === value.charAt(8);
  5724. }
  5725. };
  5726. }(window.jQuery));
  5727. ;(function($) {
  5728. $.fn.bootstrapValidator.i18n.zipCode = $.extend($.fn.bootstrapValidator.i18n.zipCode || {}, {
  5729. 'default': 'Please enter a valid zip code',
  5730. countryNotSupported: 'The country code %s is not supported',
  5731. country: 'Please enter a valid %s',
  5732. countries: {
  5733. 'CA': 'Canadian postal code',
  5734. 'DK': 'Danish postal code',
  5735. 'GB': 'United Kingdom postal code',
  5736. 'IT': 'Italian postal code',
  5737. 'NL': 'Dutch postal code',
  5738. 'SE': 'Swiss postal code',
  5739. 'SG': 'Singapore postal code',
  5740. 'US': 'US zip code'
  5741. }
  5742. });
  5743. $.fn.bootstrapValidator.validators.zipCode = {
  5744. html5Attributes: {
  5745. message: 'message',
  5746. country: 'country'
  5747. },
  5748. COUNTRY_CODES: ['CA', 'DK', 'GB', 'IT', 'NL', 'SE', 'SG', 'US'],
  5749. /**
  5750. * Return true if and only if the input value is a valid country zip code
  5751. *
  5752. * @param {BootstrapValidator} validator The validator plugin instance
  5753. * @param {jQuery} $field Field element
  5754. * @param {Object} options Consist of key:
  5755. * - message: The invalid message
  5756. * - country: The country
  5757. *
  5758. * The country can be defined by:
  5759. * - An ISO 3166 country code
  5760. * Currently it supports the following countries:
  5761. * - US (United States)
  5762. * - CA (Canada)
  5763. * - DK (Denmark)
  5764. * - GB (United Kingdom)
  5765. * - IT (Italy)
  5766. * - NL (Netherlands)
  5767. * - SE (Sweden)
  5768. * - SG (Singapore)
  5769. *
  5770. * - Name of field which its value defines the country code
  5771. * - Name of callback function that returns the country code
  5772. * - A callback function that returns the country code
  5773. *
  5774. * callback: function(value, validator, $field) {
  5775. * // value is the value of field
  5776. * // validator is the BootstrapValidator instance
  5777. * // $field is jQuery element representing the field
  5778. * }
  5779. *
  5780. * @returns {Boolean|Object}
  5781. */
  5782. validate: function(validator, $field, options) {
  5783. var value = $field.val();
  5784. if (value === '' || !options.country) {
  5785. return true;
  5786. }
  5787. var country = options.country;
  5788. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  5789. // Try to determine the country
  5790. country = validator.getDynamicOption(country, $field);
  5791. }
  5792. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  5793. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, country) };
  5794. }
  5795. var isValid = false;
  5796. country = country.toUpperCase();
  5797. switch (country) {
  5798. case 'CA':
  5799. isValid = /^(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}$/i.test(value);
  5800. break;
  5801. case 'DK':
  5802. isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
  5803. break;
  5804. case 'GB':
  5805. isValid = this._gb(value);
  5806. break;
  5807. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  5808. case 'IT':
  5809. isValid = /^(I-|IT-)?\d{5}$/i.test(value);
  5810. break;
  5811. // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  5812. case 'NL':
  5813. isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  5814. break;
  5815. case 'SE':
  5816. isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  5817. break;
  5818. case 'SG':
  5819. isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
  5820. break;
  5821. case 'US':
  5822. /* falls through */
  5823. default:
  5824. isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
  5825. break;
  5826. }
  5827. return {
  5828. valid: isValid,
  5829. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.zipCode.country, $.fn.bootstrapValidator.i18n.zipCode.countries[country])
  5830. };
  5831. },
  5832. /**
  5833. * Validate United Kingdom postcode
  5834. * Examples:
  5835. * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  5836. * - Special cases:
  5837. * AI-2640, ASCN 1ZZ, GIR 0AA
  5838. *
  5839. * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  5840. * @param {String} value The postcode
  5841. * @returns {Boolean}
  5842. */
  5843. _gb: function(value) {
  5844. var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
  5845. secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
  5846. thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
  5847. fourthChar = '[ABEHMNPRVWXY]',
  5848. fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
  5849. regexps = [
  5850. // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  5851. new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  5852. // ANA NAA
  5853. new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  5854. // AANA NAA
  5855. new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  5856. new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
  5857. /^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
  5858. /^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
  5859. /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
  5860. /^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
  5861. /^(AI-2640)$/i // Anguilla
  5862. ];
  5863. for (var i = 0; i < regexps.length; i++) {
  5864. if (regexps[i].test(value)) {
  5865. return true;
  5866. }
  5867. }
  5868. return false;
  5869. }
  5870. };
  5871. }(window.jQuery));