bootstrapValidator.js 231 KB

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