bootstrapValidator.js 183 KB

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