MCPcopy Create free account
hub / github.com/bootboxjs/bootbox / minAndMaxAreValid

Function minAndMaxAreValid

bootbox.js:1147–1190  ·  view source on GitHub ↗
(type, min, max)

Source from the content-addressed store, hash-verified

1145
1146 // Validate `min` and `max` values based on the current `inputType` value
1147 function minAndMaxAreValid(type, min, max) {
1148 let result = false;
1149 let minValid = true;
1150 let maxValid = true;
1151
1152 if (type === 'date') {
1153 if (min !== undefined && !(minValid = dateIsValid(min))) {
1154 console.warn('Browsers which natively support the "date" input type expect date values to be of the form "YYYY-MM-DD" (see ISO-8601 https://www.iso.org/iso-8601-date-and-time-format.html). Bootbox does not enforce this rule, but your min value may not be enforced by this browser.');
1155 }
1156 else if (max !== undefined && !(maxValid = dateIsValid(max))) {
1157 console.warn('Browsers which natively support the "date" input type expect date values to be of the form "YYYY-MM-DD" (see ISO-8601 https://www.iso.org/iso-8601-date-and-time-format.html). Bootbox does not enforce this rule, but your max value may not be enforced by this browser.');
1158 }
1159 }
1160 else if (type === 'time') {
1161 if (min !== undefined && !(minValid = timeIsValid(min))) {
1162 throw new Error('"min" is not a valid time. See https://www.w3.org/TR/2012/WD-html-markup-20120315/datatypes.html#form.data.time for more information.');
1163 }
1164 else if (max !== undefined && !(maxValid = timeIsValid(max))) {
1165 throw new Error('"max" is not a valid time. See https://www.w3.org/TR/2012/WD-html-markup-20120315/datatypes.html#form.data.time for more information.');
1166 }
1167 }
1168 else {
1169 if (min !== undefined && isNaN(min)) {
1170 minValid = false;
1171 throw new Error('"min" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-min for more information.');
1172 }
1173
1174 if (max !== undefined && isNaN(max)) {
1175 maxValid = false;
1176 throw new Error('"max" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max for more information.');
1177 }
1178 }
1179
1180 if (minValid && maxValid) {
1181 if (max < min) {
1182 throw new Error('"max" must be greater than or equal to "min". See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max for more information.');
1183 }
1184 else {
1185 result = true;
1186 }
1187 }
1188
1189 return result;
1190 }
1191
1192 function timeIsValid(value) {
1193 return /([01][0-9]|2[0-3]):[0-5][0-9]?:[0-5][0-9]/.test(value);

Callers 1

bootbox.jsFile · 0.85

Calls 2

dateIsValidFunction · 0.85
timeIsValidFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…