bootstrapValidator.js 316 KB

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