bootstrap datepicker
allows you to configure the inputs in such a way that you can avoid validations of this type, which is often much better for user experience
As an option, you could set this configuration
var getDate = function (input) {
return new Date(input.date.valueOf());
}
$('#entrada, #salida').datepicker({
format: "dd/mm/yyyy",
language: 'es'
});
$('#entrada').datepicker({
startDate: '+5d',
endDate: '+35d',
}).on('changeDate',
function (selected) {
$('#salida').datepicker('setStartDate', getDate(selected));
});
$('#salida').datepicker({
startDate: '+6d',
endDate: '+36d',
}).on('changeDate',
function (selected) {
$('#entrada').datepicker('setEndDate', getDate(selected));
});
As you can see, you use the event changeDate
for each input, so that the user can not exceed the dates of entry and exit when making the selection
in this link you can see how it works for your example
Edit
To be able to select a start date after the end date, update the code to the following. here is the documentation so you can use the methods of the complement
var getDate = function (input) {
return new Date(input.date.valueOf());
}
$('#entrada, #salida').datepicker({
format: "dd/mm/yyyy",
language: 'es'
});
$('#salida').datepicker({
startDate: '+6d',
endDate: '+36d',
});
$('#entrada').datepicker({
startDate: '+5d',
endDate: '+35d',
}).on('changeDate',
function (selected) {
$('#salida').datepicker('clearDates');
$('#salida').datepicker('setStartDate', getDate(selected));
});
in this link you can see how it works updated for your example