bootstrap_validator-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README.md +4 -0
  4. data/lib/bootstrap_validator-rails.rb +5 -0
  5. data/lib/bootstrap_validator-rails/engine.rb +6 -0
  6. data/vendor/javascripts/bootstrapValidator.js +1803 -0
  7. data/vendor/javascripts/language/de_DE.js +326 -0
  8. data/vendor/javascripts/language/en_US.js +327 -0
  9. data/vendor/javascripts/language/es_CL.js +326 -0
  10. data/vendor/javascripts/language/hu_HU.js +326 -0
  11. data/vendor/javascripts/language/vi_VN.js +322 -0
  12. data/vendor/javascripts/language/zh_CN.js +326 -0
  13. data/vendor/javascripts/language/zh_TW.js +326 -0
  14. data/vendor/javascripts/validator/base64.js +25 -0
  15. data/vendor/javascripts/validator/between.js +66 -0
  16. data/vendor/javascripts/validator/callback.js +40 -0
  17. data/vendor/javascripts/validator/choice.js +68 -0
  18. data/vendor/javascripts/validator/creditCard.js +103 -0
  19. data/vendor/javascripts/validator/cusip.js +55 -0
  20. data/vendor/javascripts/validator/cvv.js +116 -0
  21. data/vendor/javascripts/validator/date.js +118 -0
  22. data/vendor/javascripts/validator/different.js +41 -0
  23. data/vendor/javascripts/validator/digits.js +24 -0
  24. data/vendor/javascripts/validator/ean.js +40 -0
  25. data/vendor/javascripts/validator/emailAddress.js +31 -0
  26. data/vendor/javascripts/validator/file.js +69 -0
  27. data/vendor/javascripts/validator/greaterThan.js +61 -0
  28. data/vendor/javascripts/validator/grid.js +37 -0
  29. data/vendor/javascripts/validator/hex.js +25 -0
  30. data/vendor/javascripts/validator/hexColor.js +28 -0
  31. data/vendor/javascripts/validator/iban.js +246 -0
  32. data/vendor/javascripts/validator/id.js +815 -0
  33. data/vendor/javascripts/validator/identical.js +40 -0
  34. data/vendor/javascripts/validator/imei.js +44 -0
  35. data/vendor/javascripts/validator/integer.js +28 -0
  36. data/vendor/javascripts/validator/ip.js +48 -0
  37. data/vendor/javascripts/validator/isbn.js +86 -0
  38. data/vendor/javascripts/validator/isin.js +59 -0
  39. data/vendor/javascripts/validator/ismn.js +59 -0
  40. data/vendor/javascripts/validator/issn.js +46 -0
  41. data/vendor/javascripts/validator/lessThan.js +61 -0
  42. data/vendor/javascripts/validator/mac.js +25 -0
  43. data/vendor/javascripts/validator/notEmpty.js +32 -0
  44. data/vendor/javascripts/validator/numeric.js +39 -0
  45. data/vendor/javascripts/validator/phone.js +84 -0
  46. data/vendor/javascripts/validator/regexp.js +42 -0
  47. data/vendor/javascripts/validator/remote.js +70 -0
  48. data/vendor/javascripts/validator/rtn.js +38 -0
  49. data/vendor/javascripts/validator/sedol.js +40 -0
  50. data/vendor/javascripts/validator/siren.js +28 -0
  51. data/vendor/javascripts/validator/siret.js +38 -0
  52. data/vendor/javascripts/validator/step.js +64 -0
  53. data/vendor/javascripts/validator/stringCase.js +36 -0
  54. data/vendor/javascripts/validator/stringLength.js +81 -0
  55. data/vendor/javascripts/validator/uri.js +101 -0
  56. data/vendor/javascripts/validator/uuid.js +46 -0
  57. data/vendor/javascripts/validator/vat.js +1220 -0
  58. data/vendor/javascripts/validator/vin.js +49 -0
  59. data/vendor/javascripts/validator/zipCode.js +162 -0
  60. data/vendor/stylesheets/bootstrapValidator.css +21 -0
  61. metadata +130 -0
