bootstrapValidator.js 130 KB

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