bootstrapValidator.js 318 KB

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