@@ -0,0 +1,64 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.step = $.extend($.fn.bootstrapValidator.i18n.step || {}, {
3
+ 'default': 'Please enter a valid step of %s'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.step = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ base: 'baseValue',
10
+ step: 'step'
11
+ },
12
+
13
+ /**
14
+ * Return true if the input value is valid step one
15
+ *
16
+ * @param {BootstrapValidator} validator The validator plugin instance
17
+ * @param {jQuery} $field Field element
18
+ * @param {Object} options Can consist of the following keys:
19
+ * - baseValue: The base value
20
+ * - step: The step
21
+ * - message: The invalid message
22
+ * @returns {Boolean|Object}
23
+ */
24
+ validate: function(validator, $field, options) {
25
+ var value = $field.val();
26
+ if (value === '') {
27
+ return true;
28
+ }
29
+
30
+ options = $.extend({}, { baseValue: 0, step: 1 }, options);
31
+ value = parseFloat(value);
32
+ if (!$.isNumeric(value)) {
33
+ return false;
34
+ }
35
+
36
+ var round = function(x, precision) {
37
+ var m = Math.pow(10, precision);
38
+ x = x * m;
39
+ var sign = (x > 0) | -(x < 0),
40
+ isHalf = (x % 1 === 0.5 * sign);
41
+ if (isHalf) {
42
+ return (Math.floor(x) + (sign > 0)) / m;
43
+ } else {
44
+ return Math.round(x) / m;
45
+ }
46
+ },
47
+ floatMod = function(x, y) {
48
+ if (y === 0.0) {
49
+ return 1.0;
50
+ }
51
+ var dotX = (x + '').split('.'),
52
+ dotY = (y + '').split('.'),
53
+ precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
54
+ return round(x - y * Math.floor(x / y), precision);
55
+ };
56
+
57
+ var mod = floatMod(value - options.baseValue, options.step);
58
+ return {
59
+ valid: mod === 0.0 || mod === options.step,
60
+ message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.step['default'], [options.step])
61
+ };
62
+ }
63
+ };
64
+ }(window.jQuery));
@@ -0,0 +1,36 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.stringCase = $.extend($.fn.bootstrapValidator.i18n.stringCase || {}, {
3
+ 'default': 'Please enter only lowercase characters',
4
+ upper: 'Please enter only uppercase characters'
5
+ });
6
+
7
+ $.fn.bootstrapValidator.validators.stringCase = {
8
+ html5Attributes: {
9
+ message: 'message',
10
+ 'case': 'case'
11
+ },
12
+
13
+ /**
14
+ * Check if a string is a lower or upper case one
15
+ *
16
+ * @param {BootstrapValidator} validator The validator plugin instance
17
+ * @param {jQuery} $field Field element
18
+ * @param {Object} options Consist of key:
19
+ * - message: The invalid message
20
+ * - case: Can be 'lower' (default) or 'upper'
21
+ * @returns {Object}
22
+ */
23
+ validate: function(validator, $field, options) {
24
+ var value = $field.val();
25
+ if (value === '') {
26
+ return true;
27
+ }
28
+
29
+ var stringCase = (options['case'] || 'lower').toLowerCase();
30
+ return {
31
+ valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
32
+ message: options.message || (('upper' === stringCase) ? $.fn.bootstrapValidator.i18n.stringCase.upper : $.fn.bootstrapValidator.i18n.stringCase['default'])
33
+ };
34
+ }
35
+ };
36
+ }(window.jQuery));
@@ -0,0 +1,81 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.stringLength = $.extend($.fn.bootstrapValidator.i18n.stringLength || {}, {
3
+ 'default': 'Please enter a value with valid length',
4
+ less: 'Please enter less than %s characters',
5
+ more: 'Please enter more than %s characters',
6
+ between: 'Please enter value between %s and %s characters long'
7
+ });
8
+
9
+ $.fn.bootstrapValidator.validators.stringLength = {
10
+ html5Attributes: {
11
+ message: 'message',
12
+ min: 'min',
13
+ max: 'max'
14
+ },
15
+
16
+ enableByHtml5: function($field) {
17
+ var maxLength = $field.attr('maxlength');
18
+ if (maxLength) {
19
+ return {
20
+ max: parseInt(maxLength, 10)
21
+ };
22
+ }
23
+
24
+ return false;
25
+ },
26
+
27
+ /**
28
+ * Check if the length of element value is less or more than given number
29
+ *
30
+ * @param {BootstrapValidator} validator The validator plugin instance
31
+ * @param {jQuery} $field Field element
32
+ * @param {Object} options Consists of following keys:
33
+ * - min
34
+ * - max
35
+ * At least one of two keys is required
36
+ * The min, max keys define the number which the field value compares to. min, max can be
37
+ * - A number
38
+ * - Name of field which its value defines the number
39
+ * - Name of callback function that returns the number
40
+ * - A callback function that returns the number
41
+ *
42
+ * - message: The invalid message
43
+ * @returns {Object}
44
+ */
45
+ validate: function(validator, $field, options) {
46
+ var value = $field.val();
47
+ if (value === '') {
48
+ return true;
49
+ }
50
+
51
+ var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
52
+ max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
53
+ length = value.length,
54
+ isValid = true,
55
+ message = options.message || $.fn.bootstrapValidator.i18n.stringLength['default'];
56
+
57
+ if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
58
+ isValid = false;
59
+ }
60
+
61
+ switch (true) {
62
+ case (!!min && !!max):
63
+ message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
64
+ break;
65
+
66
+ case (!!min):
67
+ message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.more, parseInt(min, 10));
68
+ break;
69
+
70
+ case (!!max):
71
+ message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.less, parseInt(max, 10));
72
+ break;
73
+
74
+ default:
75
+ break;
76
+ }
77
+
78
+ return { valid: isValid, message: message };
79
+ }
80
+ };
81
+ }(window.jQuery));
@@ -0,0 +1,101 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.uri = $.extend($.fn.bootstrapValidator.i18n.uri || {}, {
3
+ 'default': 'Please enter a valid URI'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.uri = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ allowlocal: 'allowLocal'
10
+ },
11
+
12
+ enableByHtml5: function($field) {
13
+ return ('url' === $field.attr('type'));
14
+ },
15
+
16
+ /**
17
+ * Return true if the input value is a valid URL
18
+ *
19
+ * @param {BootstrapValidator} validator The validator plugin instance
20
+ * @param {jQuery} $field Field element
21
+ * @param {Object} options
22
+ * - message: The error message
23
+ * - allowLocal: Allow the private and local network IP. Default to false
24
+ * @returns {Boolean}
25
+ */
26
+ validate: function(validator, $field, options) {
27
+ var value = $field.val();
28
+ if (value === '') {
29
+ return true;
30
+ }
31
+
32
+ // Credit to https://gist.github.com/dperini/729294
33
+ //
34
+ // Regular Expression for URL validation
35
+ //
36
+ // Author: Diego Perini
37
+ // Updated: 2010/12/05
38
+ //
39
+ // the regular expression composed & commented
40
+ // could be easily tweaked for RFC compliance,
41
+ // it was expressly modified to fit & satisfy
42
+ // these test for an URL shortener:
43
+ //
44
+ // http://mathiasbynens.be/demo/url-regex
45
+ //
46
+ // Notes on possible differences from a standard/generic validation:
47
+ //
48
+ // - utf-8 char class take in consideration the full Unicode range
49
+ // - TLDs have been made mandatory so single names like "localhost" fails
50
+ // - protocols have been restricted to ftp, http and https only as requested
51
+ //
52
+ // Changes:
53
+ //
54
+ // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
55
+ // first and last IP address of each class is considered invalid
56
+ // (since they are broadcast/network addresses)
57
+ //
58
+ // - Added exclusion of private, reserved and/or local networks ranges
59
+ //
60
+ var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
61
+ urlExp = new RegExp(
62
+ "^" +
63
+ // protocol identifier
64
+ "(?:(?:https?|ftp)://)" +
65
+ // user:pass authentication
66
+ "(?:\\S+(?::\\S*)?@)?" +
67
+ "(?:" +
68
+ // IP address exclusion
69
+ // private & local networks
70
+ (allowLocal
71
+ ? ''
72
+ : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
73
+ "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
74
+ "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
75
+ // IP address dotted notation octets
76
+ // excludes loopback network 0.0.0.0
77
+ // excludes reserved space >= 224.0.0.0
78
+ // excludes network & broadcast addresses
79
+ // (first & last IP address of each class)
80
+ "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
81
+ "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
82
+ "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
83
+ "|" +
84
+ // host name
85
+ "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
86
+ // domain name
87
+ "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
88
+ // TLD identifier
89
+ "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
90
+ ")" +
91
+ // port number
92
+ "(?::\\d{2,5})?" +
93
+ // resource path
94
+ "(?:/[^\\s]*)?" +
95
+ "$", "i"
96
+ );
97
+
98
+ return urlExp.test(value);
99
+ }
100
+ };
101
+ }(window.jQuery));
@@ -0,0 +1,46 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.uuid = $.extend($.fn.bootstrapValidator.i18n.uuid || {}, {
3
+ 'default': 'Please enter a valid UUID number',
4
+ version: 'Please enter a valid UUID version %s number'
5
+ });
6
+
7
+ $.fn.bootstrapValidator.validators.uuid = {
8
+ html5Attributes: {
9
+ message: 'message',
10
+ version: 'version'
11
+ },
12
+
13
+ /**
14
+ * Return true if and only if the input value is a valid UUID string
15
+ *
16
+ * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
17
+ * @param {BootstrapValidator} validator The validator plugin instance
18
+ * @param {jQuery} $field Field element
19
+ * @param {Object} options Consist of key:
20
+ * - message: The invalid message
21
+ * - version: Can be 3, 4, 5, null
22
+ * @returns {Boolean|Object}
23
+ */
24
+ validate: function(validator, $field, options) {
25
+ var value = $field.val();
26
+ if (value === '') {
27
+ return true;
28
+ }
29
+
30
+ // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
31
+ var patterns = {
32
+ '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
33
+ '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
34
+ '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
35
+ all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
36
+ },
37
+ version = options.version ? (options.version + '') : 'all';
38
+ return {
39
+ valid: (null === patterns[version]) ? true : patterns[version].test(value),
40
+ message: options.version
41
+ ? $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.uuid.version, options.version)
42
+ : (options.message || $.fn.bootstrapValidator.i18n.uuid['default'])
43
+ };
44
+ }
45
+ };
46
+ }(window.jQuery));
@@ -0,0 +1,1220 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.vat = $.extend($.fn.bootstrapValidator.i18n.vat || {}, {
3
+ 'default': 'Please enter a valid VAT number',
4
+ countryNotSupported: 'The country code %s is not supported',
5
+ country: 'Please enter a valid %s VAT number',
6
+ countries: {
7
+ AT: 'Austrian',
8
+ BE: 'Belgian',
9
+ BG: 'Bulgarian',
10
+ CH: 'Swiss',
11
+ CY: 'Cypriot',
12
+ CZ: 'Czech',
13
+ DE: 'German',
14
+ DK: 'Danish',
15
+ EE: 'Estonian',
16
+ ES: 'Spanish',
17
+ FI: 'Finnish',
18
+ FR: 'French',
19
+ GB: 'United Kingdom',
20
+ GR: 'Greek',
21
+ EL: 'Greek',
22
+ HU: 'Hungarian',
23
+ HR: 'Croatian',
24
+ IE: 'Irish',
25
+ IT: 'Italian',
26
+ LT: 'Lithuanian',
27
+ LU: 'Luxembourg',
28
+ LV: 'Latvian',
29
+ MT: 'Maltese',
30
+ NL: 'Dutch',
31
+ NO: 'Norwegian',
32
+ PL: 'Polish',
33
+ PT: 'Portuguese',
34
+ RO: 'Romanian',
35
+ RU: 'Russian',
36
+ RS: 'Serbian',
37
+ SE: 'Swedish',
38
+ SI: 'Slovenian',
39
+ SK: 'Slovak'
40
+ }
41
+ });
42
+
43
+ $.fn.bootstrapValidator.validators.vat = {
44
+ html5Attributes: {
45
+ message: 'message',
46
+ country: 'country'
47
+ },
48
+
49
+ // Supported country codes
50
+ COUNTRY_CODES: [
51
+ 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'EL', 'HU', 'IE', 'IT',
52
+ 'LV', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SK', 'SI', 'ES', 'SE', 'CH', 'GB'
53
+ ],
54
+
55
+ /**
56
+ * Validate an European VAT number
57
+ *
58
+ * @param {BootstrapValidator} validator The validator plugin instance
59
+ * @param {jQuery} $field Field element
60
+ * @param {Object} options Consist of key:
61
+ * - message: The invalid message
62
+ * - country: The ISO 3166-1 country code. It can be
63
+ * - One of country code defined in COUNTRY_CODES
64
+ * - Name of field which its value defines the country code
65
+ * - Name of callback function that returns the country code
66
+ * - A callback function that returns the country code
67
+ * @returns {Boolean|Object}
68
+ */
69
+ validate: function(validator, $field, options) {
70
+ var value = $field.val();
71
+ if (value === '') {
72
+ return true;
73
+ }
74
+
75
+ var country = options.country;
76
+ if (!country) {
77
+ country = value.substr(0, 2);
78
+ } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
79
+ // Determine the country code
80
+ country = validator.getDynamicOption($field, country);
81
+ }
82
+
83
+ if ($.inArray(country, this.COUNTRY_CODES) === -1) {
84
+ return {
85
+ valid: false,
86
+ message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.vat.countryNotSupported, country)
87
+ };
88
+ }
89
+
90
+ var method = ['_', country.toLowerCase()].join('');
91
+ return this[method](value)
92
+ ? true
93
+ : {
94
+ valid: false,
95
+ message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.vat.country, $.fn.bootstrapValidator.i18n.vat.countries[country.toUpperCase()])
96
+ };
97
+ },
98
+
99
+ // VAT validators
100
+
101
+ /**
102
+ * Validate Austrian VAT number
103
+ * Example:
104
+ * - Valid: ATU13585627
105
+ * - Invalid: ATU13585626
106
+ *
107
+ * @param {String} value VAT number
108
+ * @returns {Boolean}
109
+ */
110
+ _at: function(value) {
111
+ if (!/^ATU[0-9]{8}$/.test(value)) {
112
+ return false;
113
+ }
114
+
115
+ value = value.substr(3);
116
+ var sum = 0,
117
+ weight = [1, 2, 1, 2, 1, 2, 1],
118
+ temp = 0;
119
+
120
+ for (var i = 0; i < 7; i++) {
121
+ temp = parseInt(value.charAt(i), 10) * weight[i];
122
+ if (temp > 9) {
123
+ temp = Math.floor(temp / 10) + temp % 10;
124
+ }
125
+ sum += temp;
126
+ }
127
+
128
+ sum = 10 - (sum + 4) % 10;
129
+ if (sum === 10) {
130
+ sum = 0;
131
+ }
132
+
133
+ return (sum + '' === value.substr(7, 1));
134
+ },
135
+
136
+ /**
137
+ * Validate Belgian VAT number
138
+ * Example:
139
+ * - Valid: BE0428759497
140
+ * - Invalid: BE431150351
141
+ *
142
+ * @param {String} value VAT number
143
+ * @returns {Boolean}
144
+ */
145
+ _be: function(value) {
146
+ if (!/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
147
+ return false;
148
+ }
149
+
150
+ value = value.substr(2);
151
+ if (value.length === 9) {
152
+ value = '0' + value;
153
+ }
154
+
155
+ if (value.substr(1, 1) === '0') {
156
+ return false;
157
+ }
158
+
159
+ var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
160
+ return (sum % 97 === 0);
161
+ },
162
+
163
+ /**
164
+ * Validate Bulgarian VAT number
165
+ * Example:
166
+ * - Valid: BG175074752,
167
+ * BG7523169263, BG8032056031,
168
+ * BG7542011030,
169
+ * BG7111042925
170
+ * - Invalid: BG175074753, BG7552A10004, BG7111042922
171
+ *
172
+ * @param {String} value VAT number
173
+ * @returns {Boolean}
174
+ */
175
+ _bg: function(value) {
176
+ if (!/^BG[0-9]{9,10}$/.test(value)) {
177
+ return false;
178
+ }
179
+
180
+ value = value.substr(2);
181
+ var sum = 0, i = 0;
182
+
183
+ // Legal entities
184
+ if (value.length === 9) {
185
+ for (i = 0; i < 8; i++) {
186
+ sum += parseInt(value.charAt(i), 10) * (i + 1);
187
+ }
188
+ sum = sum % 11;
189
+ if (sum === 10) {
190
+ sum = 0;
191
+ for (i = 0; i < 8; i++) {
192
+ sum += parseInt(value.charAt(i), 10) * (i + 3);
193
+ }
194
+ }
195
+ sum = sum % 10;
196
+ return (sum + '' === value.substr(8));
197
+ }
198
+ // Physical persons, foreigners and others
199
+ else if (value.length === 10) {
200
+ // Validate Bulgarian national identification numbers
201
+ var egn = function(value) {
202
+ // Check the birth date
203
+ var year = parseInt(value.substr(0, 2), 10) + 1900,
204
+ month = parseInt(value.substr(2, 2), 10),
205
+ day = parseInt(value.substr(4, 2), 10);
206
+ if (month > 40) {
207
+ year += 100;
208
+ month -= 40;
209
+ } else if (month > 20) {
210
+ year -= 100;
211
+ month -= 20;
212
+ }
213
+
214
+ if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
215
+ return false;
216
+ }
217
+
218
+ var sum = 0,
219
+ weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
220
+ for (var i = 0; i < 9; i++) {
221
+ sum += parseInt(value.charAt(i), 10) * weight[i];
222
+ }
223
+ sum = (sum % 11) % 10;
224
+ return (sum + '' === value.substr(9, 1));
225
+ },
226
+ // Validate Bulgarian personal number of a foreigner
227
+ pnf = function(value) {
228
+ var sum = 0,
229
+ weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
230
+ for (var i = 0; i < 9; i++) {
231
+ sum += parseInt(value.charAt(i), 10) * weight[i];
232
+ }
233
+ sum = sum % 10;
234
+ return (sum + '' === value.substr(9, 1));
235
+ },
236
+ // Finally, consider it as a VAT number
237
+ vat = function(value) {
238
+ var sum = 0,
239
+ weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
240
+ for (var i = 0; i < 9; i++) {
241
+ sum += parseInt(value.charAt(i), 10) * weight[i];
242
+ }
243
+ sum = 11 - sum % 11;
244
+ if (sum === 10) {
245
+ return false;
246
+ }
247
+ if (sum === 11) {
248
+ sum = 0;
249
+ }
250
+ return (sum + '' === value.substr(9, 1));
251
+ };
252
+ return (egn(value) || pnf(value) || vat(value));
253
+ }
254
+
255
+ return false;
256
+ },
257
+
258
+ /**
259
+ * Validate Swiss VAT number
260
+ *
261
+ * @param {String} value VAT number
262
+ * @returns {Boolean}
263
+ */
264
+ _ch: function(value) {
265
+ if (!/^CHE[0-9]{9}(MWST)?$/.test(value)) {
266
+ return false;
267
+ }
268
+
269
+ value = value.substr(3);
270
+ var sum = 0,
271
+ weight = [5, 4, 3, 2, 7, 6, 5, 4];
272
+ for (var i = 0; i < 8; i++) {
273
+ sum += parseInt(value.charAt(i), 10) * weight[i];
274
+ }
275
+
276
+ sum = 11 - sum % 11;
277
+ if (sum === 10) {
278
+ return false;
279
+ }
280
+ if (sum === 11) {
281
+ sum = 0;
282
+ }
283
+
284
+ return (sum + '' === value.substr(8, 1));
285
+ },
286
+
287
+ /**
288
+ * Validate Cypriot VAT number
289
+ * Examples:
290
+ * - Valid: CY10259033P
291
+ * - Invalid: CY10259033Z
292
+ *
293
+ * @param {String} value VAT number
294
+ * @returns {Boolean}
295
+ */
296
+ _cy: function(value) {
297
+ if (!/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
298
+ return false;
299
+ }
300
+
301
+ value = value.substr(2);
302
+
303
+ // Do not allow to start with "12"
304
+ if (value.substr(0, 2) === '12') {
305
+ return false;
306
+ }
307
+
308
+ // Extract the next digit and multiply by the counter.
309
+ var sum = 0,
310
+ translation = {
311
+ '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
312
+ '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
313
+ };
314
+ for (var i = 0; i < 8; i++) {
315
+ var temp = parseInt(value.charAt(i), 10);
316
+ if (i % 2 === 0) {
317
+ temp = translation[temp + ''];
318
+ }
319
+ sum += temp;
320
+ }
321
+
322
+ sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
323
+ return (sum + '' === value.substr(8, 1));
324
+ },
325
+
326
+ /**
327
+ * Validate Czech Republic VAT number
328
+ * Can be:
329
+ * i) Legal entities (8 digit numbers)
330
+ * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
331
+ * iii) Individuals without a RC (9 digit numbers beginning with 6)
332
+ *
333
+ * Examples:
334
+ * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
335
+ * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
336
+ *
337
+ * @param {String} value VAT number
338
+ * @returns {Boolean}
339
+ */
340
+ _cz: function(value) {
341
+ if (!/^CZ[0-9]{8,10}$/.test(value)) {
342
+ return false;
343
+ }
344
+
345
+ value = value.substr(2);
346
+
347
+ var sum = 0,
348
+ i = 0;
349
+ if (value.length === 8) {
350
+ // Do not allow to start with '9'
351
+ if (value.charAt(0) + '' === '9') {
352
+ return false;
353
+ }
354
+
355
+ sum = 0;
356
+ for (i = 0; i < 7; i++) {
357
+ sum += parseInt(value.charAt(i), 10) * (8 - i);
358
+ }
359
+ sum = 11 - sum % 11;
360
+ if (sum === 10) {
361
+ sum = 0;
362
+ }
363
+ if (sum === 11) {
364
+ sum = 1;
365
+ }
366
+
367
+ return (sum + '' === value.substr(7, 1));
368
+ } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
369
+ sum = 0;
370
+ // Skip the first (which is 6)
371
+ for (i = 0; i < 7; i++) {
372
+ sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
373
+ }
374
+ sum = 11 - sum % 11;
375
+ if (sum === 10) {
376
+ sum = 0;
377
+ }
378
+ if (sum === 11) {
379
+ sum = 1;
380
+ }
381
+ sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
382
+ return (sum + '' === value.substr(8, 1));
383
+ } else if (value.length === 9 || value.length === 10) {
384
+ // Validate Czech birth number (Rodné číslo), which is also national identifier
385
+ var year = 1900 + parseInt(value.substr(0, 2), 10),
386
+ month = parseInt(value.substr(2, 2), 10) % 50 % 20,
387
+ day = parseInt(value.substr(4, 2), 10);
388
+ if (value.length === 9) {
389
+ if (year >= 1980) {
390
+ year -= 100;
391
+ }
392
+ if (year > 1953) {
393
+ return false;
394
+ }
395
+ } else if (year < 1954) {
396
+ year += 100;
397
+ }
398
+
399
+ if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
400
+ return false;
401
+ }
402
+
403
+ // Check that the birth date is not in the future
404
+ if (value.length === 10) {
405
+ var check = parseInt(value.substr(0, 9), 10) % 11;
406
+ if (year < 1985) {
407
+ check = check % 10;
408
+ }
409
+ return (check + '' === value.substr(9, 1));
410
+ }
411
+
412
+ return true;
413
+ }
414
+
415
+ return false;
416
+ },
417
+
418
+ /**
419
+ * Validate German VAT number
420
+ * Examples:
421
+ * - Valid: DE136695976
422
+ * - Invalid: DE136695978
423
+ *
424
+ * @param {String} value VAT number
425
+ * @returns {Boolean}
426
+ */
427
+ _de: function(value) {
428
+ if (!/^DE[0-9]{9}$/.test(value)) {
429
+ return false;
430
+ }
431
+
432
+ value = value.substr(2);
433
+ return $.fn.bootstrapValidator.helpers.mod11And10(value);
434
+ },
435
+
436
+ /**
437
+ * Validate Danish VAT number
438
+ * Example:
439
+ * - Valid: DK13585628
440
+ * - Invalid: DK13585627
441
+ *
442
+ * @param {String} value VAT number
443
+ * @returns {Boolean}
444
+ */
445
+ _dk: function(value) {
446
+ if (!/^DK[0-9]{8}$/.test(value)) {
447
+ return false;
448
+ }
449
+
450
+ value = value.substr(2);
451
+ var sum = 0,
452
+ weight = [2, 7, 6, 5, 4, 3, 2, 1];
453
+ for (var i = 0; i < 8; i++) {
454
+ sum += parseInt(value.charAt(i), 10) * weight[i];
455
+ }
456
+
457
+ return (sum % 11 === 0);
458
+ },
459
+
460
+ /**
461
+ * Validate Estonian VAT number
462
+ * Examples:
463
+ * - Valid: EE100931558, EE100594102
464
+ * - Invalid: EE100594103
465
+ *
466
+ * @param {String} value VAT number
467
+ * @returns {Boolean}
468
+ */
469
+ _ee: function(value) {
470
+ if (!/^EE[0-9]{9}$/.test(value)) {
471
+ return false;
472
+ }
473
+
474
+ value = value.substr(2);
475
+ var sum = 0,
476
+ weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
477
+
478
+ for (var i = 0; i < 9; i++) {
479
+ sum += parseInt(value.charAt(i), 10) * weight[i];
480
+ }
481
+
482
+ return (sum % 10 === 0);
483
+ },
484
+
485
+ /**
486
+ * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
487
+ * Can be:
488
+ * i) DNI (Documento nacional de identidad), for Spaniards
489
+ * ii) NIE (Número de Identificación de Extranjeros), for foreigners
490
+ * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
491
+ *
492
+ * Examples:
493
+ * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
494
+ * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
495
+ *
496
+ * @param {String} value VAT number
497
+ * @returns {Boolean}
498
+ */
499
+ _es: function(value) {
500
+ if (!/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
501
+ return false;
502
+ }
503
+
504
+ value = value.substr(2);
505
+ var dni = function(value) {
506
+ var check = parseInt(value.substr(0, 8), 10);
507
+ check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
508
+ return (check + '' === value.substr(8, 1));
509
+ },
510
+ nie = function(value) {
511
+ var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
512
+ check = parseInt(check, 10);
513
+ check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
514
+ return (check + '' === value.substr(8, 1));
515
+ },
516
+ cif = function(value) {
517
+ var first = value.charAt(0), check;
518
+ if ('KLM'.indexOf(first) !== -1) {
519
+ // K: Spanish younger than 14 year old
520
+ // L: Spanish living outside Spain without DNI
521
+ // M: Granted the tax to foreigners who have no NIE
522
+ check = parseInt(value.substr(1, 8), 10);
523
+ check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
524
+ return (check + '' === value.substr(8, 1));
525
+ } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
526
+ var sum = 0,
527
+ weight = [2, 1, 2, 1, 2, 1, 2],
528
+ temp = 0;
529
+
530
+ for (var i = 0; i < 7; i++) {
531
+ temp = parseInt(value.charAt(i + 1), 10) * weight[i];
532
+ if (temp > 9) {
533
+ temp = Math.floor(temp / 10) + temp % 10;
534
+ }
535
+ sum += temp;
536
+ }
537
+ sum = 10 - sum % 10;
538
+ return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
539
+ }
540
+
541
+ return false;
542
+ };
543
+
544
+ var first = value.charAt(0);
545
+ if (/^[0-9]$/.test(first)) {
546
+ return dni(value);
547
+ } else if (/^[XYZ]$/.test(first)) {
548
+ return nie(value);
549
+ } else {
550
+ return cif(value);
551
+ }
552
+ },
553
+
554
+ /**
555
+ * Validate Finnish VAT number
556
+ * Examples:
557
+ * - Valid: FI20774740
558
+ * - Invalid: FI20774741
559
+ *
560
+ * @param {String} value VAT number
561
+ * @returns {Boolean}
562
+ */
563
+ _fi: function(value) {
564
+ if (!/^FI[0-9]{8}$/.test(value)) {
565
+ return false;
566
+ }
567
+
568
+ value = value.substr(2);
569
+ var sum = 0,
570
+ weight = [7, 9, 10, 5, 8, 4, 2, 1];
571
+
572
+ for (var i = 0; i < 8; i++) {
573
+ sum += parseInt(value.charAt(i), 10) * weight[i];
574
+ }
575
+
576
+ return (sum % 11 === 0);
577
+ },
578
+
579
+ /**
580
+ * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
581
+ * It's constructed by a SIREN number, prefixed by two characters.
582
+ *
583
+ * Examples:
584
+ * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
585
+ * - Invalid: FR84323140391
586
+ *
587
+ * @param {String} value VAT number
588
+ * @returns {Boolean}
589
+ */
590
+ _fr: function(value) {
591
+ if (!/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
592
+ return false;
593
+ }
594
+
595
+ value = value.substr(2);
596
+
597
+ if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
598
+ return false;
599
+ }
600
+
601
+ if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
602
+ // First two characters are digits
603
+ return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
604
+ } else {
605
+ // The first characters cann't be O and I
606
+ var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
607
+ check;
608
+ // First one is digit
609
+ if (/^[0-9]{1}$/.test(value.charAt(0))) {
610
+ check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
611
+ } else {
612
+ check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
613
+ }
614
+ return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
615
+ }
616
+ },
617
+
618
+ /**
619
+ * Validate United Kingdom VAT number
620
+ * Example:
621
+ * - Valid: GB980780684
622
+ * - Invalid: GB802311781
623
+ *
624
+ * @param {String} value VAT number
625
+ * @returns {Boolean}
626
+ */
627
+ _gb: function(value) {
628
+ if (!/^GB[0-9]{9}$/.test(value) /* Standard */
629
+ && !/^GB[0-9]{12}$/.test(value) /* Branches */
630
+ && !/^GBGD[0-9]{3}$/.test(value) /* Government department */
631
+ && !/^GBHA[0-9]{3}$/.test(value) /* Health authority */
632
+ && !/^GB(GD|HA)8888[0-9]{5}$/.test(value))
633
+ {
634
+ return false;
635
+ }
636
+
637
+ value = value.substr(2);
638
+ var length = value.length;
639
+ if (length === 5) {
640
+ var firstTwo = value.substr(0, 2),
641
+ lastThree = parseInt(value.substr(2), 10);
642
+ return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
643
+ } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
644
+ if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
645
+ || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
646
+ {
647
+ return false;
648
+ }
649
+ return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
650
+ } else if (length === 9 || length === 12) {
651
+ var sum = 0,
652
+ weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
653
+ for (var i = 0; i < 9; i++) {
654
+ sum += parseInt(value.charAt(i), 10) * weight[i];
655
+ }
656
+ sum = sum % 97;
657
+
658
+ if (parseInt(value.substr(0, 3), 10) >= 100) {
659
+ return (sum === 0 || sum === 42 || sum === 55);
660
+ } else {
661
+ return (sum === 0);
662
+ }
663
+ }
664
+
665
+ return true;
666
+ },
667
+
668
+ /**
669
+ * Validate Greek VAT number
670
+ * Examples:
671
+ * - Valid: GR023456780, EL094259216
672
+ * - Invalid: EL123456781
673
+ *
674
+ * @param {String} value VAT number
675
+ * @returns {Boolean}
676
+ */
677
+ _gr: function(value) {
678
+ if (!/^GR[0-9]{9}$/.test(value)) {
679
+ return false;
680
+ }
681
+
682
+ value = value.substr(2);
683
+ if (value.length === 8) {
684
+ value = '0' + value;
685
+ }
686
+
687
+ var sum = 0,
688
+ weight = [256, 128, 64, 32, 16, 8, 4, 2];
689
+ for (var i = 0; i < 8; i++) {
690
+ sum += parseInt(value.charAt(i), 10) * weight[i];
691
+ }
692
+ sum = (sum % 11) % 10;
693
+
694
+ return (sum + '' === value.substr(8, 1));
695
+ },
696
+
697
+ // EL is traditionally prefix of Greek VAT numbers
698
+ _el: function(value) {
699
+ if (!/^EL[0-9]{9}$/.test(value)) {
700
+ return false;
701
+ }
702
+
703
+ value = 'GR' + value.substr(2);
704
+ return this._gr(value);
705
+ },
706
+
707
+ /**
708
+ * Validate Hungarian VAT number
709
+ * Examples:
710
+ * - Valid: HU12892312
711
+ * - Invalid: HU12892313
712
+ *
713
+ * @param {String} value VAT number
714
+ * @returns {Boolean}
715
+ */
716
+ _hu: function(value) {
717
+ if (!/^HU[0-9]{8}$/.test(value)) {
718
+ return false;
719
+ }
720
+
721
+ value = value.substr(2);
722
+ var sum = 0,
723
+ weight = [9, 7, 3, 1, 9, 7, 3, 1];
724
+
725
+ for (var i = 0; i < 8; i++) {
726
+ sum += parseInt(value.charAt(i), 10) * weight[i];
727
+ }
728
+
729
+ return (sum % 10 === 0);
730
+ },
731
+
732
+ /**
733
+ * Validate Croatian VAT number
734
+ * Examples:
735
+ * - Valid: HR33392005961
736
+ * - Invalid: HR33392005962
737
+ *
738
+ * @param {String} value VAT number
739
+ * @returns {Boolean}
740
+ */
741
+ _hr: function(value) {
742
+ if (!/^HR[0-9]{11}$/.test(value)) {
743
+ return false;
744
+ }
745
+
746
+ value = value.substr(2);
747
+ return $.fn.bootstrapValidator.helpers.mod11And10(value);
748
+ },
749
+
750
+ /**
751
+ * Validate Irish VAT number
752
+ * Examples:
753
+ * - Valid: IE6433435F, IE6433435OA, IE8D79739I
754
+ * - Invalid: IE8D79738J
755
+ *
756
+ * @param {String} value VAT number
757
+ * @returns {Boolean}
758
+ */
759
+ _ie: function(value) {
760
+ if (!/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
761
+ return false;
762
+ }
763
+
764
+ value = value.substr(2);
765
+ var getCheckDigit = function(value) {
766
+ while (value.length < 7) {
767
+ value = '0' + value;
768
+ }
769
+ var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
770
+ sum = 0;
771
+ for (var i = 0; i < 7; i++) {
772
+ sum += parseInt(value.charAt(i), 10) * (8 - i);
773
+ }
774
+ sum += 9 * alphabet.indexOf(value.substr(7));
775
+ return alphabet[sum % 23];
776
+ };
777
+
778
+ // The first 7 characters are digits
779
+ if (/^[0-9]+$/.test(value.substr(0, 7))) {
780
+ // New system
781
+ return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
782
+ } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
783
+ // Old system
784
+ return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
785
+ }
786
+
787
+ return true;
788
+ },
789
+
790
+ /**
791
+ * Validate Italian VAT number, which consists of 11 digits.
792
+ * - First 7 digits are a company identifier
793
+ * - Next 3 are the province of residence
794
+ * - The last one is a check digit
795
+ *
796
+ * Examples:
797
+ * - Valid: IT00743110157
798
+ * - Invalid: IT00743110158
799
+ *
800
+ * @param {String} value VAT number
801
+ * @returns {Boolean}
802
+ */
803
+ _it: function(value) {
804
+ if (!/^IT[0-9]{11}$/.test(value)) {
805
+ return false;
806
+ }
807
+
808
+ value = value.substr(2);
809
+ if (parseInt(value.substr(0, 7), 10) === 0) {
810
+ return false;
811
+ }
812
+
813
+ var lastThree = parseInt(value.substr(7, 3), 10);
814
+ if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
815
+ return false;
816
+ }
817
+
818
+ return $.fn.bootstrapValidator.helpers.luhn(value);
819
+ },
820
+
821
+ /**
822
+ * Validate Lithuanian VAT number
823
+ * It can be:
824
+ * - 9 digits, for legal entities
825
+ * - 12 digits, for temporarily registered taxpayers
826
+ *
827
+ * Examples:
828
+ * - Valid: LT119511515, LT100001919017, LT100004801610
829
+ * - Invalid: LT100001919018
830
+ *
831
+ * @param {String} value VAT number
832
+ * @returns {Boolean}
833
+ */
834
+ _lt: function(value) {
835
+ if (!/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
836
+ return false;
837
+ }
838
+
839
+ value = value.substr(2);
840
+ var length = value.length,
841
+ sum = 0,
842
+ i;
843
+ for (i = 0; i < length - 1; i++) {
844
+ sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
845
+ }
846
+ var check = sum % 11;
847
+ if (check === 10) {
848
+ sum = 0;
849
+ for (i = 0; i < length - 1; i++) {
850
+ sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
851
+ }
852
+ }
853
+ check = check % 11 % 10;
854
+ return (check + '' === value.charAt(length - 1));
855
+ },
856
+
857
+ /**
858
+ * Validate Luxembourg VAT number
859
+ * Examples:
860
+ * - Valid: LU15027442
861
+ * - Invalid: LU15027443
862
+ *
863
+ * @param {String} value VAT number
864
+ * @returns {Boolean}
865
+ */
866
+ _lu: function(value) {
867
+ if (!/^LU[0-9]{8}$/.test(value)) {
868
+ return false;
869
+ }
870
+
871
+ value = value.substr(2);
872
+ return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
873
+ },
874
+
875
+ /**
876
+ * Validate Latvian VAT number
877
+ * Examples:
878
+ * - Valid: LV40003521600, LV16117519997
879
+ * - Invalid: LV40003521601, LV16137519997
880
+ *
881
+ * @param {String} value VAT number
882
+ * @returns {Boolean}
883
+ */
884
+ _lv: function(value) {
885
+ if (!/^LV[0-9]{11}$/.test(value)) {
886
+ return false;
887
+ }
888
+
889
+ value = value.substr(2);
890
+ var first = parseInt(value.charAt(0), 10),
891
+ sum = 0,
892
+ weight = [],
893
+ i,
894
+ length = value.length;
895
+ if (first > 3) {
896
+ // Legal entity
897
+ sum = 0;
898
+ weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
899
+ for (i = 0; i < length; i++) {
900
+ sum += parseInt(value.charAt(i), 10) * weight[i];
901
+ }
902
+ sum = sum % 11;
903
+ return (sum === 3);
904
+ } else {
905
+ // Check birth date
906
+ var day = parseInt(value.substr(0, 2), 10),
907
+ month = parseInt(value.substr(2, 2), 10),
908
+ year = parseInt(value.substr(4, 2), 10);
909
+ year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
910
+
911
+ if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
912
+ return false;
913
+ }
914
+
915
+ // Check personal code
916
+ sum = 0;
917
+ weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
918
+ for (i = 0; i < length - 1; i++) {
919
+ sum += parseInt(value.charAt(i), 10) * weight[i];
920
+ }
921
+ sum = (sum + 1) % 11 % 10;
922
+ return (sum + '' === value.charAt(length - 1));
923
+ }
924
+ },
925
+
926
+ /**
927
+ * Validate Maltese VAT number
928
+ * Examples:
929
+ * - Valid: MT11679112
930
+ * - Invalid: MT11679113
931
+ *
932
+ * @param {String} value VAT number
933
+ * @returns {Boolean}
934
+ */
935
+ _mt: function(value) {
936
+ if (!/^MT[0-9]{8}$/.test(value)) {
937
+ return false;
938
+ }
939
+
940
+ value = value.substr(2);
941
+ var sum = 0,
942
+ weight = [3, 4, 6, 7, 8, 9, 10, 1];
943
+
944
+ for (var i = 0; i < 8; i++) {
945
+ sum += parseInt(value.charAt(i), 10) * weight[i];
946
+ }
947
+
948
+ return (sum % 37 === 0);
949
+ },
950
+
951
+ /**
952
+ * Validate Dutch VAT number
953
+ * Examples:
954
+ * - Valid: NL004495445B01
955
+ * - Invalid: NL123456789B90
956
+ *
957
+ * @param {String} value VAT number
958
+ * @returns {Boolean}
959
+ */
960
+ _nl: function(value) {
961
+ if (!/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
962
+ return false;
963
+ }
964
+ value = value.substr(2);
965
+ var sum = 0,
966
+ weight = [9, 8, 7, 6, 5, 4, 3, 2];
967
+ for (var i = 0; i < 8; i++) {
968
+ sum += parseInt(value.charAt(i), 10) * weight[i];
969
+ }
970
+
971
+ sum = sum % 11;
972
+ if (sum > 9) {
973
+ sum = 0;
974
+ }
975
+ return (sum + '' === value.substr(8, 1));
976
+ },
977
+
978
+ /**
979
+ * Validate Norwegian VAT number
980
+ *
981
+ * @see http://www.brreg.no/english/coordination/number.html
982
+ * @param {String} value VAT number
983
+ * @returns {Boolean}
984
+ */
985
+ _no: function(value) {
986
+ if (!/^NO[0-9]{9}$/.test(value)) {
987
+ return false;
988
+ }
989
+ value = value.substr(2);
990
+ var sum = 0,
991
+ weight = [3, 2, 7, 6, 5, 4, 3, 2];
992
+ for (var i = 0; i < 8; i++) {
993
+ sum += parseInt(value.charAt(i), 10) * weight[i];
994
+ }
995
+
996
+ sum = 11 - sum % 11;
997
+ if (sum === 11) {
998
+ sum = 0;
999
+ }
1000
+ return (sum + '' === value.substr(8, 1));
1001
+ },
1002
+
1003
+ /**
1004
+ * Validate Polish VAT number
1005
+ * Examples:
1006
+ * - Valid: PL8567346215
1007
+ * - Invalid: PL8567346216
1008
+ *
1009
+ * @param {String} value VAT number
1010
+ * @returns {Boolean}
1011
+ */
1012
+ _pl: function(value) {
1013
+ if (!/^PL[0-9]{10}$/.test(value)) {
1014
+ return false;
1015
+ }
1016
+
1017
+ value = value.substr(2);
1018
+ var sum = 0,
1019
+ weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
1020
+
1021
+ for (var i = 0; i < 10; i++) {
1022
+ sum += parseInt(value.charAt(i), 10) * weight[i];
1023
+ }
1024
+
1025
+ return (sum % 11 === 0);
1026
+ },
1027
+
1028
+ /**
1029
+ * Validate Portuguese VAT number
1030
+ * Examples:
1031
+ * - Valid: PT501964843
1032
+ * - Invalid: PT501964842
1033
+ *
1034
+ * @param {String} value VAT number
1035
+ * @returns {Boolean}
1036
+ */
1037
+ _pt: function(value) {
1038
+ if (!/^PT[0-9]{9}$/.test(value)) {
1039
+ return false;
1040
+ }
1041
+
1042
+ value = value.substr(2);
1043
+ var sum = 0,
1044
+ weight = [9, 8, 7, 6, 5, 4, 3, 2];
1045
+
1046
+ for (var i = 0; i < 8; i++) {
1047
+ sum += parseInt(value.charAt(i), 10) * weight[i];
1048
+ }
1049
+ sum = 11 - sum % 11;
1050
+ if (sum > 9) {
1051
+ sum = 0;
1052
+ }
1053
+ return (sum + '' === value.substr(8, 1));
1054
+ },
1055
+
1056
+ /**
1057
+ * Validate Romanian VAT number
1058
+ * Examples:
1059
+ * - Valid: RO18547290
1060
+ * - Invalid: RO18547291
1061
+ *
1062
+ * @param {String} value VAT number
1063
+ * @returns {Boolean}
1064
+ */
1065
+ _ro: function(value) {
1066
+ if (!/^RO[1-9][0-9]{1,9}$/.test(value)) {
1067
+ return false;
1068
+ }
1069
+ value = value.substr(2);
1070
+
1071
+ var length = value.length,
1072
+ weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
1073
+ sum = 0;
1074
+ for (var i = 0; i < length - 1; i++) {
1075
+ sum += parseInt(value.charAt(i), 10) * weight[i];
1076
+ }
1077
+
1078
+ sum = (10 * sum) % 11 % 10;
1079
+ return (sum + '' === value.substr(length - 1, 1));
1080
+ },
1081
+
1082
+ /**
1083
+ * Validate Russian VAT number (Taxpayer Identification Number - INN)
1084
+ *
1085
+ * @param {String} value VAT number
1086
+ * @returns {Boolean}
1087
+ */
1088
+ _ru: function(value) {
1089
+ if (!/^RU([0-9]{9}|[0-9]{12})$/.test(value)) {
1090
+ return false;
1091
+ }
1092
+
1093
+ value = value.substr(2);
1094
+ var i = 0;
1095
+ if (value.length === 10) {
1096
+ var sum = 0,
1097
+ weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
1098
+ for (i = 0; i < 10; i++) {
1099
+ sum += parseInt(value.charAt(i), 10) * weight[i];
1100
+ }
1101
+ sum = sum % 11;
1102
+ if (sum > 9) {
1103
+ sum = sum % 10;
1104
+ }
1105
+
1106
+ return (sum + '' === value.substr(9, 1));
1107
+ } else if (value.length === 12) {
1108
+ var sum1 = 0,
1109
+ weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
1110
+ sum2 = 0,
1111
+ weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
1112
+
1113
+ for (i = 0; i < 11; i++) {
1114
+ sum1 += parseInt(value.charAt(i), 10) * weight1[i];
1115
+ sum2 += parseInt(value.charAt(i), 10) * weight2[i];
1116
+ }
1117
+ sum1 = sum1 % 11;
1118
+ if (sum1 > 9) {
1119
+ sum1 = sum1 % 10;
1120
+ }
1121
+ sum2 = sum2 % 11;
1122
+ if (sum2 > 9) {
1123
+ sum2 = sum2 % 10;
1124
+ }
1125
+
1126
+ return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
1127
+ }
1128
+
1129
+ return false;
1130
+ },
1131
+
1132
+ /**
1133
+ * Validate Serbian VAT number
1134
+ *
1135
+ * @param {String} value VAT number
1136
+ * @returns {Boolean}
1137
+ */
1138
+ _rs: function(value) {
1139
+ if (!/^RS[0-9]{9}$/.test(value)) {
1140
+ return false;
1141
+ }
1142
+
1143
+ value = value.substr(2);
1144
+ var sum = 10,
1145
+ temp = 0;
1146
+ for (var i = 0; i < 8; i++) {
1147
+ temp = (parseInt(value.charAt(i), 10) + sum) % 10;
1148
+ if (temp === 0) {
1149
+ temp = 10;
1150
+ }
1151
+ sum = (2 * temp) % 11;
1152
+ }
1153
+
1154
+ return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
1155
+ },
1156
+
1157
+ /**
1158
+ * Validate Swedish VAT number
1159
+ * Examples:
1160
+ * - Valid: SE123456789701
1161
+ * - Invalid: SE123456789101
1162
+ *
1163
+ * @param {String} value VAT number
1164
+ * @returns {Boolean}
1165
+ */
1166
+ _se: function(value) {
1167
+ if (!/^SE[0-9]{10}01$/.test(value)) {
1168
+ return false;
1169
+ }
1170
+
1171
+ value = value.substr(2, 10);
1172
+ return $.fn.bootstrapValidator.helpers.luhn(value);
1173
+ },
1174
+
1175
+ /**
1176
+ * Validate Slovenian VAT number
1177
+ * Examples:
1178
+ * - Valid: SI50223054
1179
+ * - Invalid: SI50223055
1180
+ *
1181
+ * @param {String} value VAT number
1182
+ * @returns {Boolean}
1183
+ */
1184
+ _si: function(value) {
1185
+ if (!/^SI[0-9]{8}$/.test(value)) {
1186
+ return false;
1187
+ }
1188
+
1189
+ value = value.substr(2);
1190
+ var sum = 0,
1191
+ weight = [8, 7, 6, 5, 4, 3, 2];
1192
+
1193
+ for (var i = 0; i < 7; i++) {
1194
+ sum += parseInt(value.charAt(i), 10) * weight[i];
1195
+ }
1196
+ sum = 11 - sum % 11;
1197
+ if (sum === 10) {
1198
+ sum = 0;
1199
+ }
1200
+ return (sum + '' === value.substr(7, 1));
1201
+ },
1202
+
1203
+ /**
1204
+ * Validate Slovak VAT number
1205
+ * Examples:
1206
+ * - Valid: SK2022749619
1207
+ * - Invalid: SK2022749618
1208
+ *
1209
+ * @param {String} value VAT number
1210
+ * @returns {Boolean}
1211
+ */
1212
+ _sk: function(value) {
1213
+ if (!/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
1214
+ return false;
1215
+ }
1216
+
1217
+ return (parseInt(value.substr(2), 10) % 11 === 0);
1218
+ }
1219
+ };
1220
+ }(window.jQuery));