bootstrapValidator.js 199 KB

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