bootstrapValidator.js 233 KB

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