bootstrapValidator.js 197 KB

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