diff --git a/js/bootstrap-timepicker.js b/js/bootstrap-timepicker.js index bbb923c5..89b11e00 100644 --- a/js/bootstrap-timepicker.js +++ b/js/bootstrap-timepicker.js @@ -274,7 +274,11 @@ templateContent; if (this.showInputs) { - hourTemplate = ''; + var maxLength = ''; + if (isFinite(this.maxHours)) { + maxLength = 'maxlength="'+this.maxHours.toString().length+'"'; + } + hourTemplate = ''; minuteTemplate = ''; secondTemplate = ''; meridianTemplate = ''; @@ -827,19 +831,21 @@ second = timeArray[2] ? timeArray[2].toString() : ''; // adaptive time parsing - if (hour.length > 4) { - second = hour.slice(-2); - hour = hour.slice(0, -2); - } + if (+hour > this.maxHours) { + if (hour.length > 4) { + second = hour.slice(-2); + hour = hour.slice(0, -2); + } - if (hour.length > 2) { - minute = hour.slice(-2); - hour = hour.slice(0, -2); - } + if (hour.length > 2) { + minute = hour.slice(-2); + hour = hour.slice(0, -2); + } - if (minute.length > 2) { - second = minute.slice(-2); - minute = minute.slice(0, -2); + if (minute.length > 2) { + second = minute.slice(-2); + minute = minute.slice(0, -2); + } } hour = parseInt(hour, 10);