bootstrapValidator.js 242 KB

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