bootstrapValidator.js 200 KB

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