bootstrapValidator.js 199 KB

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