bootstrapValidator.js 224 KB

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