bootstrap_validator-rails 0.0.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +4 -0
- data/lib/bootstrap_validator-rails.rb +5 -0
- data/lib/bootstrap_validator-rails/engine.rb +6 -0
- data/vendor/javascripts/bootstrapValidator.js +1803 -0
- data/vendor/javascripts/language/de_DE.js +326 -0
- data/vendor/javascripts/language/en_US.js +327 -0
- data/vendor/javascripts/language/es_CL.js +326 -0
- data/vendor/javascripts/language/hu_HU.js +326 -0
- data/vendor/javascripts/language/vi_VN.js +322 -0
- data/vendor/javascripts/language/zh_CN.js +326 -0
- data/vendor/javascripts/language/zh_TW.js +326 -0
- data/vendor/javascripts/validator/base64.js +25 -0
- data/vendor/javascripts/validator/between.js +66 -0
- data/vendor/javascripts/validator/callback.js +40 -0
- data/vendor/javascripts/validator/choice.js +68 -0
- data/vendor/javascripts/validator/creditCard.js +103 -0
- data/vendor/javascripts/validator/cusip.js +55 -0
- data/vendor/javascripts/validator/cvv.js +116 -0
- data/vendor/javascripts/validator/date.js +118 -0
- data/vendor/javascripts/validator/different.js +41 -0
- data/vendor/javascripts/validator/digits.js +24 -0
- data/vendor/javascripts/validator/ean.js +40 -0
- data/vendor/javascripts/validator/emailAddress.js +31 -0
- data/vendor/javascripts/validator/file.js +69 -0
- data/vendor/javascripts/validator/greaterThan.js +61 -0
- data/vendor/javascripts/validator/grid.js +37 -0
- data/vendor/javascripts/validator/hex.js +25 -0
- data/vendor/javascripts/validator/hexColor.js +28 -0
- data/vendor/javascripts/validator/iban.js +246 -0
- data/vendor/javascripts/validator/id.js +815 -0
- data/vendor/javascripts/validator/identical.js +40 -0
- data/vendor/javascripts/validator/imei.js +44 -0
- data/vendor/javascripts/validator/integer.js +28 -0
- data/vendor/javascripts/validator/ip.js +48 -0
- data/vendor/javascripts/validator/isbn.js +86 -0
- data/vendor/javascripts/validator/isin.js +59 -0
- data/vendor/javascripts/validator/ismn.js +59 -0
- data/vendor/javascripts/validator/issn.js +46 -0
- data/vendor/javascripts/validator/lessThan.js +61 -0
- data/vendor/javascripts/validator/mac.js +25 -0
- data/vendor/javascripts/validator/notEmpty.js +32 -0
- data/vendor/javascripts/validator/numeric.js +39 -0
- data/vendor/javascripts/validator/phone.js +84 -0
- data/vendor/javascripts/validator/regexp.js +42 -0
- data/vendor/javascripts/validator/remote.js +70 -0
- data/vendor/javascripts/validator/rtn.js +38 -0
- data/vendor/javascripts/validator/sedol.js +40 -0
- data/vendor/javascripts/validator/siren.js +28 -0
- data/vendor/javascripts/validator/siret.js +38 -0
- data/vendor/javascripts/validator/step.js +64 -0
- data/vendor/javascripts/validator/stringCase.js +36 -0
- data/vendor/javascripts/validator/stringLength.js +81 -0
- data/vendor/javascripts/validator/uri.js +101 -0
- data/vendor/javascripts/validator/uuid.js +46 -0
- data/vendor/javascripts/validator/vat.js +1220 -0
- data/vendor/javascripts/validator/vin.js +49 -0
- data/vendor/javascripts/validator/zipCode.js +162 -0
- data/vendor/stylesheets/bootstrapValidator.css +21 -0
- metadata +130 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
(function($) {
|
|
2
|
+
$.fn.bootstrapValidator.i18n.choice = $.extend($.fn.bootstrapValidator.i18n.choice || {}, {
|
|
3
|
+
'default': 'Please enter a valid value',
|
|
4
|
+
less: 'Please choose %s options at minimum',
|
|
5
|
+
more: 'Please choose %s options at maximum',
|
|
6
|
+
between: 'Please choose %s - %s options'
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
$.fn.bootstrapValidator.validators.choice = {
|
|
10
|
+
html5Attributes: {
|
|
11
|
+
message: 'message',
|
|
12
|
+
min: 'min',
|
|
13
|
+
max: 'max'
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Check if the number of checked boxes are less or more than a given number
|
|
18
|
+
*
|
|
19
|
+
* @param {BootstrapValidator} validator The validator plugin instance
|
|
20
|
+
* @param {jQuery} $field Field element
|
|
21
|
+
* @param {Object} options Consists of following keys:
|
|
22
|
+
* - min
|
|
23
|
+
* - max
|
|
24
|
+
*
|
|
25
|
+
* At least one of two keys is required
|
|
26
|
+
* The min, max keys define the number which the field value compares to. min, max can be
|
|
27
|
+
* - A number
|
|
28
|
+
* - Name of field which its value defines the number
|
|
29
|
+
* - Name of callback function that returns the number
|
|
30
|
+
* - A callback function that returns the number
|
|
31
|
+
*
|
|
32
|
+
* - message: The invalid message
|
|
33
|
+
* @returns {Object}
|
|
34
|
+
*/
|
|
35
|
+
validate: function(validator, $field, options) {
|
|
36
|
+
var numChoices = $field.is('select')
|
|
37
|
+
? validator.getFieldElements($field.attr('data-bv-field')).find('option').filter(':selected').length
|
|
38
|
+
: validator.getFieldElements($field.attr('data-bv-field')).filter(':checked').length,
|
|
39
|
+
min = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min)) : null,
|
|
40
|
+
max = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max)) : null,
|
|
41
|
+
isValid = true,
|
|
42
|
+
message = options.message || $.fn.bootstrapValidator.i18n.choice['default'];
|
|
43
|
+
|
|
44
|
+
if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
|
|
45
|
+
isValid = false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
switch (true) {
|
|
49
|
+
case (!!min && !!max):
|
|
50
|
+
message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.between, [parseInt(min, 10), parseInt(max, 10)]);
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case (!!min):
|
|
54
|
+
message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.less, parseInt(min, 10));
|
|
55
|
+
break;
|
|
56
|
+
|
|
57
|
+
case (!!max):
|
|
58
|
+
message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.more, parseInt(max, 10));
|
|
59
|
+
break;
|
|
60
|
+
|
|
61
|
+
default:
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { valid: isValid, message: message };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}(window.jQuery));
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
(function($) {
|
|
2
|
+
$.fn.bootstrapValidator.i18n.creditCard = $.extend($.fn.bootstrapValidator.i18n.creditCard || {}, {
|
|
3
|
+
'default': 'Please enter a valid credit card number'
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
$.fn.bootstrapValidator.validators.creditCard = {
|
|
7
|
+
/**
|
|
8
|
+
* Return true if the input value is valid credit card number
|
|
9
|
+
* Based on https://gist.github.com/DiegoSalazar/4075533
|
|
10
|
+
*
|
|
11
|
+
* @param {BootstrapValidator} validator The validator plugin instance
|
|
12
|
+
* @param {jQuery} $field Field element
|
|
13
|
+
* @param {Object} [options] Can consist of the following key:
|
|
14
|
+
* - message: The invalid message
|
|
15
|
+
* @returns {Boolean}
|
|
16
|
+
*/
|
|
17
|
+
validate: function(validator, $field, options) {
|
|
18
|
+
var value = $field.val();
|
|
19
|
+
if (value === '') {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Accept only digits, dashes or spaces
|
|
24
|
+
if (/[^0-9-\s]+/.test(value)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
value = value.replace(/\D/g, '');
|
|
28
|
+
|
|
29
|
+
if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Validate the card number based on prefix (IIN ranges) and length
|
|
34
|
+
var cards = {
|
|
35
|
+
AMERICAN_EXPRESS: {
|
|
36
|
+
length: [15],
|
|
37
|
+
prefix: ['34', '37']
|
|
38
|
+
},
|
|
39
|
+
DINERS_CLUB: {
|
|
40
|
+
length: [14],
|
|
41
|
+
prefix: ['300', '301', '302', '303', '304', '305', '36']
|
|
42
|
+
},
|
|
43
|
+
DINERS_CLUB_US: {
|
|
44
|
+
length: [16],
|
|
45
|
+
prefix: ['54', '55']
|
|
46
|
+
},
|
|
47
|
+
DISCOVER: {
|
|
48
|
+
length: [16],
|
|
49
|
+
prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
|
|
50
|
+
'62214', '62215', '62216', '62217', '62218', '62219',
|
|
51
|
+
'6222', '6223', '6224', '6225', '6226', '6227', '6228',
|
|
52
|
+
'62290', '62291', '622920', '622921', '622922', '622923',
|
|
53
|
+
'622924', '622925', '644', '645', '646', '647', '648',
|
|
54
|
+
'649', '65']
|
|
55
|
+
},
|
|
56
|
+
JCB: {
|
|
57
|
+
length: [16],
|
|
58
|
+
prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
|
|
59
|
+
},
|
|
60
|
+
LASER: {
|
|
61
|
+
length: [16, 17, 18, 19],
|
|
62
|
+
prefix: ['6304', '6706', '6771', '6709']
|
|
63
|
+
},
|
|
64
|
+
MAESTRO: {
|
|
65
|
+
length: [12, 13, 14, 15, 16, 17, 18, 19],
|
|
66
|
+
prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
|
|
67
|
+
},
|
|
68
|
+
MASTERCARD: {
|
|
69
|
+
length: [16],
|
|
70
|
+
prefix: ['51', '52', '53', '54', '55']
|
|
71
|
+
},
|
|
72
|
+
SOLO: {
|
|
73
|
+
length: [16, 18, 19],
|
|
74
|
+
prefix: ['6334', '6767']
|
|
75
|
+
},
|
|
76
|
+
UNIONPAY: {
|
|
77
|
+
length: [16, 17, 18, 19],
|
|
78
|
+
prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
|
|
79
|
+
'62215', '62216', '62217', '62218', '62219', '6222', '6223',
|
|
80
|
+
'6224', '6225', '6226', '6227', '6228', '62290', '62291',
|
|
81
|
+
'622920', '622921', '622922', '622923', '622924', '622925']
|
|
82
|
+
},
|
|
83
|
+
VISA: {
|
|
84
|
+
length: [16],
|
|
85
|
+
prefix: ['4']
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var type, i;
|
|
90
|
+
for (type in cards) {
|
|
91
|
+
for (i in cards[type].prefix) {
|
|
92
|
+
if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
|
|
93
|
+
&& $.inArray(value.length, cards[type].length) !== -1) // and length
|
|
94
|
+
{
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}(window.jQuery));
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
(function($) {
|
|
2
|
+
$.fn.bootstrapValidator.i18n.cusip = $.extend($.fn.bootstrapValidator.i18n.cusip || {}, {
|
|
3
|
+
'default': 'Please enter a valid CUSIP number'
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
$.fn.bootstrapValidator.validators.cusip = {
|
|
7
|
+
/**
|
|
8
|
+
* Validate a CUSIP
|
|
9
|
+
* Examples:
|
|
10
|
+
* - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
|
|
11
|
+
* - Invalid: 31430F200, 022615AC2
|
|
12
|
+
*
|
|
13
|
+
* @see http://en.wikipedia.org/wiki/CUSIP
|
|
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 (!/^[0-9A-Z]{9}$/.test(value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var converted = $.map(value.split(''), function(item) {
|
|
32
|
+
var code = item.charCodeAt(0);
|
|
33
|
+
return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
|
|
34
|
+
// Replace A, B, C, ..., Z with 10, 11, ..., 35
|
|
35
|
+
? (code - 'A'.charCodeAt(0) + 10)
|
|
36
|
+
: item;
|
|
37
|
+
}),
|
|
38
|
+
length = converted.length,
|
|
39
|
+
sum = 0;
|
|
40
|
+
for (var i = 0; i < length - 1; i++) {
|
|
41
|
+
var num = parseInt(converted[i], 10);
|
|
42
|
+
if (i % 2 !== 0) {
|
|
43
|
+
num *= 2;
|
|
44
|
+
}
|
|
45
|
+
if (num > 9) {
|
|
46
|
+
num -= 9;
|
|
47
|
+
}
|
|
48
|
+
sum += num;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
sum = (10 - (sum % 10)) % 10;
|
|
52
|
+
return sum === converted[length - 1];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}(window.jQuery));
|
|
@@ -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));
|