bootstrap_validator_rails 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
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,116 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.cvv = $.extend($.fn.bootstrapValidator.i18n.cvv || {}, {
3
+ 'default': 'Please enter a valid CVV number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.cvv = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ ccfield: 'creditCardField'
10
+ },
11
+
12
+ /**
13
+ * Return true if the input value is a valid CVV number.
14
+ *
15
+ * @param {BootstrapValidator} validator The validator plugin instance
16
+ * @param {jQuery} $field Field element
17
+ * @param {Object} options Can consist of the following keys:
18
+ * - creditCardField: The credit card number field. It can be null
19
+ * - message: The invalid message
20
+ * @returns {Boolean}
21
+ */
22
+ validate: function(validator, $field, options) {
23
+ var value = $field.val();
24
+ if (value === '') {
25
+ return true;
26
+ }
27
+
28
+ if (!/^[0-9]{3,4}$/.test(value)) {
29
+ return false;
30
+ }
31
+
32
+ if (!options.creditCardField) {
33
+ return true;
34
+ }
35
+
36
+ // Get the credit card number
37
+ var creditCard = validator.getFieldElements(options.creditCardField).val();
38
+ if (creditCard === '') {
39
+ return true;
40
+ }
41
+
42
+ creditCard = creditCard.replace(/\D/g, '');
43
+
44
+ // Supported credit card types
45
+ var cards = {
46
+ AMERICAN_EXPRESS: {
47
+ length: [15],
48
+ prefix: ['34', '37']
49
+ },
50
+ DINERS_CLUB: {
51
+ length: [14],
52
+ prefix: ['300', '301', '302', '303', '304', '305', '36']
53
+ },
54
+ DINERS_CLUB_US: {
55
+ length: [16],
56
+ prefix: ['54', '55']
57
+ },
58
+ DISCOVER: {
59
+ length: [16],
60
+ prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
61
+ '62214', '62215', '62216', '62217', '62218', '62219',
62
+ '6222', '6223', '6224', '6225', '6226', '6227', '6228',
63
+ '62290', '62291', '622920', '622921', '622922', '622923',
64
+ '622924', '622925', '644', '645', '646', '647', '648',
65
+ '649', '65']
66
+ },
67
+ JCB: {
68
+ length: [16],
69
+ prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
70
+ },
71
+ LASER: {
72
+ length: [16, 17, 18, 19],
73
+ prefix: ['6304', '6706', '6771', '6709']
74
+ },
75
+ MAESTRO: {
76
+ length: [12, 13, 14, 15, 16, 17, 18, 19],
77
+ prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
78
+ },
79
+ MASTERCARD: {
80
+ length: [16],
81
+ prefix: ['51', '52', '53', '54', '55']
82
+ },
83
+ SOLO: {
84
+ length: [16, 18, 19],
85
+ prefix: ['6334', '6767']
86
+ },
87
+ UNIONPAY: {
88
+ length: [16, 17, 18, 19],
89
+ prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
90
+ '62215', '62216', '62217', '62218', '62219', '6222', '6223',
91
+ '6224', '6225', '6226', '6227', '6228', '62290', '62291',
92
+ '622920', '622921', '622922', '622923', '622924', '622925']
93
+ },
94
+ VISA: {
95
+ length: [16],
96
+ prefix: ['4']
97
+ }
98
+ };
99
+ var type, i, creditCardType = null;
100
+ for (type in cards) {
101
+ for (i in cards[type].prefix) {
102
+ if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
103
+ && $.inArray(creditCard.length, cards[type].length) !== -1) // and length
104
+ {
105
+ creditCardType = type;
106
+ break;
107
+ }
108
+ }
109
+ }
110
+
111
+ return (creditCardType === null)
112
+ ? false
113
+ : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
114
+ }
115
+ };
116
+ }(window.jQuery));
@@ -0,0 +1,118 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.date = $.extend($.fn.bootstrapValidator.i18n.date || {}, {
3
+ 'default': 'Please enter a valid date'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.date = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ format: 'format',
10
+ separator: 'separator'
11
+ },
12
+
13
+ /**
14
+ * Return true if the input value is valid date
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
+ * - message: The invalid message
20
+ * - separator: Use to separate the date, month, and year.
21
+ * By default, it is /
22
+ * - format: The date format. Default is MM/DD/YYYY
23
+ * The format can be:
24
+ *
25
+ * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
26
+ * ii) date and time:
27
+ * The time can consist of h, m, s parts which are separated by :
28
+ * ii) date, time and A (indicating AM or PM)
29
+ * @returns {Boolean}
30
+ */
31
+ validate: function(validator, $field, options) {
32
+ var value = $field.val();
33
+ if (value === '') {
34
+ return true;
35
+ }
36
+
37
+ options.format = options.format || 'MM/DD/YYYY';
38
+
39
+ var formats = options.format.split(' '),
40
+ dateFormat = formats[0],
41
+ timeFormat = (formats.length > 1) ? formats[1] : null,
42
+ amOrPm = (formats.length > 2) ? formats[2] : null,
43
+ sections = value.split(' '),
44
+ date = sections[0],
45
+ time = (sections.length > 1) ? sections[1] : null;
46
+
47
+ if (formats.length !== sections.length) {
48
+ return false;
49
+ }
50
+
51
+ // Determine the separator
52
+ var separator = options.separator;
53
+ if (!separator) {
54
+ separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
55
+ }
56
+ if (separator === null || date.indexOf(separator) === -1) {
57
+ return false;
58
+ }
59
+
60
+ // Determine the date
61
+ date = date.split(separator);
62
+ dateFormat = dateFormat.split(separator);
63
+ if (date.length !== dateFormat.length) {
64
+ return false;
65
+ }
66
+
67
+ var year = date[$.inArray('YYYY', dateFormat)],
68
+ month = date[$.inArray('MM', dateFormat)],
69
+ day = date[$.inArray('DD', dateFormat)];
70
+
71
+ if (!year || !month || !day) {
72
+ return false;
73
+ }
74
+
75
+ // Determine the time
76
+ var minutes = null, hours = null, seconds = null;
77
+ if (timeFormat) {
78
+ timeFormat = timeFormat.split(':');
79
+ time = time.split(':');
80
+
81
+ if (timeFormat.length !== time.length) {
82
+ return false;
83
+ }
84
+
85
+ hours = time.length > 0 ? time[0] : null;
86
+ minutes = time.length > 1 ? time[1] : null;
87
+ seconds = time.length > 2 ? time[2] : null;
88
+
89
+ // Validate seconds
90
+ if (seconds) {
91
+ seconds = parseInt(seconds, 10);
92
+ if (isNaN(seconds) || seconds < 0 || seconds > 60) {
93
+ return false;
94
+ }
95
+ }
96
+
97
+ // Validate hours
98
+ if (hours) {
99
+ hours = parseInt(hours, 10);
100
+ if (isNaN(hours) || hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
101
+ return false;
102
+ }
103
+ }
104
+
105
+ // Validate minutes
106
+ if (minutes) {
107
+ minutes = parseInt(minutes, 10);
108
+ if (isNaN(minutes) || minutes < 0 || minutes > 59) {
109
+ return false;
110
+ }
111
+ }
112
+ }
113
+
114
+ // Validate day, month, and year
115
+ return $.fn.bootstrapValidator.helpers.date(year, month, day);
116
+ }
117
+ };
118
+ }(window.jQuery));
@@ -0,0 +1,41 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.different = $.extend($.fn.bootstrapValidator.i18n.different || {}, {
3
+ 'default': 'Please enter a different value'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.different = {
7
+ html5Attributes: {
8
+ message: 'message',
9
+ field: 'field'
10
+ },
11
+
12
+ /**
13
+ * Return true if the input value is different with given field's value
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
+ * - message: The invalid message
20
+ * @returns {Boolean}
21
+ */
22
+ validate: function(validator, $field, options) {
23
+ var value = $field.val();
24
+ if (value === '') {
25
+ return true;
26
+ }
27
+
28
+ var compareWith = validator.getFieldElements(options.field);
29
+ if (compareWith === null) {
30
+ return true;
31
+ }
32
+
33
+ if (value !== compareWith.val()) {
34
+ validator.updateStatus(options.field, validator.STATUS_VALID, 'different');
35
+ return true;
36
+ } else {
37
+ return false;
38
+ }
39
+ }
40
+ };
41
+ }(window.jQuery));
@@ -0,0 +1,24 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.digits = $.extend($.fn.bootstrapValidator.i18n.digits || {}, {
3
+ 'default': 'Please enter only digits'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.digits = {
7
+ /**
8
+ * Return true if the input value contains digits only
9
+ *
10
+ * @param {BootstrapValidator} validator Validate plugin instance
11
+ * @param {jQuery} $field Field element
12
+ * @param {Object} [options]
13
+ * @returns {Boolean}
14
+ */
15
+ validate: function(validator, $field, options) {
16
+ var value = $field.val();
17
+ if (value === '') {
18
+ return true;
19
+ }
20
+
21
+ return /^\d+$/.test(value);
22
+ }
23
+ };
24
+ }(window.jQuery));
@@ -0,0 +1,40 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.ean = $.extend($.fn.bootstrapValidator.i18n.ean || {}, {
3
+ 'default': 'Please enter a valid EAN number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.ean = {
7
+ /**
8
+ * Validate EAN (International Article Number)
9
+ * Examples:
10
+ * - Valid: 73513537, 9780471117094, 4006381333931
11
+ * - Invalid: 73513536
12
+ *
13
+ * @see http://en.wikipedia.org/wiki/European_Article_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
+ if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
27
+ return false;
28
+ }
29
+
30
+ var length = value.length,
31
+ sum = 0,
32
+ weight = (length === 8) ? [3, 1] : [1, 3];
33
+ for (var i = 0; i < length - 1; i++) {
34
+ sum += parseInt(value.charAt(i), 10) * weight[i % 2];
35
+ }
36
+ sum = (10 - sum % 10) % 10;
37
+ return (sum + '' === value.charAt(length - 1));
38
+ }
39
+ };
40
+ }(window.jQuery));
@@ -0,0 +1,31 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
3
+ 'default': 'Please enter a valid email address'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.emailAddress = {
7
+ enableByHtml5: function($field) {
8
+ return ('email' === $field.attr('type'));
9
+ },
10
+
11
+ /**
12
+ * Return true if and only if the input value is a valid email address
13
+ *
14
+ * @param {BootstrapValidator} validator Validate plugin instance
15
+ * @param {jQuery} $field Field element
16
+ * @param {Object} [options]
17
+ * @returns {Boolean}
18
+ */
19
+ validate: function(validator, $field, options) {
20
+ var value = $field.val();
21
+ if (value === '') {
22
+ return true;
23
+ }
24
+
25
+ // Email address regular expression
26
+ // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
27
+ var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
28
+ return emailRegExp.test(value);
29
+ }
30
+ };
31
+ }(window.jQuery));
@@ -0,0 +1,69 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.file = $.extend($.fn.bootstrapValidator.i18n.file || {}, {
3
+ 'default': 'Please choose a valid file'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.file = {
7
+ html5Attributes: {
8
+ extension: 'extension',
9
+ maxsize: 'maxSize',
10
+ message: 'message',
11
+ type: 'type'
12
+ },
13
+
14
+ /**
15
+ * Validate upload file. Use HTML 5 API if the browser supports
16
+ *
17
+ * @param {BootstrapValidator} validator The validator plugin instance
18
+ * @param {jQuery} $field Field element
19
+ * @param {Object} options Can consist of the following keys:
20
+ * - extension: The allowed extensions, separated by a comma
21
+ * - maxSize: The maximum size in bytes
22
+ * - message: The invalid message
23
+ * - type: The allowed MIME type, separated by a comma
24
+ * @returns {Boolean}
25
+ */
26
+ validate: function(validator, $field, options) {
27
+ var value = $field.val();
28
+ if (value === '') {
29
+ return true;
30
+ }
31
+
32
+ var ext,
33
+ extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
34
+ types = options.type ? options.type.toLowerCase().split(',') : null,
35
+ html5 = (window.File && window.FileList && window.FileReader);
36
+
37
+ if (html5) {
38
+ // Get FileList instance
39
+ var files = $field.get(0).files,
40
+ total = files.length;
41
+ for (var i = 0; i < total; i++) {
42
+ // Check file size
43
+ if (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) {
44
+ return false;
45
+ }
46
+
47
+ // Check file extension
48
+ ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
49
+ if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
50
+ return false;
51
+ }
52
+
53
+ // Check file type
54
+ if (types && $.inArray(files[i].type.toLowerCase(), types) === -1) {
55
+ return false;
56
+ }
57
+ }
58
+ } else {
59
+ // Check file extension
60
+ ext = value.substr(value.lastIndexOf('.') + 1);
61
+ if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ return true;
67
+ }
68
+ };
69
+ }(window.jQuery));
@@ -0,0 +1,61 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
3
+ 'default': 'Please enter a value greater than or equal to %s',
4
+ notInclusive: 'Please enter a value greater than %s'
5
+ });
6
+
7
+ $.fn.bootstrapValidator.validators.greaterThan = {
8
+ html5Attributes: {
9
+ message: 'message',
10
+ value: 'value',
11
+ inclusive: 'inclusive'
12
+ },
13
+
14
+ enableByHtml5: function($field) {
15
+ var min = $field.attr('min');
16
+ if (min) {
17
+ return {
18
+ value: min
19
+ };
20
+ }
21
+
22
+ return false;
23
+ },
24
+
25
+ /**
26
+ * Return true if the input value is greater than or equals to given number
27
+ *
28
+ * @param {BootstrapValidator} validator Validate plugin instance
29
+ * @param {jQuery} $field Field element
30
+ * @param {Object} options Can consist of the following keys:
31
+ * - value: Define the number to compare with. 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.greaterThan['default'], compareTo)
54
+ }
55
+ : {
56
+ valid: value > compareTo,
57
+ message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan.notInclusive, compareTo)
58
+ };
59
+ }
60
+ };
61
+ }(window.jQuery));
@@ -0,0 +1,37 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.grid = $.extend($.fn.bootstrapValidator.i18n.grid || {}, {
3
+ 'default': 'Please enter a valid GRId number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.grid = {
7
+ /**
8
+ * Validate GRId (Global Release Identifier)
9
+ * Examples:
10
+ * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
11
+ * - Invalid: A1-2425G-ABC1234002-Q
12
+ *
13
+ * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
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
+ value = value.toUpperCase();
27
+ if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
28
+ return false;
29
+ }
30
+ value = value.replace(/\s/g, '').replace(/-/g, '');
31
+ if ('GRID:' === value.substr(0, 5)) {
32
+ value = value.substr(5);
33
+ }
34
+ return $.fn.bootstrapValidator.helpers.mod37And36(value);
35
+ }
36
+ };
37
+ }(window.jQuery));
@@ -0,0 +1,25 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.hex = $.extend($.fn.bootstrapValidator.i18n.hex || {}, {
3
+ 'default': 'Please enter a valid hexadecimal number'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.hex = {
7
+ /**
8
+ * Return true if and only if the input value is a valid hexadecimal 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
+ return /^[0-9a-fA-F]+$/.test(value);
23
+ }
24
+ };
25
+ }(window.jQuery));
@@ -0,0 +1,28 @@
1
+ (function($) {
2
+ $.fn.bootstrapValidator.i18n.hexColor = $.extend($.fn.bootstrapValidator.i18n.hexColor || {}, {
3
+ 'default': 'Please enter a valid hex color'
4
+ });
5
+
6
+ $.fn.bootstrapValidator.validators.hexColor = {
7
+ enableByHtml5: function($field) {
8
+ return ('color' === $field.attr('type'));
9
+ },
10
+
11
+ /**
12
+ * Return true if the input value is a valid hex color
13
+ *
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
+ return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
26
+ }
27
+ };
28
+ }(window.jQuery));