bootstrapValidator.js 319 KB

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