bootstrapValidator.js 198 KB

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