bootstrapValidator.js 177 KB

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