bootstrapValidator.js 244 KB

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