bootstrapValidator.js 175 KB

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