bootstrap_validator_rails 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +32 -0
  4. data/lib/bootstrap_validator_rails/engine.rb +4 -0
  5. data/lib/bootstrap_validator_rails/version.rb +3 -0
  6. data/lib/bootstrap_validator_rails.rb +42 -0
  7. data/lib/tasks/bootstrap_validator_rails_tasks.rake +4 -0
  8. data/test/bootstrap_validator_rails_test.rb +13 -0
  9. data/test/dummy/README.rdoc +28 -0
  10. data/test/dummy/Rakefile +6 -0
  11. data/test/dummy/app/assets/javascripts/application.js +13 -0
  12. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  13. data/test/dummy/app/controllers/application_controller.rb +5 -0
  14. data/test/dummy/app/helpers/application_helper.rb +2 -0
  15. data/test/dummy/app/models/post.rb +3 -0
  16. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  17. data/test/dummy/bin/bundle +3 -0
  18. data/test/dummy/bin/rails +4 -0
  19. data/test/dummy/bin/rake +4 -0
  20. data/test/dummy/config/application.rb +23 -0
  21. data/test/dummy/config/boot.rb +5 -0
  22. data/test/dummy/config/database.yml +25 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +37 -0
  25. data/test/dummy/config/environments/production.rb +82 -0
  26. data/test/dummy/config/environments/test.rb +39 -0
  27. data/test/dummy/config/initializers/assets.rb +8 -0
  28. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  30. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  31. data/test/dummy/config/initializers/inflections.rb +16 -0
  32. data/test/dummy/config/initializers/mime_types.rb +4 -0
  33. data/test/dummy/config/initializers/session_store.rb +3 -0
  34. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/test/dummy/config/locales/en.yml +23 -0
  36. data/test/dummy/config/routes.rb +56 -0
  37. data/test/dummy/config/secrets.yml +22 -0
  38. data/test/dummy/config.ru +4 -0
  39. data/test/dummy/db/development.sqlite3 +0 -0
  40. data/test/dummy/db/migrate/20140723124112_create_posts.rb +7 -0
  41. data/test/dummy/db/schema.rb +20 -0
  42. data/test/dummy/db/test.sqlite3 +0 -0
  43. data/test/dummy/log/ENV=test.log +0 -0
  44. data/test/dummy/log/development.log +22 -0
  45. data/test/dummy/log/test.log +781 -0
  46. data/test/dummy/public/404.html +67 -0
  47. data/test/dummy/public/422.html +67 -0
  48. data/test/dummy/public/500.html +66 -0
  49. data/test/dummy/public/favicon.ico +0 -0
  50. data/test/test_helper.rb +15 -0
  51. data/vendor/assets/javascripts/bootstrapValidator.js +1803 -0
  52. data/vendor/assets/javascripts/language/de_DE.js +326 -0
  53. data/vendor/assets/javascripts/language/en_US.js +327 -0
  54. data/vendor/assets/javascripts/language/es_CL.js +326 -0
  55. data/vendor/assets/javascripts/language/hu_HU.js +326 -0
  56. data/vendor/assets/javascripts/language/vi_VN.js +322 -0
  57. data/vendor/assets/javascripts/language/zh_CN.js +326 -0
  58. data/vendor/assets/javascripts/language/zh_TW.js +326 -0
  59. data/vendor/assets/javascripts/validator/base64.js +25 -0
  60. data/vendor/assets/javascripts/validator/between.js +66 -0
  61. data/vendor/assets/javascripts/validator/callback.js +40 -0
  62. data/vendor/assets/javascripts/validator/choice.js +68 -0
  63. data/vendor/assets/javascripts/validator/creditCard.js +103 -0
  64. data/vendor/assets/javascripts/validator/cusip.js +55 -0
  65. data/vendor/assets/javascripts/validator/cvv.js +116 -0
  66. data/vendor/assets/javascripts/validator/date.js +118 -0
  67. data/vendor/assets/javascripts/validator/different.js +41 -0
  68. data/vendor/assets/javascripts/validator/digits.js +24 -0
  69. data/vendor/assets/javascripts/validator/ean.js +40 -0
  70. data/vendor/assets/javascripts/validator/emailAddress.js +31 -0
  71. data/vendor/assets/javascripts/validator/file.js +69 -0
  72. data/vendor/assets/javascripts/validator/greaterThan.js +61 -0
  73. data/vendor/assets/javascripts/validator/grid.js +37 -0
  74. data/vendor/assets/javascripts/validator/hex.js +25 -0
  75. data/vendor/assets/javascripts/validator/hexColor.js +28 -0
  76. data/vendor/assets/javascripts/validator/iban.js +246 -0
  77. data/vendor/assets/javascripts/validator/id.js +815 -0
  78. data/vendor/assets/javascripts/validator/identical.js +40 -0
  79. data/vendor/assets/javascripts/validator/imei.js +44 -0
  80. data/vendor/assets/javascripts/validator/integer.js +28 -0
  81. data/vendor/assets/javascripts/validator/ip.js +48 -0
  82. data/vendor/assets/javascripts/validator/isbn.js +86 -0
  83. data/vendor/assets/javascripts/validator/isin.js +59 -0
  84. data/vendor/assets/javascripts/validator/ismn.js +59 -0
  85. data/vendor/assets/javascripts/validator/issn.js +46 -0
  86. data/vendor/assets/javascripts/validator/lessThan.js +61 -0
  87. data/vendor/assets/javascripts/validator/mac.js +25 -0
  88. data/vendor/assets/javascripts/validator/notEmpty.js +32 -0
  89. data/vendor/assets/javascripts/validator/numeric.js +39 -0
  90. data/vendor/assets/javascripts/validator/phone.js +84 -0
  91. data/vendor/assets/javascripts/validator/regexp.js +42 -0
  92. data/vendor/assets/javascripts/validator/remote.js +70 -0
  93. data/vendor/assets/javascripts/validator/rtn.js +38 -0
  94. data/vendor/assets/javascripts/validator/sedol.js +40 -0
  95. data/vendor/assets/javascripts/validator/siren.js +28 -0
  96. data/vendor/assets/javascripts/validator/siret.js +38 -0
  97. data/vendor/assets/javascripts/validator/step.js +64 -0
  98. data/vendor/assets/javascripts/validator/stringCase.js +36 -0
  99. data/vendor/assets/javascripts/validator/stringLength.js +81 -0
  100. data/vendor/assets/javascripts/validator/uri.js +101 -0
  101. data/vendor/assets/javascripts/validator/uuid.js +46 -0
  102. data/vendor/assets/javascripts/validator/vat.js +1220 -0
  103. data/vendor/assets/javascripts/validator/vin.js +49 -0
  104. data/vendor/assets/javascripts/validator/zipCode.js +162 -0
  105. data/vendor/assets/stylesheets/bootstrapValidator.css +21 -0
  106. metadata +233 -0
