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,42 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.regexp = $.extend($.fn.bootstrapValidator.i18n.regexp || {}, {
3
+ 'default': 'Please enter a value matching the pattern'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.regexp = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ regexp: 'regexp'
10
+ },
11
+
12
+ enableByHtml5: function($field) {
13
+ var pattern = $field.attr('pattern');
14
+ if (pattern) {
15
+ return {
16
+ regexp: pattern
17
+ };
18
+ }
19
+
20
+ return false;
21
+ },
22
+
23
+ /**
24
+ * Check if the element value matches given regular expression
25
+ *
26
+ * @param {BootstrapValidator} validator The validator plugin instance
27
+ * @param {jQuery} $field Field element
28
+ * @param {Object} options Consists of the following key:
29
+ * - regexp: The regular expression you need to check
30
+ * @returns {Boolean}
31
+ */
32
+ validate: function(validator, $field, options) {
33
+ var value = $field.val();
34
+ if (value === '') {
35
+ return true;
36
+ }
37
+
38
+ var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
39
+ return regexp.test(value);
40
+ }
41
+ };
42
+ }(window.jQuery));
@@ -0,0 +1,70 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.remote = $.extend($.fn.bootstrapValidator.i18n.remote || {}, {
3
+ 'default': 'Please enter a valid value'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.remote = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ url: 'url',
10
+ name: 'name'
11
+ },
12
+
13
+ /**
14
+ * Request a remote server to check the input value
15
+ *
16
+ * @param {BootstrapValidator} validator Plugin instance
17
+ * @param {jQuery} $field Field element
18
+ * @param {Object} options Can consist of the following keys:
19
+ * - url {String|Function}
20
+ * - type {String} [optional] Can be GET or POST (default)
21
+ * - data {Object|Function} [optional]: By default, it will take the value
22
+ * {
23
+ * <fieldName>: <fieldValue>
24
+ * }
25
+ * - name {String} [optional]: Override the field name for the request.
26
+ * - message: The invalid message
27
+ * @returns {Boolean|Deferred}
28
+ */
29
+ validate: function(validator, $field, options) {
30
+ var value = $field.val();
31
+ if (value === '') {
32
+ return true;
33
+ }
34
+
35
+ var name = $field.attr('data-bv-field'),
36
+ data = options.data || {},
37
+ url = options.url,
38
+ type = options.type || 'POST';
39
+
40
+ // Support dynamic data
41
+ if ('function' === typeof data) {
42
+ data = data.call(this, validator);
43
+ }
44
+
45
+ // Support dynamic url
46
+ if ('function' === typeof url) {
47
+ url = url.call(this, validator);
48
+ }
49
+
50
+ data[options.name || name] = value;
51
+
52
+ var dfd = new $.Deferred();
53
+ var xhr = $.ajax({
54
+ type: type,
55
+ url: url,
56
+ dataType: 'json',
57
+ data: data
58
+ });
59
+ xhr.then(function(response) {
60
+ dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true', response.message ? response.message : null);
61
+ });
62
+
63
+ dfd.fail(function() {
64
+ xhr.abort();
65
+ });
66
+
67
+ return dfd;
68
+ }
69
+ };
70
+ }(window.jQuery));
@@ -0,0 +1,38 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.rtn = $.extend($.fn.bootstrapValidator.i18n.rtn || {}, {
3
+ 'default': 'Please enter a valid RTN number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.rtn = {
7
+ /**
8
+ * Validate a RTN (Routing transit number)
9
+ * Examples:
10
+ * - Valid: 021200025, 789456124
11
+ *
12
+ * @see http://en.wikipedia.org/wiki/Routing_transit_number
13
+ * @param {BootstrapValidator} validator The validator plugin instance
14
+ * @param {jQuery} $field Field element
15
+ * @param {Object} options Can consist of the following keys:
16
+ * - message: The invalid message
17
+ * @returns {Boolean}
18
+ */
19
+ validate: function(validator, $field, options) {
20
+ var value = $field.val();
21
+ if (value === '') {
22
+ return true;
23
+ }
24
+
25
+ if (!/^\d{9}$/.test(value)) {
26
+ return false;
27
+ }
28
+
29
+ var sum = 0;
30
+ for (var i = 0; i < value.length; i += 3) {
31
+ sum += parseInt(value.charAt(i), 10) * 3
32
+ + parseInt(value.charAt(i + 1), 10) * 7
33
+ + parseInt(value.charAt(i + 2), 10);
34
+ }
35
+ return (sum !== 0 && sum % 10 === 0);
36
+ }
37
+ };
38
+ }(window.jQuery));
@@ -0,0 +1,40 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.sedol = $.extend($.fn.bootstrapValidator.i18n.sedol || {}, {
3
+ 'default': 'Please enter a valid SEDOL number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.sedol = {
7
+ /**
8
+ * Validate a SEDOL (Stock Exchange Daily Official List)
9
+ * Examples:
10
+ * - Valid: 0263494, B0WNLY7
11
+ *
12
+ * @see http://en.wikipedia.org/wiki/SEDOL
13
+ * @param {BootstrapValidator} validator The validator plugin instance
14
+ * @param {jQuery} $field Field element
15
+ * @param {Object} options Can consist of the following keys:
16
+ * - message: The invalid message
17
+ * @returns {Boolean}
18
+ */
19
+ validate: function(validator, $field, options) {
20
+ var value = $field.val();
21
+ if (value === '') {
22
+ return true;
23
+ }
24
+
25
+ value = value.toUpperCase();
26
+ if (!/^[0-9A-Z]{7}$/.test(value)) {
27
+ return false;
28
+ }
29
+
30
+ var sum = 0,
31
+ weight = [1, 3, 1, 7, 3, 9, 1],
32
+ length = value.length;
33
+ for (var i = 0; i < length - 1; i++) {
34
+ sum += weight[i] * parseInt(value.charAt(i), 36);
35
+ }
36
+ sum = (10 - sum % 10) % 10;
37
+ return sum + '' === value.charAt(length - 1);
38
+ }
39
+ };
40
+ }(window.jQuery));
@@ -0,0 +1,28 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.siren = $.extend($.fn.bootstrapValidator.i18n.siren || {}, {
3
+ 'default': 'Please enter a valid SIREN number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.siren = {
7
+ /**
8
+ * Check if a string is a siren number
9
+ *
10
+ * @param {BootstrapValidator} validator The validator plugin instance
11
+ * @param {jQuery} $field Field element
12
+ * @param {Object} options Consist of key:
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
+ if (!/^\d{9}$/.test(value)) {
23
+ return false;
24
+ }
25
+ return $.fn.bootstrapValidator.helpers.luhn(value);
26
+ }
27
+ };
28
+ }(window.jQuery));
@@ -0,0 +1,38 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.siret = $.extend($.fn.bootstrapValidator.i18n.siret || {}, {
3
+ 'default': 'Please enter a valid SIRET number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.siret = {
7
+ /**
8
+ * Check if a string is a siret number
9
+ *
10
+ * @param {BootstrapValidator} validator The validator plugin instance
11
+ * @param {jQuery} $field Field element
12
+ * @param {Object} options Consist of key:
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
+ var sum = 0,
23
+ length = value.length,
24
+ tmp;
25
+ for (var i = 0; i < length; i++) {
26
+ tmp = parseInt(value.charAt(i), 10);
27
+ if ((i % 2) === 0) {
28
+ tmp = tmp * 2;
29
+ if (tmp > 9) {
30
+ tmp -= 9;
31
+ }
32
+ }
33
+ sum += tmp;
34
+ }
35
+ return (sum % 10 === 0);
36
+ }
37
+ };
38
+ }(window.jQuery));
@@ -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));