bootstrapValidator.js 199 KB

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