@@ -0,0 +1,40 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
3
+ 'default': 'Please enter the same value'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.identical = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ field: 'field'
10
+ },
11
+
12
+ /**
13
+ * Check if input value equals to value of particular one
14
+ *
15
+ * @param {BootstrapValidator} validator The validator plugin instance
16
+ * @param {jQuery} $field Field element
17
+ * @param {Object} options Consists of the following key:
18
+ * - field: The name of field that will be used to compare with current one
19
+ * @returns {Boolean}
20
+ */
21
+ validate: function(validator, $field, options) {
22
+ var value = $field.val();
23
+ if (value === '') {
24
+ return true;
25
+ }
26
+
27
+ var compareWith = validator.getFieldElements(options.field);
28
+ if (compareWith === null) {
29
+ return true;
30
+ }
31
+
32
+ if (value === compareWith.val()) {
33
+ validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
34
+ return true;
35
+ } else {
36
+ return false;
37
+ }
38
+ }
39
+ };
40
+ }(window.jQuery));
@@ -0,0 +1,44 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.imei = $.extend($.fn.bootstrapValidator.i18n.imei || {}, {
3
+ 'default': 'Please enter a valid IMEI number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.imei = {
7
+ /**
8
+ * Validate IMEI (International Mobile Station Equipment Identity)
9
+ * Examples:
10
+ * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
11
+ * - Invalid: 490154203237517
12
+ *
13
+ * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
14
+ * @param {BootstrapValidator} validator The validator plugin instance
15
+ * @param {jQuery} $field Field element
16
+ * @param {Object} options Can consist of the following keys:
17
+ * - message: The invalid message
18
+ * @returns {Boolean}
19
+ */
20
+ validate: function(validator, $field, options) {
21
+ var value = $field.val();
22
+ if (value === '') {
23
+ return true;
24
+ }
25
+
26
+ switch (true) {
27
+ case /^\d{15}$/.test(value):
28
+ case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
29
+ case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
30
+ value = value.replace(/[^0-9]/g, '');
31
+ return $.fn.bootstrapValidator.helpers.luhn(value);
32
+
33
+ case /^\d{14}$/.test(value):
34
+ case /^\d{16}$/.test(value):
35
+ case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
36
+ case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
37
+ return true;
38
+
39
+ default:
40
+ return false;
41
+ }
42
+ }
43
+ };
44
+ }(window.jQuery));
@@ -0,0 +1,28 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.integer = $.extend($.fn.bootstrapValidator.i18n.integer || {}, {
3
+ 'default': 'Please enter a valid number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.integer = {
7
+ enableByHtml5: function($field) {
8
+ return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
9
+ },
10
+
11
+ /**
12
+ * Return true if the input value is an integer
13
+ *
14
+ * @param {BootstrapValidator} validator The validator plugin instance
15
+ * @param {jQuery} $field Field element
16
+ * @param {Object} options Can consist of the following key:
17
+ * - message: The invalid message
18
+ * @returns {Boolean}
19
+ */
20
+ validate: function(validator, $field, options) {
21
+ var value = $field.val();
22
+ if (value === '') {
23
+ return true;
24
+ }
25
+ return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
26
+ }
27
+ };
28
+ }(window.jQuery));
@@ -0,0 +1,48 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.ip = $.extend($.fn.bootstrapValidator.i18n.ip || {}, {
3
+ 'default': 'Please enter a valid IP address',
4
+ ipv4: 'Please enter a valid IPv4 address',
5
+ ipv6: 'Please enter a valid IPv6 address'
6
+ });
7
+
8
+ $.fn.bootstrapValidator.validators.ip = {
9
+ html5Attributes: {
10
+ message: 'message',
11
+ ipv4: 'ipv4',
12
+ ipv6: 'ipv6'
13
+ },
14
+
15
+ /**
16
+ * Return true if the input value is a IP address.
17
+ *
18
+ * @param {BootstrapValidator} validator The validator plugin instance
19
+ * @param {jQuery} $field Field element
20
+ * @param {Object} options Can consist of the following keys:
21
+ * - ipv4: Enable IPv4 validator, default to true
22
+ * - ipv6: Enable IPv6 validator, default to true
23
+ * - message: The invalid message
24
+ * @returns {Boolean|Object}
25
+ */
26
+ validate: function(validator, $field, options) {
27
+ var value = $field.val();
28
+ if (value === '') {
29
+ return true;
30
+ }
31
+ options = $.extend({}, { ipv4: true, ipv6: true }, options);
32
+
33
+ if (options.ipv4) {
34
+ return {
35
+ valid: /^(?:(?: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),
36
+ message: options.message || $.fn.bootstrapValidator.i18n.ip.ipv4
37
+ };
38
+ } else if (options.ipv6) {
39
+ return {
40
+ valid: /^\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(value),
41
+ message: options.message || $.fn.bootstrapValidator.i18n.ip.ipv6
42
+ };
43
+ }
44
+
45
+ return false;
46
+ }
47
+ };
48
+ }(window.jQuery));
@@ -0,0 +1,86 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.isbn = $.extend($.fn.bootstrapValidator.i18n.isbn || {}, {
3
+ 'default': 'Please enter a valid ISBN number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.isbn = {
7
+ /**
8
+ * Return true if the input value is a valid ISBN 10 or ISBN 13 number
9
+ * Examples:
10
+ * - Valid:
11
+ * ISBN 10: 99921-58-10-7, 9971-5-0210-0, 960-425-059-0, 80-902734-1-6, 85-359-0277-5, 1-84356-028-3, 0-684-84328-5, 0-8044-2957-X, 0-85131-041-9, 0-943396-04-2, 0-9752298-0-X
12
+ * ISBN 13: 978-0-306-40615-7
13
+ * - Invalid:
14
+ * ISBN 10: 99921-58-10-6
15
+ * ISBN 13: 978-0-306-40615-6
16
+ *
17
+ * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
18
+ * @param {BootstrapValidator} validator The validator plugin instance
19
+ * @param {jQuery} $field Field element
20
+ * @param {Object} [options] Can consist of the following keys:
21
+ * - message: The invalid message
22
+ * @returns {Boolean}
23
+ */
24
+ validate: function(validator, $field, options) {
25
+ var value = $field.val();
26
+ if (value === '') {
27
+ return true;
28
+ }
29
+
30
+ // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
31
+ // Groups are separated by a hyphen or a space
32
+ var type;
33
+ switch (true) {
34
+ case /^\d{9}[\dX]$/.test(value):
35
+ case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
36
+ case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
37
+ type = 'ISBN10';
38
+ break;
39
+ case /^(978|979)\d{9}[\dX]$/.test(value):
40
+ case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
41
+ case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
42
+ type = 'ISBN13';
43
+ break;
44
+ default:
45
+ return false;
46
+ }
47
+
48
+ // Replace all special characters except digits and X
49
+ value = value.replace(/[^0-9X]/gi, '');
50
+ var chars = value.split(''),
51
+ length = chars.length,
52
+ sum = 0,
53
+ i,
54
+ checksum;
55
+
56
+ switch (type) {
57
+ case 'ISBN10':
58
+ sum = 0;
59
+ for (i = 0; i < length - 1; i++) {
60
+ sum += parseInt(chars[i], 10) * (10 - i);
61
+ }
62
+ checksum = 11 - (sum % 11);
63
+ if (checksum === 11) {
64
+ checksum = 0;
65
+ } else if (checksum === 10) {
66
+ checksum = 'X';
67
+ }
68
+ return (checksum + '' === chars[length - 1]);
69
+
70
+ case 'ISBN13':
71
+ sum = 0;
72
+ for (i = 0; i < length - 1; i++) {
73
+ sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
74
+ }
75
+ checksum = 10 - (sum % 10);
76
+ if (checksum === 10) {
77
+ checksum = '0';
78
+ }
79
+ return (checksum + '' === chars[length - 1]);
80
+
81
+ default:
82
+ return false;
83
+ }
84
+ }
85
+ };
86
+ }(window.jQuery));
@@ -0,0 +1,59 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.isin = $.extend($.fn.bootstrapValidator.i18n.isin || {}, {
3
+ 'default': 'Please enter a valid ISIN number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.isin = {
7
+ // Available country codes
8
+ // See http://isin.net/country-codes/
9
+ COUNTRY_CODES: 'AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW',
10
+
11
+ /**
12
+ * Validate an ISIN (International Securities Identification Number)
13
+ * Examples:
14
+ * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
15
+ * - Invalid: US0378331004, AA0000XVGZA3
16
+ *
17
+ * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
18
+ * @param {BootstrapValidator} validator The validator plugin instance
19
+ * @param {jQuery} $field Field element
20
+ * @param {Object} options Can consist of the following keys:
21
+ * - message: The invalid message
22
+ * @returns {Boolean}
23
+ */
24
+ validate: function(validator, $field, options) {
25
+ var value = $field.val();
26
+ if (value === '') {
27
+ return true;
28
+ }
29
+
30
+ value = value.toUpperCase();
31
+ var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
32
+ if (!regex.test(value)) {
33
+ return false;
34
+ }
35
+
36
+ var converted = '',
37
+ length = value.length;
38
+ // Convert letters to number
39
+ for (var i = 0; i < length - 1; i++) {
40
+ var c = value.charCodeAt(i);
41
+ converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
42
+ }
43
+
44
+ var digits = '',
45
+ n = converted.length,
46
+ group = (n % 2 !== 0) ? 0 : 1;
47
+ for (i = 0; i < n; i++) {
48
+ digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
49
+ }
50
+
51
+ var sum = 0;
52
+ for (i = 0; i < digits.length; i++) {
53
+ sum += parseInt(digits.charAt(i), 10);
54
+ }
55
+ sum = (10 - (sum % 10)) % 10;
56
+ return sum + '' === value.charAt(length - 1);
57
+ }
58
+ };
59
+ }(window.jQuery));
@@ -0,0 +1,59 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.ismn = $.extend($.fn.bootstrapValidator.i18n.ismn || {}, {
3
+ 'default': 'Please enter a valid ISMN number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.ismn = {
7
+ /**
8
+ * Validate ISMN (International Standard Music Number)
9
+ * Examples:
10
+ * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
11
+ * - Invalid: 9790060115614
12
+ *
13
+ * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
14
+ * @param {BootstrapValidator} validator The validator plugin instance
15
+ * @param {jQuery} $field Field element
16
+ * @param {Object} options Can consist of the following keys:
17
+ * - message: The invalid message
18
+ * @returns {Boolean}
19
+ */
20
+ validate: function(validator, $field, options) {
21
+ var value = $field.val();
22
+ if (value === '') {
23
+ return true;
24
+ }
25
+
26
+ // Groups are separated by a hyphen or a space
27
+ var type;
28
+ switch (true) {
29
+ case /^M\d{9}$/.test(value):
30
+ case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
31
+ case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
32
+ type = 'ISMN10';
33
+ break;
34
+ case /^9790\d{9}$/.test(value):
35
+ case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
36
+ case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
37
+ type = 'ISMN13';
38
+ break;
39
+ default:
40
+ return false;
41
+ }
42
+
43
+ if ('ISMN10' === type) {
44
+ value = '9790' + value.substr(1);
45
+ }
46
+
47
+ // Replace all special characters except digits
48
+ value = value.replace(/[^0-9]/gi, '');
49
+ var length = value.length,
50
+ sum = 0,
51
+ weight = [1, 3];
52
+ for (var i = 0; i < length - 1; i++) {
53
+ sum += parseInt(value.charAt(i), 10) * weight[i % 2];
54
+ }
55
+ sum = 10 - sum % 10;
56
+ return (sum + '' === value.charAt(length - 1));
57
+ }
58
+ };
59
+ }(window.jQuery));
@@ -0,0 +1,46 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.issn = $.extend($.fn.bootstrapValidator.i18n.issn || {}, {
3
+ 'default': 'Please enter a valid ISSN number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.issn = {
7
+ /**
8
+ * Validate ISSN (International Standard Serial Number)
9
+ * Examples:
10
+ * - Valid: 0378-5955, 0024-9319, 0032-1478
11
+ * - Invalid: 0032-147X
12
+ *
13
+ * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
14
+ * @param {BootstrapValidator} validator The validator plugin instance
15
+ * @param {jQuery} $field Field element
16
+ * @param {Object} options Can consist of the following keys:
17
+ * - message: The invalid message
18
+ * @returns {Boolean}
19
+ */
20
+ validate: function(validator, $field, options) {
21
+ var value = $field.val();
22
+ if (value === '') {
23
+ return true;
24
+ }
25
+
26
+ // Groups are separated by a hyphen or a space
27
+ if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
28
+ return false;
29
+ }
30
+
31
+ // Replace all special characters except digits and X
32
+ value = value.replace(/[^0-9X]/gi, '');
33
+ var chars = value.split(''),
34
+ length = chars.length,
35
+ sum = 0;
36
+
37
+ if (chars[7] === 'X') {
38
+ chars[7] = 10;
39
+ }
40
+ for (var i = 0; i < length; i++) {
41
+ sum += parseInt(chars[i], 10) * (8 - i);
42
+ }
43
+ return (sum % 11 === 0);
44
+ }
45
+ };
46
+ }(window.jQuery));
@@ -0,0 +1,61 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.lessThan = $.extend($.fn.bootstrapValidator.i18n.lessThan || {}, {
3
+ 'default': 'Please enter a value less than or equal to %s',
4
+ notInclusive: 'Please enter a value less than %s'
5
+ });
6
+
7
+ $.fn.bootstrapValidator.validators.lessThan = {
8
+ html5Attributes: {
9
+ message: 'message',
10
+ value: 'value',
11
+ inclusive: 'inclusive'
12
+ },
13
+
14
+ enableByHtml5: function($field) {
15
+ var max = $field.attr('max');
16
+ if (max) {
17
+ return {
18
+ value: max
19
+ };
20
+ }
21
+
22
+ return false;
23
+ },
24
+
25
+ /**
26
+ * Return true if the input value is less than or equal to given number
27
+ *
28
+ * @param {BootstrapValidator} validator The validator plugin instance
29
+ * @param {jQuery} $field Field element
30
+ * @param {Object} options Can consist of the following keys:
31
+ * - value: The number used to compare to. It can be
32
+ * - A number
33
+ * - Name of field which its value defines the number
34
+ * - Name of callback function that returns the number
35
+ * - A callback function that returns the number
36
+ *
37
+ * - inclusive [optional]: Can be true or false. Default is true
38
+ * - message: The invalid message
39
+ * @returns {Boolean|Object}
40
+ */
41
+ validate: function(validator, $field, options) {
42
+ var value = $field.val();
43
+ if (value === '') {
44
+ return true;
45
+ }
46
+
47
+ var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
48
+
49
+ value = parseFloat(value);
50
+ return (options.inclusive === true || options.inclusive === undefined)
51
+ ? {
52
+ valid: value <= compareTo,
53
+ message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan['default'], compareTo)
54
+ }
55
+ : {
56
+ valid: value < compareTo,
57
+ message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan.notInclusive, compareTo)
58
+ };
59
+ }
60
+ };
61
+ }(window.jQuery));
@@ -0,0 +1,25 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.mac = $.extend($.fn.bootstrapValidator.i18n.mac || {}, {
3
+ 'default': 'Please enter a valid MAC address'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.mac = {
7
+ /**
8
+ * Return true if the input value is a MAC address.
9
+ *
10
+ * @param {BootstrapValidator} validator The validator plugin instance
11
+ * @param {jQuery} $field Field element
12
+ * @param {Object} options Can consist of the following keys:
13
+ * - message: The invalid message
14
+ * @returns {Boolean}
15
+ */
16
+ validate: function(validator, $field, options) {
17
+ var value = $field.val();
18
+ if (value === '') {
19
+ return true;
20
+ }
21
+
22
+ return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
23
+ }
24
+ };
25
+ }(window.jQuery));
@@ -0,0 +1,32 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.notEmpty = $.extend($.fn.bootstrapValidator.i18n.notEmpty || {}, {
3
+ 'default': 'Please enter a value'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.notEmpty = {
7
+ enableByHtml5: function($field) {
8
+ var required = $field.attr('required') + '';
9
+ return ('required' === required || 'true' === required);
10
+ },
11
+
12
+ /**
13
+ * Check if input value is empty or not
14
+ *
15
+ * @param {BootstrapValidator} validator The validator plugin instance
16
+ * @param {jQuery} $field Field element
17
+ * @param {Object} options
18
+ * @returns {Boolean}
19
+ */
20
+ validate: function(validator, $field, options) {
21
+ var type = $field.attr('type');
22
+ if ('radio' === type || 'checkbox' === type) {
23
+ return validator
24
+ .getFieldElements($field.attr('data-bv-field'))
25
+ .filter(':checked')
26
+ .length > 0;
27
+ }
28
+
29
+ return $.trim($field.val()) !== '';
30
+ }
31
+ };
32
+ }(window.jQuery));
@@ -0,0 +1,39 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.numeric = $.extend($.fn.bootstrapValidator.i18n.numeric || {}, {
3
+ 'default': 'Please enter a valid float number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.numeric = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ separator: 'separator'
10
+ },
11
+
12
+ enableByHtml5: function($field) {
13
+ return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
14
+ },
15
+
16
+ /**
17
+ * Validate decimal number
18
+ *
19
+ * @param {BootstrapValidator} validator The validator plugin instance
20
+ * @param {jQuery} $field Field element
21
+ * @param {Object} options Consist of key:
22
+ * - message: The invalid message
23
+ * - separator: The decimal separator. Can be "." (default), ","
24
+ * @returns {Boolean}
25
+ */
26
+ validate: function(validator, $field, options) {
27
+ var value = $field.val();
28
+ if (value === '') {
29
+ return true;
30
+ }
31
+ var separator = options.separator || '.';
32
+ if (separator !== '.') {
33
+ value = value.replace(separator, '.');
34
+ }
35
+
36
+ return !isNaN(parseFloat(value)) && isFinite(value);
37
+ }
38
+ };
39
+ }(window.jQuery));
@@ -0,0 +1,84 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.phone = $.extend($.fn.bootstrapValidator.i18n.phone || {}, {
3
+ 'default': 'Please enter a valid phone number',
4
+ countryNotSupported: 'The country code %s is not supported',
5
+ country: 'Please enter a valid phone number in %s',
6
+ countries: {
7
+ GB: 'United Kingdom',
8
+ US: 'USA'
9
+ }
10
+ });
11
+
12
+ $.fn.bootstrapValidator.validators.phone = {
13
+ html5Attributes: {
14
+ message: 'message',
15
+ country: 'country'
16
+ },
17
+
18
+ // The supported countries
19
+ COUNTRY_CODES: ['GB', 'US'],
20
+
21
+ /**
22
+ * Return true if the input value contains a valid phone number for the country
23
+ * selected in the options
24
+ *
25
+ * @param {BootstrapValidator} validator Validate plugin instance
26
+ * @param {jQuery} $field Field element
27
+ * @param {Object} options Consist of key:
28
+ * - message: The invalid message
29
+ * - country: The ISO-3166 country code. It can be
30
+ * - A country code
31
+ * - Name of field which its value defines the country code
32
+ * - Name of callback function that returns the country code
33
+ * - A callback function that returns the country code
34
+ *
35
+ * Currently it only supports United State (US) or United Kingdom (GB) countries
36
+ * @returns {Boolean|Object}
37
+ */
38
+ validate: function(validator, $field, options) {
39
+ var value = $field.val();
40
+ if (value === '') {
41
+ return true;
42
+ }
43
+
44
+ var country = options.country;
45
+ if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
46
+ // Try to determine the country
47
+ country = validator.getDynamicOption($field, country);
48
+ }
49
+
50
+ if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
51
+ return {
52
+ valid: false,
53
+ message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.phone.countryNotSupported, country)
54
+ };
55
+ }
56
+
57
+ var isValid = true;
58
+ switch (country.toUpperCase()) {
59
+ case 'GB':
60
+ // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
61
+ // Test: http://regexr.com/38uhv
62
+ value = $.trim(value);
63
+ isValid = (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
64
+ break;
65
+
66
+ case 'US':
67
+ /* falls through */
68
+ default:
69
+ // Make sure US phone numbers have 10 digits
70
+ // May start with 1, +1, or 1-; should discard
71
+ // Area code may be delimited with (), & sections may be delimited with . or -
72
+ // Test: http://regexr.com/38mqi
73
+ value = value.replace(/\D/g, '');
74
+ isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length === 10);
75
+ break;
76
+ }
77
+
78
+ return {
79
+ valid: isValid,
80
+ message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.phone.country, $.fn.bootstrapValidator.i18n.phone.countries[country])
81
+ };
82
+ }
83
+ };
84
+ }(window.jQuery));