bootstrapValidator.js 144 KB

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