bootstrapValidator.js 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672
  1. /**
  2. * BootstrapValidator (http://bootstrapvalidator.com)
  3. *
  4. * A jQuery plugin to validate form fields. Use with Bootstrap 3
  5. *
  6. * @version v0.4.3
  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 (!$field.attr('data-bv-field')) {
  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.emailAddress = {
  1197. enableByHtml5: function($field) {
  1198. return ('email' == $field.attr('type'));
  1199. },
  1200. /**
  1201. * Return true if and only if the input value is a valid email address
  1202. *
  1203. * @param {BootstrapValidator} validator Validate plugin instance
  1204. * @param {jQuery} $field Field element
  1205. * @param {Object} options
  1206. * @returns {Boolean}
  1207. */
  1208. validate: function(validator, $field, options) {
  1209. var value = $field.val();
  1210. if (value == '') {
  1211. return true;
  1212. }
  1213. // Email address regular expression
  1214. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  1215. 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,}))$/;
  1216. return emailRegExp.test(value);
  1217. }
  1218. }
  1219. }(window.jQuery));
  1220. ;(function($) {
  1221. $.fn.bootstrapValidator.validators.file = {
  1222. html5Attributes: {
  1223. extension: 'extension',
  1224. maxsize: 'maxSize',
  1225. message: 'message',
  1226. type: 'type'
  1227. },
  1228. /**
  1229. * Validate upload file. Use HTML 5 API if the browser supports
  1230. *
  1231. * @param {BootstrapValidator} validator The validator plugin instance
  1232. * @param {jQuery} $field Field element
  1233. * @param {Object} options Can consist of the following keys:
  1234. * - extension: The allowed extensions, separated by a comma
  1235. * - maxSize: The maximum size in bytes
  1236. * - message: The invalid message
  1237. * - type: The allowed MIME type, separated by a comma
  1238. * @returns {Boolean}
  1239. */
  1240. validate: function(validator, $field, options) {
  1241. var value = $field.val();
  1242. if (value == '') {
  1243. return true;
  1244. }
  1245. var ext,
  1246. extensions = options.extension ? options.extension.split(',') : null,
  1247. types = options.type ? options.type.split(',') : null,
  1248. html5 = (window.File && window.FileList && window.FileReader);
  1249. if (html5) {
  1250. // Get FileList instance
  1251. var files = $field.get(0).files,
  1252. total = files.length;
  1253. for (var i = 0; i < total; i++) {
  1254. // Check file size
  1255. if (options.maxSize && files[i].size > parseInt(options.maxSize)) {
  1256. return false;
  1257. }
  1258. // Check file extension
  1259. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  1260. if (extensions && extensions.indexOf(ext) == -1) {
  1261. return false;
  1262. }
  1263. // Check file type
  1264. if (types && types.indexOf(files[i].type) == -1) {
  1265. return false;
  1266. }
  1267. }
  1268. } else {
  1269. // Check file extension
  1270. ext = value.substr(value.lastIndexOf('.') + 1);
  1271. if (extensions && extensions.indexOf(ext) == -1) {
  1272. return false;
  1273. }
  1274. }
  1275. return true;
  1276. }
  1277. };
  1278. }(window.jQuery));
  1279. ;(function($) {
  1280. $.fn.bootstrapValidator.validators.greaterThan = {
  1281. html5Attributes: {
  1282. message: 'message',
  1283. value: 'value',
  1284. inclusive: 'inclusive'
  1285. },
  1286. enableByHtml5: function($field) {
  1287. var min = $field.attr('min');
  1288. if (min) {
  1289. return {
  1290. value: min
  1291. };
  1292. }
  1293. return false;
  1294. },
  1295. /**
  1296. * Return true if the input value is greater than or equals to given number
  1297. *
  1298. * @param {BootstrapValidator} validator Validate plugin instance
  1299. * @param {jQuery} $field Field element
  1300. * @param {Object} options Can consist of the following keys:
  1301. * - value: The number used to compare to
  1302. * - inclusive [optional]: Can be true or false. Default is true
  1303. * - message: The invalid message
  1304. * @returns {Boolean}
  1305. */
  1306. validate: function(validator, $field, options) {
  1307. var value = $field.val();
  1308. if (value == '') {
  1309. return true;
  1310. }
  1311. value = parseFloat(value);
  1312. return (options.inclusive === true) ? (value > options.value) : (value >= options.value);
  1313. }
  1314. }
  1315. }(window.jQuery));
  1316. ;(function($) {
  1317. $.fn.bootstrapValidator.validators.hex = {
  1318. /**
  1319. * Return true if and only if the input value is a valid hexadecimal number
  1320. *
  1321. * @param {BootstrapValidator} validator The validator plugin instance
  1322. * @param {jQuery} $field Field element
  1323. * @param {Object} options Consist of key:
  1324. * - message: The invalid message
  1325. * @returns {Boolean}
  1326. */
  1327. validate: function(validator, $field, options) {
  1328. var value = $field.val();
  1329. if (value == '') {
  1330. return true;
  1331. }
  1332. return /^[0-9a-fA-F]+$/.test(value);
  1333. }
  1334. };
  1335. }(window.jQuery));
  1336. ;(function($) {
  1337. $.fn.bootstrapValidator.validators.hexColor = {
  1338. enableByHtml5: function($field) {
  1339. return ('color' == $field.attr('type'));
  1340. },
  1341. /**
  1342. * Return true if the input value is a valid hex color
  1343. *
  1344. * @param {BootstrapValidator} validator The validator plugin instance
  1345. * @param {jQuery} $field Field element
  1346. * @param {Object} options Can consist of the following keys:
  1347. * - message: The invalid message
  1348. * @returns {Boolean}
  1349. */
  1350. validate: function(validator, $field, options) {
  1351. var value = $field.val();
  1352. if (value == '') {
  1353. return true;
  1354. }
  1355. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  1356. }
  1357. };
  1358. }(window.jQuery));
  1359. ;(function($) {
  1360. $.fn.bootstrapValidator.validators.iban = {
  1361. html5Attributes: {
  1362. message: 'message',
  1363. country: 'country'
  1364. },
  1365. /**
  1366. * Validate an International Bank Account Number (IBAN)
  1367. * To test it, take the sample IBAN from
  1368. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  1369. *
  1370. * @param {BootstrapValidator} validator The validator plugin instance
  1371. * @param {jQuery} $field Field element
  1372. * @param {Object} options Can consist of the following keys:
  1373. * - message: The invalid message
  1374. * - country: The ISO 3166-1 country code
  1375. * @returns {Boolean}
  1376. */
  1377. validate: function(validator, $field, options) {
  1378. var value = $field.val();
  1379. if (value == '') {
  1380. return true;
  1381. }
  1382. // See
  1383. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  1384. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  1385. var ibanRegex = {
  1386. 'AD': 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  1387. 'AE': 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  1388. 'AL': 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  1389. 'AO': 'AO[0-9]{2}[0-9]{21}', // Angola
  1390. 'AT': 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  1391. 'AZ': 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  1392. 'BA': 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  1393. 'BE': 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  1394. 'BF': 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  1395. 'BG': 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  1396. 'BH': 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  1397. 'BI': 'BI[0-9]{2}[0-9]{12}', // Burundi
  1398. 'BJ': 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  1399. 'BR': 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  1400. 'CH': 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  1401. 'CI': 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  1402. 'CM': 'CM[0-9]{2}[0-9]{23}', // Cameroon
  1403. 'CR': 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  1404. 'CV': 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  1405. 'CY': 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  1406. 'CZ': 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  1407. 'DE': 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  1408. 'DK': 'DK[0-9]{2}[0-9]{14}', // Denmark
  1409. 'DO': 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  1410. 'DZ': 'DZ[0-9]{2}[0-9]{20}', // Algeria
  1411. 'EE': 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  1412. 'ES': 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  1413. 'FI': 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  1414. 'FO': 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  1415. 'FR': 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  1416. 'GB': 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  1417. 'GE': 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  1418. 'GI': 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  1419. 'GL': 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland[
  1420. 'GR': 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  1421. 'GT': 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  1422. 'HR': 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  1423. 'HU': 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  1424. 'IE': 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  1425. 'IL': 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  1426. 'IR': 'IR[0-9]{2}[0-9]{22}', // Iran
  1427. 'IS': 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  1428. 'IT': 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  1429. 'JO': 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  1430. 'KW': 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  1431. 'KZ': 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  1432. 'LB': 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  1433. 'LI': 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  1434. 'LT': 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  1435. 'LU': 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  1436. 'LV': 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  1437. 'MC': 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  1438. 'MD': 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  1439. 'ME': 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  1440. 'MG': 'MG[0-9]{2}[0-9]{23}', // Madagascar
  1441. 'MK': 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  1442. 'ML': 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  1443. 'MR': 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  1444. 'MT': 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  1445. 'MU': 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}',// Mauritius
  1446. 'MZ': 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  1447. 'NL': 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  1448. 'NO': 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  1449. 'PK': 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  1450. 'PL': 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  1451. 'PS': 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  1452. 'PT': 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  1453. 'QA': 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  1454. 'RO': 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  1455. 'RS': 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  1456. 'SA': 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  1457. 'SE': 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  1458. 'SI': 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  1459. 'SK': 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  1460. 'SM': 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  1461. 'SN': 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  1462. 'TN': 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  1463. 'TR': 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  1464. 'VG': 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  1465. };
  1466. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  1467. var country = options.country || value.substr(0, 2);
  1468. if (!ibanRegex[country]) {
  1469. return false;
  1470. }
  1471. if (!(new RegExp('^' + ibanRegex[country] + '$')).test(value)) {
  1472. return false;
  1473. }
  1474. value = value.substr(4) + value.substr(0, 4);
  1475. value = value.split('').map(function(n) {
  1476. var code = n.charCodeAt(0);
  1477. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  1478. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  1479. ? (code - 'A'.charCodeAt(0) + 10)
  1480. : n;
  1481. }).join('');
  1482. var temp = parseInt(value.substr(0, 1), 10),
  1483. length = value.length;
  1484. for (var i = 1; i < length; ++i) {
  1485. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  1486. }
  1487. return (temp == 1);
  1488. }
  1489. };
  1490. }(window.jQuery));
  1491. ;(function($) {
  1492. $.fn.bootstrapValidator.validators.identical = {
  1493. html5Attributes: {
  1494. message: 'message',
  1495. field: 'field'
  1496. },
  1497. /**
  1498. * Check if input value equals to value of particular one
  1499. *
  1500. * @param {BootstrapValidator} validator The validator plugin instance
  1501. * @param {jQuery} $field Field element
  1502. * @param {Object} options Consists of the following key:
  1503. * - field: The name of field that will be used to compare with current one
  1504. * @returns {Boolean}
  1505. */
  1506. validate: function(validator, $field, options) {
  1507. var value = $field.val();
  1508. if (value == '') {
  1509. return true;
  1510. }
  1511. var compareWith = validator.getFieldElements(options.field);
  1512. if (compareWith == null) {
  1513. return true;
  1514. }
  1515. if (value == compareWith.val()) {
  1516. validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
  1517. return true;
  1518. } else {
  1519. return false;
  1520. }
  1521. }
  1522. };
  1523. }(window.jQuery));
  1524. ;(function($) {
  1525. $.fn.bootstrapValidator.validators.integer = {
  1526. enableByHtml5: function($field) {
  1527. return ('number' == $field.attr('type'));
  1528. },
  1529. /**
  1530. * Return true if the input value is an integer
  1531. *
  1532. * @param {BootstrapValidator} validator The validator plugin instance
  1533. * @param {jQuery} $field Field element
  1534. * @param {Object} options Can consist of the following key:
  1535. * - message: The invalid message
  1536. * @returns {Boolean}
  1537. */
  1538. validate: function(validator, $field, options) {
  1539. var value = $field.val();
  1540. if (value == '') {
  1541. return true;
  1542. }
  1543. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  1544. }
  1545. };
  1546. }(window.jQuery));
  1547. ;(function($) {
  1548. $.fn.bootstrapValidator.validators.ip = {
  1549. html5Attributes: {
  1550. message: 'message',
  1551. ipv4: 'ipv4',
  1552. ipv6: 'ipv6'
  1553. },
  1554. /**
  1555. * Return true if the input value is a IP address.
  1556. *
  1557. * @param {BootstrapValidator} validator The validator plugin instance
  1558. * @param {jQuery} $field Field element
  1559. * @param {Object} options Can consist of the following keys:
  1560. * - ipv4: Enable IPv4 validator, default to true
  1561. * - ipv6: Enable IPv6 validator, default to true
  1562. * - message: The invalid message
  1563. * @returns {Boolean}
  1564. */
  1565. validate: function(validator, $field, options) {
  1566. var value = $field.val();
  1567. if (value == '') {
  1568. return true;
  1569. }
  1570. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  1571. if (options.ipv4) {
  1572. 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);
  1573. } else if (options.ipv6) {
  1574. 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);
  1575. }
  1576. return false;
  1577. }
  1578. };
  1579. }(window.jQuery));
  1580. ;(function($) {
  1581. $.fn.bootstrapValidator.validators.isbn = {
  1582. /**
  1583. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  1584. * Examples:
  1585. * - Valid:
  1586. * 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
  1587. * ISBN 13: 978-0-306-40615-7
  1588. * - Invalid:
  1589. * ISBN 10: 99921-58-10-6
  1590. * ISBN 13: 978-0-306-40615-6
  1591. *
  1592. * @param {BootstrapValidator} validator The validator plugin instance
  1593. * @param {jQuery} $field Field element
  1594. * @param {Object} options Can consist of the following keys:
  1595. * - message: The invalid message
  1596. * @returns {Boolean}
  1597. */
  1598. validate: function(validator, $field, options) {
  1599. var value = $field.val();
  1600. if (value == '') {
  1601. return true;
  1602. }
  1603. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  1604. // Groups are separated by a hyphen or a space
  1605. var type;
  1606. switch (true) {
  1607. case /^\d{9}[\dX]$/.test(value):
  1608. case (value.length == 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  1609. case (value.length == 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  1610. type = 'ISBN10';
  1611. break;
  1612. case /^(978|979)\d{9}[\dX]$/.test(value):
  1613. case (value.length == 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  1614. case (value.length == 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  1615. type = 'ISBN13';
  1616. break;
  1617. default:
  1618. return false;
  1619. }
  1620. // Replace all special characters except digits and X
  1621. value = value.replace(/[^0-9X]/gi, '');
  1622. var chars = value.split(''),
  1623. length = chars.length,
  1624. sum = 0,
  1625. checksum;
  1626. switch (type) {
  1627. case 'ISBN10':
  1628. sum = 0;
  1629. for (var i = 0; i < length - 1; i++) {
  1630. sum += ((10 - i) * parseInt(chars[i]));
  1631. }
  1632. checksum = 11 - (sum % 11);
  1633. if (checksum == 11) {
  1634. checksum = 0;
  1635. } else if (checksum == 10) {
  1636. checksum = 'X';
  1637. }
  1638. return (checksum + '' == chars[length - 1]);
  1639. case 'ISBN13':
  1640. sum = 0;
  1641. for (var i = 0; i < length - 1; i++) {
  1642. sum += ((i % 2 == 0) ? parseInt(chars[i]) : (parseInt(chars[i]) * 3));
  1643. }
  1644. checksum = 10 - (sum % 10);
  1645. if (checksum == 10) {
  1646. checksum = '0';
  1647. }
  1648. return (checksum + '' == chars[length - 1]);
  1649. default:
  1650. return false;
  1651. }
  1652. }
  1653. };
  1654. }(window.jQuery));
  1655. ;(function($) {
  1656. $.fn.bootstrapValidator.validators.lessThan = {
  1657. html5Attributes: {
  1658. message: 'message',
  1659. value: 'value',
  1660. inclusive: 'inclusive'
  1661. },
  1662. enableByHtml5: function($field) {
  1663. var max = $field.attr('max');
  1664. if (max) {
  1665. return {
  1666. value: max
  1667. };
  1668. }
  1669. return false;
  1670. },
  1671. /**
  1672. * Return true if the input value is less than or equal to given number
  1673. *
  1674. * @param {BootstrapValidator} validator The validator plugin instance
  1675. * @param {jQuery} $field Field element
  1676. * @param {Object} options Can consist of the following keys:
  1677. * - value: The number used to compare to
  1678. * - inclusive [optional]: Can be true or false. Default is true
  1679. * - message: The invalid message
  1680. * @returns {Boolean}
  1681. */
  1682. validate: function(validator, $field, options) {
  1683. var value = $field.val();
  1684. if (value == '') {
  1685. return true;
  1686. }
  1687. value = parseFloat(value);
  1688. return (options.inclusive === false) ? (value <= options.value) : (value < options.value);
  1689. }
  1690. };
  1691. }(window.jQuery));
  1692. ;(function($) {
  1693. $.fn.bootstrapValidator.validators.mac = {
  1694. /**
  1695. * Return true if the input value is a MAC address.
  1696. *
  1697. * @param {BootstrapValidator} validator The validator plugin instance
  1698. * @param {jQuery} $field Field element
  1699. * @param {Object} options Can consist of the following keys:
  1700. * - message: The invalid message
  1701. * @returns {Boolean}
  1702. */
  1703. validate: function(validator, $field, options) {
  1704. var value = $field.val();
  1705. if (value == '') {
  1706. return true;
  1707. }
  1708. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  1709. }
  1710. };
  1711. }(window.jQuery));
  1712. ;(function($) {
  1713. $.fn.bootstrapValidator.validators.notEmpty = {
  1714. enableByHtml5: function($field) {
  1715. var required = $field.attr('required') + '';
  1716. return ('required' == required || 'true' == required);
  1717. },
  1718. /**
  1719. * Check if input value is empty or not
  1720. *
  1721. * @param {BootstrapValidator} validator The validator plugin instance
  1722. * @param {jQuery} $field Field element
  1723. * @param {Object} options
  1724. * @returns {Boolean}
  1725. */
  1726. validate: function(validator, $field, options) {
  1727. var type = $field.attr('type');
  1728. if ('radio' == type || 'checkbox' == type) {
  1729. return validator
  1730. .getFieldElements($field.attr('data-bv-field'))
  1731. .filter(':checked')
  1732. .length > 0;
  1733. }
  1734. return $.trim($field.val()) != '';
  1735. }
  1736. };
  1737. }(window.jQuery));
  1738. ;(function($) {
  1739. $.fn.bootstrapValidator.validators.numeric = {
  1740. /**
  1741. * Validate decimal number
  1742. *
  1743. * @param {BootstrapValidator} validator The validator plugin instance
  1744. * @param {jQuery} $field Field element
  1745. * @param {Object} options Consist of key:
  1746. * - message: The invalid message
  1747. * @returns {Boolean}
  1748. */
  1749. validate: function(validator, $field, options) {
  1750. var value = $field.val();
  1751. if (value == '') {
  1752. return true;
  1753. }
  1754. return !isNaN(parseFloat(value)) && isFinite(value);
  1755. }
  1756. };
  1757. }(window.jQuery));
  1758. ;(function($) {
  1759. $.fn.bootstrapValidator.validators.phone = {
  1760. html5Attributes: {
  1761. message: 'message',
  1762. country: 'country'
  1763. },
  1764. /**
  1765. * Return true if the input value contains a valid US phone number only
  1766. *
  1767. * @param {BootstrapValidator} validator Validate plugin instance
  1768. * @param {jQuery} $field Field element
  1769. * @param {Object} options Consist of key:
  1770. * - message: The invalid message
  1771. * - country: The ISO 3166 country code
  1772. * Currently it only supports United State (US) country
  1773. * @returns {Boolean}
  1774. */
  1775. validate: function(validator, $field, options) {
  1776. var value = $field.val();
  1777. if (value == '') {
  1778. return true;
  1779. }
  1780. var country = (options.country || 'US').toUpperCase();
  1781. switch (country) {
  1782. case 'US':
  1783. default:
  1784. // Make sure US phone numbers have 10 digits
  1785. // May start with 1, +1, or 1-; should discard
  1786. // Area code may be delimited with (), & sections may be delimited with . or -
  1787. // Test: http://regexr.com/38mqi
  1788. value = value.replace(/\D/g, '');
  1789. return (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
  1790. }
  1791. }
  1792. }
  1793. }(window.jQuery));
  1794. ;(function($) {
  1795. $.fn.bootstrapValidator.validators.regexp = {
  1796. html5Attributes: {
  1797. message: 'message',
  1798. regexp: 'regexp'
  1799. },
  1800. enableByHtml5: function($field) {
  1801. var pattern = $field.attr('pattern');
  1802. if (pattern) {
  1803. return {
  1804. regexp: pattern
  1805. };
  1806. }
  1807. return false;
  1808. },
  1809. /**
  1810. * Check if the element value matches given regular expression
  1811. *
  1812. * @param {BootstrapValidator} validator The validator plugin instance
  1813. * @param {jQuery} $field Field element
  1814. * @param {Object} options Consists of the following key:
  1815. * - regexp: The regular expression you need to check
  1816. * @returns {Boolean}
  1817. */
  1818. validate: function(validator, $field, options) {
  1819. var value = $field.val();
  1820. if (value == '') {
  1821. return true;
  1822. }
  1823. var regexp = ('string' == typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  1824. return regexp.test(value);
  1825. }
  1826. };
  1827. }(window.jQuery));
  1828. ;(function ($) {
  1829. $.fn.bootstrapValidator.validators.remote = {
  1830. html5Attributes: {
  1831. message: 'message',
  1832. url: 'url',
  1833. name: 'name'
  1834. },
  1835. /**
  1836. * Request a remote server to check the input value
  1837. *
  1838. * @param {BootstrapValidator} validator Plugin instance
  1839. * @param {jQuery} $field Field element
  1840. * @param {Object} options Can consist of the following keys:
  1841. * - url
  1842. * - data [optional]: By default, it will take the value
  1843. * {
  1844. * <fieldName>: <fieldValue>
  1845. * }
  1846. * - name [optional]: Override the field name for the request.
  1847. * - message: The invalid message
  1848. * @returns {Boolean|Deferred}
  1849. */
  1850. validate: function(validator, $field, options) {
  1851. var value = $field.val();
  1852. if (value == '') {
  1853. return true;
  1854. }
  1855. var name = $field.attr('data-bv-field'), data = options.data;
  1856. if (data == null) {
  1857. data = {};
  1858. }
  1859. // Support dynamic data
  1860. if ('function' == typeof data) {
  1861. data = data.call(this, validator);
  1862. }
  1863. data[options.name || name] = value;
  1864. var dfd = new $.Deferred();
  1865. var xhr = $.ajax({
  1866. type: 'POST',
  1867. url: options.url,
  1868. dataType: 'json',
  1869. data: data
  1870. });
  1871. xhr.then(function(response) {
  1872. dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true');
  1873. });
  1874. dfd.fail(function() {
  1875. xhr.abort();
  1876. });
  1877. return dfd;
  1878. }
  1879. };
  1880. }(window.jQuery));
  1881. ;(function($) {
  1882. $.fn.bootstrapValidator.validators.siren = {
  1883. /**
  1884. * Check if a string is a siren number
  1885. *
  1886. * @param {BootstrapValidator} validator The validator plugin instance
  1887. * @param {jQuery} $field Field element
  1888. * @param {Object} options Consist of key:
  1889. * - message: The invalid message
  1890. * @returns {Boolean}
  1891. */
  1892. validate: function(validator, $field, options) {
  1893. var value = $field.val();
  1894. if (value == '') {
  1895. return true;
  1896. }
  1897. if (!/^\d{9}$/.test(value)) {
  1898. return false;
  1899. }
  1900. return $.fn.bootstrapValidator.helpers.luhn(value);
  1901. }
  1902. };
  1903. }(window.jQuery));
  1904. ;(function($) {
  1905. $.fn.bootstrapValidator.validators.siret = {
  1906. /**
  1907. * Check if a string is a siret number
  1908. *
  1909. * @param {BootstrapValidator} validator The validator plugin instance
  1910. * @param {jQuery} $field Field element
  1911. * @param {Object} options Consist of key:
  1912. * - message: The invalid message
  1913. * @returns {Boolean}
  1914. */
  1915. validate: function(validator, $field, options) {
  1916. var value = $field.val();
  1917. if (value == '') {
  1918. return true;
  1919. }
  1920. var sum = 0,
  1921. length = value.length,
  1922. tmp;
  1923. for (var i = 0; i < length; i++) {
  1924. tmp = parseInt(value.charAt(i), 10);
  1925. if ((i % 2) == 0) {
  1926. tmp = tmp * 2;
  1927. if (tmp > 9) {
  1928. tmp -= 9;
  1929. }
  1930. }
  1931. sum += tmp;
  1932. }
  1933. return (sum % 10 == 0);
  1934. }
  1935. };
  1936. }(window.jQuery));
  1937. ;(function($) {
  1938. $.fn.bootstrapValidator.validators.step = {
  1939. html5Attributes: {
  1940. message: 'message',
  1941. base: 'baseValue',
  1942. step: 'step'
  1943. },
  1944. /**
  1945. * Return true if the input value is valid step one
  1946. *
  1947. * @param {BootstrapValidator} validator The validator plugin instance
  1948. * @param {jQuery} $field Field element
  1949. * @param {Object} options Can consist of the following keys:
  1950. * - baseValue: The base value
  1951. * - step: The step
  1952. * - message: The invalid message
  1953. * @returns {Boolean}
  1954. */
  1955. validate: function(validator, $field, options) {
  1956. var value = $field.val();
  1957. if (value == '') {
  1958. return true;
  1959. }
  1960. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  1961. value = parseFloat(value);
  1962. if (isNaN(value) || !isFinite(value)) {
  1963. return false;
  1964. }
  1965. var round = function(x, precision) {
  1966. var m = Math.pow(10, precision);
  1967. x = x * m;
  1968. var sign = (x > 0) | -(x < 0),
  1969. isHalf = (x % 1 === 0.5 * sign);
  1970. if (isHalf) {
  1971. return (Math.floor(x) + (sign > 0)) / m;
  1972. } else {
  1973. return Math.round(x) / m;
  1974. }
  1975. },
  1976. floatMod = function(x, y) {
  1977. if (y == 0.0) {
  1978. return 1.0;
  1979. }
  1980. var dotX = (x + '').split('.'),
  1981. dotY = (y + '').split('.'),
  1982. precision = ((dotX.length == 1) ? 0 : dotX[1].length) + ((dotY.length == 1) ? 0 : dotY[1].length);
  1983. return round(x - y * Math.floor(x / y), precision);
  1984. };
  1985. var mod = floatMod(value - options.baseValue, options.step);
  1986. return (mod == 0.0 || mod == options.step);
  1987. }
  1988. };
  1989. }(window.jQuery));
  1990. ;(function($) {
  1991. $.fn.bootstrapValidator.validators.stringCase = {
  1992. html5Attributes: {
  1993. message: 'message',
  1994. 'case': 'case'
  1995. },
  1996. /**
  1997. * Check if a string is a lower or upper case one
  1998. *
  1999. * @param {BootstrapValidator} validator The validator plugin instance
  2000. * @param {jQuery} $field Field element
  2001. * @param {Object} options Consist of key:
  2002. * - message: The invalid message
  2003. * - case: Can be 'lower' (default) or 'upper'
  2004. * @returns {Boolean}
  2005. */
  2006. validate: function(validator, $field, options) {
  2007. var value = $field.val();
  2008. if (value == '') {
  2009. return true;
  2010. }
  2011. var stringCase = (options['case'] || 'lower').toLowerCase();
  2012. switch (stringCase) {
  2013. case 'upper':
  2014. return value === value.toUpperCase();
  2015. case 'lower':
  2016. default:
  2017. return value === value.toLowerCase();
  2018. }
  2019. }
  2020. };
  2021. }(window.jQuery));
  2022. ;(function($) {
  2023. $.fn.bootstrapValidator.validators.stringLength = {
  2024. html5Attributes: {
  2025. message: 'message',
  2026. min: 'min',
  2027. max: 'max'
  2028. },
  2029. enableByHtml5: function($field) {
  2030. var maxLength = $field.attr('maxlength');
  2031. if (maxLength) {
  2032. return {
  2033. max: parseInt(maxLength, 10)
  2034. };
  2035. }
  2036. return false;
  2037. },
  2038. /**
  2039. * Check if the length of element value is less or more than given number
  2040. *
  2041. * @param {BootstrapValidator} validator The validator plugin instance
  2042. * @param {jQuery} $field Field element
  2043. * @param {Object} options Consists of following keys:
  2044. * - min
  2045. * - max
  2046. * At least one of two keys is required
  2047. * - message: The invalid message
  2048. * @returns {Boolean}
  2049. */
  2050. validate: function(validator, $field, options) {
  2051. var value = $field.val();
  2052. if (value == '') {
  2053. return true;
  2054. }
  2055. var length = $.trim(value).length;
  2056. if ((options.min && length < options.min) || (options.max && length > options.max)) {
  2057. return false;
  2058. }
  2059. return true;
  2060. }
  2061. };
  2062. }(window.jQuery));
  2063. ;(function($) {
  2064. $.fn.bootstrapValidator.validators.uri = {
  2065. enableByHtml5: function($field) {
  2066. return ('url' == $field.attr('type'));
  2067. },
  2068. /**
  2069. * Return true if the input value is a valid URL
  2070. *
  2071. * @param {BootstrapValidator} validator The validator plugin instance
  2072. * @param {jQuery} $field Field element
  2073. * @param {Object} options
  2074. * @returns {Boolean}
  2075. */
  2076. validate: function(validator, $field, options) {
  2077. var value = $field.val();
  2078. if (value == '') {
  2079. return true;
  2080. }
  2081. // Credit to https://gist.github.com/dperini/729294
  2082. //
  2083. // Regular Expression for URL validation
  2084. //
  2085. // Author: Diego Perini
  2086. // Updated: 2010/12/05
  2087. //
  2088. // the regular expression composed & commented
  2089. // could be easily tweaked for RFC compliance,
  2090. // it was expressly modified to fit & satisfy
  2091. // these test for an URL shortener:
  2092. //
  2093. // http://mathiasbynens.be/demo/url-regex
  2094. //
  2095. // Notes on possible differences from a standard/generic validation:
  2096. //
  2097. // - utf-8 char class take in consideration the full Unicode range
  2098. // - TLDs have been made mandatory so single names like "localhost" fails
  2099. // - protocols have been restricted to ftp, http and https only as requested
  2100. //
  2101. // Changes:
  2102. //
  2103. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  2104. // first and last IP address of each class is considered invalid
  2105. // (since they are broadcast/network addresses)
  2106. //
  2107. // - Added exclusion of private, reserved and/or local networks ranges
  2108. //
  2109. // Compressed one-line versions:
  2110. //
  2111. // Javascript version
  2112. //
  2113. // /^(?:(?: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
  2114. //
  2115. // PHP version
  2116. //
  2117. // _^(?:(?: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
  2118. var urlExp = new RegExp(
  2119. "^" +
  2120. // protocol identifier
  2121. "(?:(?:https?|ftp)://)" +
  2122. // user:pass authentication
  2123. "(?:\\S+(?::\\S*)?@)?" +
  2124. "(?:" +
  2125. // IP address exclusion
  2126. // private & local networks
  2127. "(?!10(?:\\.\\d{1,3}){3})" +
  2128. "(?!127(?:\\.\\d{1,3}){3})" +
  2129. "(?!169\\.254(?:\\.\\d{1,3}){2})" +
  2130. "(?!192\\.168(?:\\.\\d{1,3}){2})" +
  2131. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
  2132. // IP address dotted notation octets
  2133. // excludes loopback network 0.0.0.0
  2134. // excludes reserved space >= 224.0.0.0
  2135. // excludes network & broacast addresses
  2136. // (first & last IP address of each class)
  2137. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  2138. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  2139. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  2140. "|" +
  2141. // host name
  2142. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  2143. // domain name
  2144. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  2145. // TLD identifier
  2146. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  2147. ")" +
  2148. // port number
  2149. "(?::\\d{2,5})?" +
  2150. // resource path
  2151. "(?:/[^\\s]*)?" +
  2152. "$", "i"
  2153. );
  2154. return urlExp.test(value);
  2155. }
  2156. };
  2157. }(window.jQuery));
  2158. ;(function($) {
  2159. $.fn.bootstrapValidator.validators.uuid = {
  2160. html5Attributes: {
  2161. message: 'message',
  2162. version: 'version'
  2163. },
  2164. /**
  2165. * Return true if and only if the input value is a valid UUID string
  2166. *
  2167. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  2168. * @param {BootstrapValidator} validator The validator plugin instance
  2169. * @param {jQuery} $field Field element
  2170. * @param {Object} options Consist of key:
  2171. * - message: The invalid message
  2172. * - version: Can be 3, 4, 5, null
  2173. * @returns {Boolean}
  2174. */
  2175. validate: function(validator, $field, options) {
  2176. var value = $field.val();
  2177. if (value == '') {
  2178. return true;
  2179. }
  2180. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  2181. var patterns = {
  2182. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  2183. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2184. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2185. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  2186. },
  2187. version = options.version ? (options.version + '') : 'all';
  2188. return (null == patterns[version]) ? true : patterns[version].test(value);
  2189. }
  2190. };
  2191. }(window.jQuery));
  2192. ;(function($) {
  2193. $.fn.bootstrapValidator.validators.vat = {
  2194. html5Attributes: {
  2195. message: 'message',
  2196. country: 'country'
  2197. },
  2198. /**
  2199. * Validate an European VAT number
  2200. *
  2201. * @param {BootstrapValidator} validator The validator plugin instance
  2202. * @param {jQuery} $field Field element
  2203. * @param {Object} options Consist of key:
  2204. * - message: The invalid message
  2205. * - country: The ISO 3166-1 country code
  2206. * @returns {Boolean}
  2207. */
  2208. validate: function(validator, $field, options) {
  2209. var value = $field.val();
  2210. if (value == '') {
  2211. return true;
  2212. }
  2213. var country = options.country || value.substr(0, 2),
  2214. method = ['_', country.toLowerCase()].join('');
  2215. if (this[method] && 'function' == typeof this[method]) {
  2216. return this[method](value);
  2217. }
  2218. return true;
  2219. },
  2220. // VAT validators
  2221. /**
  2222. * Validate Austrian VAT number
  2223. * Example:
  2224. * - Valid: ATU13585627
  2225. * - Invalid: ATU13585626
  2226. *
  2227. * @param {String} value VAT number
  2228. * @returns {Boolean}
  2229. */
  2230. _at: function(value) {
  2231. if (!/^ATU[0-9]{8}$/.test(value)) {
  2232. return false;
  2233. }
  2234. value = value.substr(3);
  2235. var sum = 0,
  2236. weight = [1, 2, 1, 2, 1, 2, 1],
  2237. temp = 0;
  2238. for (var i = 0; i < 7; i++) {
  2239. temp = parseInt(value.charAt(i)) * weight[i];
  2240. if (temp > 9) {
  2241. temp = Math.floor(temp / 10) + temp % 10;
  2242. }
  2243. sum += temp;
  2244. }
  2245. sum = 10 - (sum + 4) % 10;
  2246. if (sum == 10) {
  2247. sum = 0;
  2248. }
  2249. return (sum == value.substr(7, 1));
  2250. },
  2251. /**
  2252. * Validate Belgian VAT number
  2253. * Example:
  2254. * - Valid: BE0428759497
  2255. * - Invalid: BE431150351
  2256. *
  2257. * @param {String} value VAT number
  2258. * @returns {Boolean}
  2259. */
  2260. _be: function(value) {
  2261. if (!/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  2262. return false;
  2263. }
  2264. value = value.substr(2);
  2265. if (value.length == 9) {
  2266. value = '0' + value;
  2267. }
  2268. if (value.substr(1, 1) == 0) {
  2269. return false;
  2270. }
  2271. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  2272. return (sum % 97 == 0);
  2273. },
  2274. /**
  2275. * Validate Bulgarian VAT number
  2276. * Example:
  2277. * - Valid: BG175074752,
  2278. * BG7523169263, BG8032056031,
  2279. * BG7542011030,
  2280. * BG7111042925
  2281. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  2282. *
  2283. * @param {String} value VAT number
  2284. * @returns {Boolean}
  2285. */
  2286. _bg: function(value) {
  2287. if (!/^BG[0-9]{9,10}$/.test(value)) {
  2288. return false;
  2289. }
  2290. value = value.substr(2);
  2291. var total = 0, sum = 0, weight = [], i = 0;
  2292. // Legal entities
  2293. if (value.length == 9) {
  2294. for (i = 0; i < 8; i++) {
  2295. sum += parseInt(value.charAt(i)) * (i + 1);
  2296. }
  2297. sum = sum % 11;
  2298. if (sum == 10) {
  2299. sum = 0;
  2300. for (i = 0; i < 8; i++) {
  2301. sum += parseInt(value.charAt(i)) * (i + 3);
  2302. }
  2303. }
  2304. sum = sum % 10;
  2305. return (sum == value.substr(8));
  2306. }
  2307. // Physical persons, foreigners and others
  2308. else if (value.length == 10) {
  2309. // Validate Bulgarian national identification numbers
  2310. var egn = function(value) {
  2311. // Check the birth date
  2312. var year = parseInt(value.substr(0, 2), 10) + 1900,
  2313. month = parseInt(value.substr(2, 2), 10),
  2314. day = parseInt(value.substr(4, 2), 10);
  2315. if (month > 40) {
  2316. year += 100;
  2317. month -= 40;
  2318. } else if (month > 20) {
  2319. year -= 100;
  2320. month -= 20;
  2321. }
  2322. try {
  2323. var d = new Date(year, month, day);
  2324. } catch (ex) {
  2325. return false;
  2326. }
  2327. var sum = 0,
  2328. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2329. for (var i = 0; i < 9; i++) {
  2330. sum += parseInt(value.charAt(i)) * weight[i];
  2331. }
  2332. sum = (sum % 11) % 10;
  2333. return (sum == value.substr(9, 1));
  2334. },
  2335. // Validate Bulgarian personal number of a foreigner
  2336. pnf = function(value) {
  2337. var sum = 0,
  2338. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  2339. for (var i = 0; i < 9; i++) {
  2340. sum += parseInt(value.charAt(i)) * weight[i];
  2341. }
  2342. sum = sum % 10;
  2343. return (sum == value.substr(9, 1));
  2344. },
  2345. // Finally, consider it as a VAT number
  2346. vat = function(value) {
  2347. var sum = 0,
  2348. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  2349. for (var i = 0; i < 9; i++) {
  2350. sum += parseInt(value.charAt(i)) * weight[i];
  2351. }
  2352. sum = 11 - sum % 11;
  2353. if (sum == 10) {
  2354. return false;
  2355. }
  2356. if (sum == 11) {
  2357. sum = 0;
  2358. }
  2359. return (sum == value.substr(9, 1));
  2360. };
  2361. return (egn(value) || pnf(value) || vat(value));
  2362. }
  2363. return false;
  2364. },
  2365. /**
  2366. * Validate Swiss VAT number
  2367. *
  2368. * @param {String} value VAT number
  2369. * @returns {Boolean}
  2370. */
  2371. _ch: function(value) {
  2372. if (!/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  2373. return false;
  2374. }
  2375. value = value.substr(3);
  2376. var sum = 0,
  2377. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  2378. for (var i = 0; i < 8; i++) {
  2379. sum += parseInt(value.charAt(i), 10) * weight[i];
  2380. }
  2381. sum = 11 - sum % 11;
  2382. if (sum == 10) {
  2383. return false;
  2384. }
  2385. if (sum == 11) {
  2386. sum = 0;
  2387. }
  2388. return (sum == value.substr(8, 1));
  2389. },
  2390. /**
  2391. * Validate Cypriot VAT number
  2392. * Examples:
  2393. * - Valid: CY10259033P
  2394. * - Invalid: CY10259033Z
  2395. *
  2396. * @param {String} value VAT number
  2397. * @returns {Boolean}
  2398. */
  2399. _cy: function(value) {
  2400. if (!/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  2401. return false;
  2402. }
  2403. value = value.substr(2);
  2404. // Do not allow to start with "12"
  2405. if (value.substr(0, 2) == '12') {
  2406. return false;
  2407. }
  2408. // Extract the next digit and multiply by the counter.
  2409. var sum = 0,
  2410. translation = {
  2411. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  2412. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  2413. };
  2414. for (var i = 0; i < 8; i++) {
  2415. var temp = parseInt(value.charAt(i), 10);
  2416. if (i % 2 == 0) {
  2417. temp = translation[temp + ''];
  2418. }
  2419. sum += temp;
  2420. }
  2421. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  2422. return (sum == value.substr(8, 1));
  2423. },
  2424. /**
  2425. * Validate Czech Republic VAT number
  2426. * Can be:
  2427. * i) Legal entities (8 digit numbers)
  2428. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  2429. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  2430. *
  2431. * Examples:
  2432. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  2433. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  2434. *
  2435. * @param {String} value VAT number
  2436. * @returns {Boolean}
  2437. */
  2438. _cz: function(value) {
  2439. if (!/^CZ[0-9]{8,10}$/.test(value)) {
  2440. return false;
  2441. }
  2442. value = value.substr(2);
  2443. var sum = 0,
  2444. i = 0;
  2445. if (value.length == 8) {
  2446. // Do not allow to start with '9'
  2447. if (value.charAt(0) + '' == '9') {
  2448. return false;
  2449. }
  2450. sum = 0;
  2451. for (i = 0; i < 7; i++) {
  2452. sum += parseInt(value.charAt(i), 10) * (8 - i);
  2453. }
  2454. sum = 11 - sum % 11;
  2455. if (sum == 10) {
  2456. sum = 0;
  2457. }
  2458. if (sum == 11) {
  2459. sum = 1;
  2460. }
  2461. return (sum == value.substr(7, 1));
  2462. } else if (value.length == 9 && (value.charAt(0) + '' == '6')) {
  2463. sum = 0;
  2464. // Skip the first (which is 6)
  2465. for (i = 0; i < 7; i++) {
  2466. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  2467. }
  2468. sum = 11 - sum % 11;
  2469. if (sum == 10) {
  2470. sum = 0;
  2471. }
  2472. if (sum == 11) {
  2473. sum = 1;
  2474. }
  2475. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  2476. return (sum == value.substr(8, 1));
  2477. } else if (value.length == 9 || value.length == 10) {
  2478. // Validate Czech birth number (Rodné číslo), which is also national identifier
  2479. var year = 1900 + parseInt(value.substr(0, 2)),
  2480. month = parseInt(value.substr(2, 2)) % 50 % 20,
  2481. day = parseInt(value.substr(4, 2));
  2482. if (value.length == 9) {
  2483. if (year >= 1980) {
  2484. year -= 100;
  2485. }
  2486. if (year > 1953) {
  2487. return false;
  2488. }
  2489. } else if (year < 1954) {
  2490. year += 100;
  2491. }
  2492. try {
  2493. var d = new Date(year, month, day);
  2494. } catch (ex) {
  2495. return false;
  2496. }
  2497. // Check that the birth date is not in the future
  2498. if (value.length == 10) {
  2499. var check = parseInt(value.substr(0, 9), 10) % 11;
  2500. if (year < 1985) {
  2501. check = check % 10;
  2502. }
  2503. return (check == value.substr(9, 1));
  2504. }
  2505. return true;
  2506. }
  2507. return false;
  2508. },
  2509. /**
  2510. * Validate German VAT number
  2511. * Examples:
  2512. * - Valid: DE136695976
  2513. * - Invalid: DE136695978
  2514. *
  2515. * @param {String} value VAT number
  2516. * @returns {Boolean}
  2517. */
  2518. _de: function(value) {
  2519. if (!/^DE[0-9]{9}$/.test(value)) {
  2520. return false;
  2521. }
  2522. value = value.substr(2);
  2523. var product = 10,
  2524. sum = 0;
  2525. for (var i = 0; i < 8; i++) {
  2526. sum = (parseInt(value.charAt(i), 10) + product) % 10;
  2527. if (sum == 0) {
  2528. sum = 10;
  2529. }
  2530. product = (sum * 2) % 11;
  2531. }
  2532. var checkDigit = (11 - product == 10) ? 0 : (11 - product);
  2533. return (checkDigit == value.substr(8, 1));
  2534. },
  2535. /**
  2536. * Validate Danish VAT number
  2537. * Example:
  2538. * - Valid: DK13585628
  2539. * - Invalid: DK13585627
  2540. *
  2541. * @param {String} value VAT number
  2542. * @returns {Boolean}
  2543. */
  2544. _dk: function(value) {
  2545. if (!/^DK[0-9]{8}$/.test(value)) {
  2546. return false;
  2547. }
  2548. value = value.substr(2);
  2549. var sum = 0,
  2550. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  2551. for (var i = 0; i < 8; i++) {
  2552. sum += parseInt(value.charAt(i), 10) * weight[i];
  2553. }
  2554. return (sum % 11 == 0);
  2555. },
  2556. /**
  2557. * Validate Estonian VAT number
  2558. * Examples:
  2559. * - Valid: EE100931558, EE100594102
  2560. * - Invalid: EE100594103
  2561. *
  2562. * @param {String} value VAT number
  2563. * @returns {Boolean}
  2564. */
  2565. _ee: function(value) {
  2566. if (!/^EE[0-9]{9}$/.test(value)) {
  2567. return false;
  2568. }
  2569. value = value.substr(2);
  2570. var sum = 0,
  2571. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  2572. for (var i = 0; i < 9; i++) {
  2573. sum += parseInt(value.charAt(i)) * weight[i];
  2574. }
  2575. return (sum % 10 == 0);
  2576. },
  2577. /**
  2578. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  2579. * Can be:
  2580. * i) DNI (Documento nacional de identidad), for Spaniards
  2581. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  2582. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  2583. *
  2584. * Examples:
  2585. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  2586. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  2587. *
  2588. * @param {String} value VAT number
  2589. * @returns {Boolean}
  2590. */
  2591. _es: function(value) {
  2592. if (!/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  2593. return false;
  2594. }
  2595. value = value.substr(2);
  2596. var dni = function(value) {
  2597. var check = parseInt(value.substr(0, 8), 10);
  2598. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  2599. return (check == value.substr(8, 1));
  2600. },
  2601. nie = function(value) {
  2602. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  2603. check = parseInt(check, 10);
  2604. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  2605. return (check == value.substr(8, 1));
  2606. },
  2607. cif = function(value) {
  2608. var first = value.charAt(0), check;
  2609. if ('KLM'.indexOf(first) != -1) {
  2610. // K: Spanish younger than 14 year old
  2611. // L: Spanish living outside Spain without DNI
  2612. // M: Granted the tax to foreigners who have no NIE
  2613. check = parseInt(value.substr(1, 8), 10);
  2614. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  2615. return (check == value.substr(8, 1));
  2616. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) != -1) {
  2617. var sum = 0,
  2618. weight = [2, 1, 2, 1, 2, 1, 2],
  2619. temp = 0;
  2620. for (var i = 0; i < 7; i++) {
  2621. temp = parseInt(value.charAt(i + 1)) * weight[i];
  2622. if (temp > 9) {
  2623. temp = Math.floor(temp / 10) + temp % 10;
  2624. }
  2625. sum += temp;
  2626. }
  2627. sum = 10 - sum % 10;
  2628. return (sum == value.substr(8, 1) || 'JABCDEFGHI'[sum] == value.substr(8, 1));
  2629. }
  2630. return false;
  2631. };
  2632. var first = value.charAt(0);
  2633. if (/^[0-9]$/.test(first)) {
  2634. return dni(value);
  2635. } else if (/^[XYZ]$/.test(first)) {
  2636. return nie(value);
  2637. } else {
  2638. return cif(value);
  2639. }
  2640. },
  2641. /**
  2642. * Validate Finnish VAT number
  2643. * Examples:
  2644. * - Valid: FI20774740
  2645. * - Invalid: FI20774741
  2646. *
  2647. * @param {String} value VAT number
  2648. * @returns {Boolean}
  2649. */
  2650. _fi: function(value) {
  2651. if (!/^FI[0-9]{8}$/.test(value)) {
  2652. return false;
  2653. }
  2654. value = value.substr(2);
  2655. var sum = 0,
  2656. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  2657. for (var i = 0; i < 8; i++) {
  2658. sum += parseInt(value.charAt(i)) * weight[i];
  2659. }
  2660. return (sum % 11 == 0);
  2661. },
  2662. /**
  2663. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  2664. * It's constructed by a SIREN number, prefixed by two characters.
  2665. *
  2666. * Examples:
  2667. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  2668. * - Invalid: FR84323140391
  2669. *
  2670. * @param {String} value VAT number
  2671. * @returns {Boolean}
  2672. */
  2673. _fr: function(value) {
  2674. if (!/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  2675. return false;
  2676. }
  2677. value = value.substr(2);
  2678. if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
  2679. return false;
  2680. }
  2681. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  2682. // First two characters are digits
  2683. return value.substr(0, 2) == (parseInt(value.substr(2) + '12', 10) % 97);
  2684. } else {
  2685. // The first characters cann't be O and I
  2686. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  2687. check;
  2688. // First one is digit
  2689. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  2690. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  2691. } else {
  2692. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  2693. }
  2694. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) == (check % 11);
  2695. }
  2696. },
  2697. /**
  2698. * Validate United Kingdom VAT number
  2699. * Example:
  2700. * - Valid: GB980780684
  2701. * - Invalid: GB802311781
  2702. *
  2703. * @param {String} value VAT number
  2704. * @returns {Boolean}
  2705. */
  2706. _gb: function(value) {
  2707. if (!/^GB[0-9]{9}$/.test(value) // Standard
  2708. && !/^GB[0-9]{12}$/.test(value) // Branches
  2709. && !/^GBGD[0-9]{3}$/.test(value) // Government department
  2710. && !/^GBHA[0-9]{3}$/.test(value) // Health authority
  2711. && !/^GB(GD|HA)8888[0-9]{5}$/.test(value))
  2712. {
  2713. return false;
  2714. }
  2715. value = value.substr(2);
  2716. var length = value.length;
  2717. if (length == 5) {
  2718. var firstTwo = value.substr(0, 2),
  2719. lastThree = parseInt(value.substr(2));
  2720. return ('GD' == firstTwo && lastThree < 500) || ('HA' == firstTwo && lastThree >= 500);
  2721. } else if (length == 11 && ('GD8888' == value.substr(0, 6) || 'HA8888' == value.substr(0, 6))) {
  2722. if (('GD' == value.substr(0, 2) && parseInt(value.substr(6, 3)) >= 500)
  2723. || ('HA' == value.substr(0, 2) && parseInt(value.substr(6, 3)) < 500))
  2724. {
  2725. return false;
  2726. }
  2727. return (parseInt(value.substr(6, 3)) % 97 == parseInt(value.substr(9, 2)));
  2728. } else if (length == 9 || length == 12) {
  2729. var sum = 0,
  2730. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  2731. for (var i = 0; i < 9; i++) {
  2732. sum += parseInt(value.charAt(i)) * weight[i];
  2733. }
  2734. sum = sum % 97;
  2735. if (parseInt(value.substr(0, 3)) >= 100) {
  2736. return (sum == 0 || sum == 42 || sum == 55);
  2737. } else {
  2738. return (sum == 0);
  2739. }
  2740. }
  2741. return true;
  2742. },
  2743. /**
  2744. * Validate Greek VAT number
  2745. * Examples:
  2746. * - Valid: GR023456780, EL094259216
  2747. * - Invalid: EL123456781
  2748. *
  2749. * @param {String} value VAT number
  2750. * @returns {Boolean}
  2751. */
  2752. _gr: function(value) {
  2753. if (!/^GR[0-9]{9}$/.test(value)) {
  2754. return false;
  2755. }
  2756. value = value.substr(2);
  2757. if (value.length == 8) {
  2758. value = '0' + value;
  2759. }
  2760. var sum = 0,
  2761. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  2762. for (var i = 0; i < 8; i++) {
  2763. sum += parseInt(value.charAt(i)) * weight[i];
  2764. }
  2765. sum = (sum % 11) % 10;
  2766. return (sum == value.substr(8, 1));
  2767. },
  2768. // EL is traditionally prefix of Greek VAT numbers
  2769. _el: function(value) {
  2770. if (!/^EL[0-9]{9}$/.test(value)) {
  2771. return false;
  2772. }
  2773. value = 'GR' + value.substr(2);
  2774. return this._gr(value);
  2775. },
  2776. /**
  2777. * Validate Hungarian VAT number
  2778. * Examples:
  2779. * - Valid: HU12892312
  2780. * - Invalid: HU12892313
  2781. *
  2782. * @param {String} value VAT number
  2783. * @returns {Boolean}
  2784. */
  2785. _hu: function(value) {
  2786. if (!/^HU[0-9]{8}$/.test(value)) {
  2787. return false;
  2788. }
  2789. value = value.substr(2);
  2790. var sum = 0,
  2791. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  2792. for (var i = 0; i < 8; i++) {
  2793. sum += parseInt(value.charAt(i)) * weight[i];
  2794. }
  2795. return (sum % 10 == 0);
  2796. },
  2797. /**
  2798. * Validate Croatian VAT number
  2799. * Examples:
  2800. * - Valid: HR33392005961
  2801. * - Invalid: HR33392005962
  2802. *
  2803. * @param {String} value VAT number
  2804. * @returns {Boolean}
  2805. */
  2806. _hr: function(value) {
  2807. if (!/^HR[0-9]{11}$/.test(value)) {
  2808. return false;
  2809. }
  2810. value = value.substr(2);
  2811. var sum = 10,
  2812. temp = 0;
  2813. for (var i = 0; i < 10; i++) {
  2814. temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  2815. if (temp == 0) {
  2816. temp = 10;
  2817. }
  2818. sum = (temp * 2) % 11;
  2819. }
  2820. sum += parseInt(value.substr(10, 1), 10);
  2821. return (sum % 10 == 1);
  2822. },
  2823. /**
  2824. * Validate Irish VAT number
  2825. * Examples:
  2826. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  2827. * - Invalid: IE8D79738J
  2828. *
  2829. * @param {String} value VAT number
  2830. * @returns {Boolean}
  2831. */
  2832. _ie: function(value) {
  2833. if (!/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  2834. return false;
  2835. }
  2836. value = value.substr(2);
  2837. var getCheckDigit = function(value) {
  2838. while (value.length < 7) {
  2839. value = '0' + value;
  2840. }
  2841. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  2842. sum = 0;
  2843. for (var i = 0; i < 7; i++) {
  2844. sum += parseInt(value.charAt(i)) * (8 - i);
  2845. }
  2846. sum += 9 * alphabet.indexOf(value.substr(7));
  2847. return alphabet[sum % 23];
  2848. };
  2849. // The first 7 characters are digits
  2850. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  2851. // New system
  2852. return value.charAt(7) == getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  2853. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) != -1) {
  2854. // Old system
  2855. return value.charAt(7) == getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  2856. }
  2857. return true;
  2858. },
  2859. /**
  2860. * Validate Italian VAT number, which consists of 11 digits.
  2861. * - First 7 digits are a company identifier
  2862. * - Next 3 are the province of residence
  2863. * - The last one is a check digit
  2864. *
  2865. * Examples:
  2866. * - Valid: IT00743110157
  2867. * - Invalid: IT00743110158
  2868. *
  2869. * @param {String} value VAT number
  2870. * @returns {Boolean}
  2871. */
  2872. _it: function(value) {
  2873. if (!/^IT[0-9]{11}$/.test(value)) {
  2874. return false;
  2875. }
  2876. value = value.substr(2);
  2877. if (parseInt(value.substr(0, 7)) == 0) {
  2878. return false;
  2879. }
  2880. var lastThree = parseInt(value.substr(7, 3));
  2881. if ((lastThree < 1) || (lastThree > 201) && lastThree != 999 && lastThree != 888) {
  2882. return false;
  2883. }
  2884. return $.fn.bootstrapValidator.helpers.luhn(value);
  2885. },
  2886. /**
  2887. * Validate Lithuanian VAT number
  2888. * It can be:
  2889. * - 9 digits, for legal entities
  2890. * - 12 digits, for temporarily registered taxpayers
  2891. *
  2892. * Examples:
  2893. * - Valid: LT119511515, LT100001919017, LT100004801610
  2894. * - Invalid: LT100001919018
  2895. *
  2896. * @param {String} value VAT number
  2897. * @returns {Boolean}
  2898. */
  2899. _lt: function(value) {
  2900. if (!/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  2901. return false;
  2902. }
  2903. value = value.substr(2);
  2904. var length = value.length,
  2905. sum = 0;
  2906. for (var i = 0; i < length - 1; i++) {
  2907. sum += parseInt(value.charAt(i)) * (1 + i % 9);
  2908. }
  2909. var check = sum % 11;
  2910. if (check == 10) {
  2911. sum = 0;
  2912. for (var i = 0; i < length - 1; i++) {
  2913. sum += parseInt(value.charAt(i)) * (1 + (i + 2) % 9);
  2914. }
  2915. }
  2916. check = check % 11 % 10;
  2917. return (check == value.charAt(length - 1));
  2918. },
  2919. /**
  2920. * Validate Luxembourg VAT number
  2921. * Examples:
  2922. * - Valid: LU15027442
  2923. * - Invalid: LU15027443
  2924. *
  2925. * @param {String} value VAT number
  2926. * @returns {Boolean}
  2927. */
  2928. _lu: function(value) {
  2929. if (!/^LU[0-9]{8}$/.test(value)) {
  2930. return false;
  2931. }
  2932. value = value.substr(2);
  2933. return (value.substr(0, 6) % 89 == value.substr(6, 2));
  2934. },
  2935. /**
  2936. * Validate Latvian VAT number
  2937. * Examples:
  2938. * - Valid: LV40003521600, LV16117519997
  2939. * - Invalid: LV40003521601, LV16137519997
  2940. *
  2941. * @param {String} value VAT number
  2942. * @returns {Boolean}
  2943. */
  2944. _lv: function(value) {
  2945. if (!/^LV[0-9]{11}$/.test(value)) {
  2946. return false;
  2947. }
  2948. value = value.substr(2);
  2949. var first = parseInt(value.charAt(0)),
  2950. sum = 0,
  2951. weight = [],
  2952. i = 0,
  2953. length = value.length;
  2954. if (first > 3) {
  2955. // Legal entity
  2956. sum = 0;
  2957. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  2958. for (i = 0; i < length; i++) {
  2959. sum += parseInt(value.charAt(i)) * weight[i];
  2960. }
  2961. sum = sum % 11;
  2962. return (sum == 3);
  2963. } else {
  2964. // Check birth date
  2965. var day = parseInt(value.substr(0, 2)),
  2966. month = parseInt(value.substr(2, 2)),
  2967. year = parseInt(value.substr(4, 2));
  2968. year = year + 1800 + parseInt(value.charAt(6)) * 100;
  2969. try {
  2970. var d = new Date(year, month, day);
  2971. } catch (ex) {
  2972. return false;
  2973. }
  2974. // Check personal code
  2975. sum = 0;
  2976. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  2977. for (i = 0; i < length - 1; i++) {
  2978. sum += parseInt(value.charAt(i)) * weight[i];
  2979. }
  2980. sum = (sum + 1) % 11 % 10;
  2981. return (sum == value.charAt(length - 1));
  2982. }
  2983. return true;
  2984. },
  2985. /**
  2986. * Validate Maltese VAT number
  2987. * Examples:
  2988. * - Valid: MT11679112
  2989. * - Invalid: MT11679113
  2990. *
  2991. * @param {String} value VAT number
  2992. * @returns {Boolean}
  2993. */
  2994. _mt: function(value) {
  2995. if (!/^MT[0-9]{8}$/.test(value)) {
  2996. return false;
  2997. }
  2998. value = value.substr(2);
  2999. var sum = 0,
  3000. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  3001. for (var i = 0; i < 8; i++) {
  3002. sum += parseInt(value.charAt(i)) * weight[i];
  3003. }
  3004. return (sum % 37 == 0);
  3005. },
  3006. /**
  3007. * Validate Dutch VAT number
  3008. * Examples:
  3009. * - Valid: NL004495445B01
  3010. * - Invalid: NL123456789B90
  3011. *
  3012. * @param {String} value VAT number
  3013. * @returns {Boolean}
  3014. */
  3015. _nl: function(value) {
  3016. if (!/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  3017. return false;
  3018. }
  3019. value = value.substr(2);
  3020. var sum = 0,
  3021. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  3022. for (var i = 0; i < 8; i++) {
  3023. sum += parseInt(value.charAt(i)) * weight[i];
  3024. }
  3025. sum = sum % 11;
  3026. if (sum > 9) {
  3027. sum = 0;
  3028. }
  3029. return (sum == value.substr(8, 1));
  3030. },
  3031. /**
  3032. * Validate Norwegian VAT number
  3033. *
  3034. * @see http://www.brreg.no/english/coordination/number.html
  3035. * @param {String} value VAT number
  3036. * @returns {Boolean}
  3037. */
  3038. _no: function(value) {
  3039. if (!/^NO[0-9]{9}$/.test(value)) {
  3040. return false;
  3041. }
  3042. value = value.substr(2);
  3043. var sum = 0,
  3044. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  3045. for (var i = 0; i < 8; i++) {
  3046. sum += parseInt(value.charAt(i)) * weight[i];
  3047. }
  3048. sum = 11 - sum % 11;
  3049. if (sum == 11) {
  3050. sum = 0;
  3051. }
  3052. return (sum == value.substr(8, 1));
  3053. },
  3054. /**
  3055. * Validate Polish VAT number
  3056. * Examples:
  3057. * - Valid: PL8567346215
  3058. * - Invalid: PL8567346216
  3059. *
  3060. * @param {String} value VAT number
  3061. * @returns {Boolean}
  3062. */
  3063. _pl: function(value) {
  3064. if (!/^PL[0-9]{10}$/.test(value)) {
  3065. return false;
  3066. }
  3067. value = value.substr(2);
  3068. var sum = 0,
  3069. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  3070. for (var i = 0; i < 10; i++) {
  3071. sum += parseInt(value.charAt(i)) * weight[i];
  3072. }
  3073. return (sum % 11 == 0);
  3074. },
  3075. /**
  3076. * Validate Portuguese VAT number
  3077. * Examples:
  3078. * - Valid: PT501964843
  3079. * - Invalid: PT501964842
  3080. *
  3081. * @param {String} value VAT number
  3082. * @returns {Boolean}
  3083. */
  3084. _pt: function(value) {
  3085. if (!/^PT[0-9]{9}$/.test(value)) {
  3086. return false;
  3087. }
  3088. value = value.substr(2);
  3089. var sum = 0,
  3090. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  3091. for (var i = 0; i < 8; i++) {
  3092. sum += parseInt(value.charAt(i)) * weight[i];
  3093. }
  3094. sum = 11 - sum % 11;
  3095. if (sum > 9) {
  3096. sum = 0;
  3097. }
  3098. return (sum == value.substr(8, 1));
  3099. },
  3100. /**
  3101. * Validate Romanian VAT number
  3102. * Examples:
  3103. * - Valid: RO18547290
  3104. * - Invalid: RO18547291
  3105. *
  3106. * @param {String} value VAT number
  3107. * @returns {Boolean}
  3108. */
  3109. _ro: function(value) {
  3110. if (!/^RO[1-9][0-9]{1,9}$/.test(value)) {
  3111. return false;
  3112. }
  3113. value = value.substr(2);
  3114. var length = value.length,
  3115. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  3116. sum = 0;
  3117. for (var i = 0; i < length - 1; i++) {
  3118. sum += parseInt(value.charAt(i)) * weight[i];
  3119. }
  3120. sum = (10 * sum) % 11 % 10;
  3121. return (sum == value.substr(length - 1, 1));
  3122. },
  3123. /**
  3124. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  3125. *
  3126. * @param {String} value VAT number
  3127. * @returns {Boolean}
  3128. */
  3129. _ru: function(value) {
  3130. if (!/^RU([0-9]{9}|[0-9]{12})$/.test(value)) {
  3131. return false;
  3132. }
  3133. value = value.substr(2);
  3134. if (value.length == 10) {
  3135. var sum = 0,
  3136. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  3137. for (var i = 0; i < 10; i++) {
  3138. sum += parseInt(value.charAt(i)) * weight[i];
  3139. }
  3140. sum = sum % 11;
  3141. if (sum > 9) {
  3142. sum = sum % 10;
  3143. }
  3144. return (sum == value.substr(9, 1));
  3145. } else if (value.length == 12) {
  3146. var sum1 = 0,
  3147. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  3148. sum2 = 0,
  3149. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  3150. for (var i = 0; i < 11; i++) {
  3151. sum1 += parseInt(value.charAt(i)) * weight1[i];
  3152. sum2 += parseInt(value.charAt(i)) * weight2[i];
  3153. }
  3154. sum1 = sum1 % 11;
  3155. if (sum1 > 9) {
  3156. sum1 = sum1 % 10;
  3157. }
  3158. sum2 = sum2 % 11;
  3159. if (sum2 > 9) {
  3160. sum2 = sum2 % 10;
  3161. }
  3162. return (sum1 == value.substr(10, 1) && sum2 == value.substr(11, 1));
  3163. }
  3164. return false;
  3165. },
  3166. /**
  3167. * Validate Serbian VAT number
  3168. *
  3169. * @param {String} value VAT number
  3170. * @returns {Boolean}
  3171. */
  3172. _rs: function(value) {
  3173. if (!/^RS[0-9]{9}$/.test(value)) {
  3174. return false;
  3175. }
  3176. value = value.substr(2);
  3177. var sum = 10,
  3178. temp = 0;
  3179. for (var i = 0; i < 8; i++) {
  3180. temp = (parseInt(value.charAt(i)) + sum) % 10;
  3181. if (temp == 0) {
  3182. temp = 10;
  3183. }
  3184. sum = (2 * temp) % 11;
  3185. }
  3186. return ((sum + parseInt(value.substr(8, 1))) % 10 == 1);
  3187. },
  3188. /**
  3189. * Validate Swedish VAT number
  3190. * Examples:
  3191. * - Valid: SE123456789701
  3192. * - Invalid: SE123456789101
  3193. *
  3194. * @param {String} value VAT number
  3195. * @returns {Boolean}
  3196. */
  3197. _se: function(value) {
  3198. if (!/^SE[0-9]{10}01$/.test(value)) {
  3199. return false;
  3200. }
  3201. value = value.substr(2, 10);
  3202. return $.fn.bootstrapValidator.helpers.luhn(value);
  3203. },
  3204. /**
  3205. * Validate Slovenian VAT number
  3206. * Examples:
  3207. * - Valid: SI50223054
  3208. * - Invalid: SI50223055
  3209. *
  3210. * @param {String} value VAT number
  3211. * @returns {Boolean}
  3212. */
  3213. _si: function(value) {
  3214. if (!/^SI[0-9]{8}$/.test(value)) {
  3215. return false;
  3216. }
  3217. value = value.substr(2);
  3218. var sum = 0,
  3219. weight = [8, 7, 6, 5, 4, 3, 2];
  3220. for (var i = 0; i < 7; i++) {
  3221. sum += parseInt(value.charAt(i)) * weight[i];
  3222. }
  3223. sum = 11 - sum % 11;
  3224. if (sum == 10) {
  3225. sum = 0;
  3226. }
  3227. return (sum == value.substr(7, 1));
  3228. },
  3229. /**
  3230. * Validate Slovak VAT number
  3231. * Examples:
  3232. * - Valid: SK2022749619
  3233. * - Invalid: SK2022749618
  3234. *
  3235. * @param {String} value VAT number
  3236. * @returns {Boolean}
  3237. */
  3238. _sk: function(value) {
  3239. if (!/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  3240. return false;
  3241. }
  3242. value = value.substr(2);
  3243. return (value % 11 == 0);
  3244. }
  3245. };
  3246. }(window.jQuery));
  3247. ;(function($) {
  3248. $.fn.bootstrapValidator.validators.vin = {
  3249. /**
  3250. * Validate an US VIN (Vehicle Identification Number)
  3251. *
  3252. * @param {BootstrapValidator} validator The validator plugin instance
  3253. * @param {jQuery} $field Field element
  3254. * @param {Object} options Consist of key:
  3255. * - message: The invalid message
  3256. * @returns {Boolean}
  3257. */
  3258. validate: function(validator, $field, options) {
  3259. var value = $field.val();
  3260. if (value == '') {
  3261. return true;
  3262. }
  3263. // Don't accept I, O, Q characters
  3264. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  3265. return false;
  3266. }
  3267. value = value.toUpperCase();
  3268. var chars = {
  3269. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  3270. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  3271. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  3272. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  3273. },
  3274. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  3275. sum = 0,
  3276. length = value.length;
  3277. for (var i = 0; i < length; i++) {
  3278. sum += chars[value.charAt(i) + ''] * weights[i];
  3279. }
  3280. var reminder = sum % 11;
  3281. if (reminder == 10) {
  3282. reminder = 'X';
  3283. }
  3284. return reminder == value.charAt(8);
  3285. }
  3286. };
  3287. }(window.jQuery));
  3288. ;(function($) {
  3289. $.fn.bootstrapValidator.validators.zipCode = {
  3290. html5Attributes: {
  3291. message: 'message',
  3292. country: 'country'
  3293. },
  3294. /**
  3295. * Return true if and only if the input value is a valid country zip code
  3296. *
  3297. * @param {BootstrapValidator} validator The validator plugin instance
  3298. * @param {jQuery} $field Field element
  3299. * @param {Object} options Consist of key:
  3300. * - message: The invalid message
  3301. * - country: The ISO 3166 country code
  3302. *
  3303. * Currently it supports the following countries:
  3304. * - US (United State)
  3305. * - CA (Canada)
  3306. * - DK (Denmark)
  3307. * - SE (Sweden)
  3308. * @returns {Boolean}
  3309. */
  3310. validate: function(validator, $field, options) {
  3311. var value = $field.val();
  3312. if (value == '' || !options.country) {
  3313. return true;
  3314. }
  3315. var country = (options.country || 'US').toUpperCase();
  3316. switch (country) {
  3317. case 'CA':
  3318. 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);
  3319. case 'DK':
  3320. return /^(DK(-|\s)?)?\d{4}$/i.test(value);
  3321. case 'SE':
  3322. return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  3323. case 'US':
  3324. default:
  3325. return /^\d{4,5}([\-]\d{4})?$/.test(value);
  3326. }
  3327. }
  3328. };
  3329. }(window.jQuery));