bootstrapValidator.js 180 KB

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