bootstrapValidator.js 271 KB

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