bootstrapValidator.js 264 KB

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