I used to use this solution by adding the call to a blur in the field, and if it returned false, I would show a tooltip stating that the date is invalid
function date(ele){
var dateRegex = /^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-.\/])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
return dateRegex.test(ele.val());
}
The problem is that in this project I will need to use an old version of the bootstrap in which I don't have a tooltip.
I was thinking about copying the css of the newest bootsrap to create my own tooltip, but before that I want to find out if anyone knows a better way to resolve this date validation. the best solution is to make a mask for the input along with the validation and already displaying something like a tooltip or html5 message warning that the date is invalid.
I want to know if there is any way to implement a date mask that validates and returns to the user if the date is invalid and do not allow a submit, just like when we use a required in the field. Is there an implementation or library that does this?
something like invalide-feedback or valid-tooltip for date
If you ask for something custom, it could be done like shown on MDN: Client-side form validation. I threw this quickly together and did not spend time on making it look nice but it works using the Constraint Validation API and your JS function just to show you can mix and match.
If that's not good enough you might look into custom Bootstrap plugins like FormValidation (available for v3/4)