官网 管理后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bootstrapValidator.js 318KB

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