bootstrapValidator.js 201 KB

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